]> git.pond.sub.org Git - empserver/blob - src/lib/commands/zdon.c
Make zdone accept country names
[empserver] / src / lib / commands / zdon.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  zdon.c: Update right now
29  * 
30  *  Known contributors to this file:
31  *     Doug Hay, 1990
32  *     Markus Armbruster, 2007
33  */
34
35 /*
36  * Syntax:
37  *  Normal player:   zdone [Y|N|C]
38  *  Deity        :   zdone [country_num [Y|N|C]]
39  *
40  *  Where:
41  *         Y  = Yes, wants an update.
42  *         N  = No, change status to not wanting an update.
43  *         C  = Check (the default), check how many want an update.
44  *
45  * Sets/Unsets a nation flag.
46  *
47  * Only considers NORMAL, active countries.  No Deities or sanctuaries.
48  *
49  * After the change, send a message to the "tm" for it to check
50  * if an update should occur.
51  */
52
53 #include <config.h>
54
55 #include "commands.h"
56 #include "optlist.h"
57 #include "server.h"
58
59 int
60 zdon(void)
61 {
62     int whichcnum;
63     struct natstr *natp;
64     char *p;
65
66     int checking;
67     int wantupd;
68     int totpop;
69     int totwant;
70     int dowant;
71     char buf[1024];
72
73     if (update_demand != UPD_DEMAND_SCHED
74         && update_demand != UPD_DEMAND_ASYNC) {
75         pr("Demand updates are not enabled.\n");
76         return RET_FAIL;
77     }
78     if (player->god) {
79         /* Deity syntax "country what" */
80         whichcnum = natarg(player->argp[1], "Which country no.? ");
81         if (whichcnum < 0)
82             return RET_SYN;
83         p = getstarg(player->argp[2], "Want update? [Yes|No|Check] ", buf);
84     } else {
85         whichcnum = player->cnum;
86         p = getstarg(player->argp[1], "Want update? [Yes|No|Check] ", buf);
87     }
88     if (!p)
89         return RET_SYN;
90
91     if (*p == 'y' || *p == 'Y') {
92         checking = 0;
93         wantupd = 1;
94     } else if  (*p == 'n' || *p == 'N') {
95         checking = 0;
96         wantupd = 0;
97     } else {
98         checking = 1;
99         wantupd = 0;
100     }
101
102     if (!(natp = getnatp(whichcnum))) {
103         pr("Unable to find country. %d\n", whichcnum);
104         pr("Notify the Deity.\n");
105         return RET_FAIL;
106     }
107     if (!checking) {
108         if (wantupd) {
109             if (influx(natp)) {
110                 pr("Unable to request an update as the country is in flux\n");
111                 return RET_FAIL;
112             }
113             pr("You (%d) now want an update.\n", whichcnum);
114         } else {
115             pr("You (%d) now DON'T want an update.\n", whichcnum);
116         }
117         natp->nat_update = wantupd;
118         putnat(natp);
119     }
120
121     dowant = demand_update_want(&totwant, &totpop, whichcnum);
122     if (checking) {
123         if (dowant) {
124             pr("You want an update.\n");
125         } else
126             pr("You DON'T want an update, yet.\n");
127     }
128
129     pr("%d of a total of %d lunatics want an update.\n", totwant, totpop);
130
131     if (!checking && wantupd && demandupdatecheck()) {
132         pr("Here goes...\n");
133         update_trigger();
134     }
135     return RET_OK;
136 }