]> git.pond.sub.org Git - empserver/blob - src/lib/commands/zdon.c
c49844732c5ab4cc206eb2da675d5f7075cae0de
[empserver] / src / lib / commands / zdon.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  zdon.c: Update right now
28  *
29  *  Known contributors to this file:
30  *     Doug Hay, 1990
31  *     Markus Armbruster, 2007-2010
32  */
33
34 /*
35  * Syntax:
36  *  Normal player:   zdone [Y|N|C]
37  *  Deity        :   zdone [country_num [Y|N|C]]
38  *
39  *  Where:
40  *         Y  = Yes, wants an update.
41  *         N  = No, change status to not wanting an update.
42  *         C  = Check (the default), check how many want an update.
43  *
44  * Sets/Unsets a nation flag.
45  *
46  * Only considers NORMAL, active countries.  No Deities or sanctuaries.
47  *
48  * After the change, send a message to the "tm" for it to check
49  * if an update should occur.
50  */
51
52 #include <config.h>
53
54 #include "commands.h"
55 #include "optlist.h"
56 #include "server.h"
57
58 int
59 zdon(void)
60 {
61     int whichcnum;
62     struct natstr *natp;
63     char *p;
64
65     int checking;
66     int wantupd;
67     int totpop;
68     int totwant;
69     int dowant;
70     char buf[1024];
71
72     if (update_demand != UPD_DEMAND_SCHED
73         && update_demand != UPD_DEMAND_ASYNC) {
74         pr("Demand updates are not enabled.\n");
75         return RET_FAIL;
76     }
77     p = getstarg(player->argp[1], "Want update? [Yes|No|Check] ", buf);
78     if (!p)
79         return RET_SYN;
80     if (*p == 'y' || *p == 'Y') {
81         checking = 0;
82         wantupd = 1;
83     } else if (*p == 'n' || *p == 'N') {
84         checking = 0;
85         wantupd = 0;
86     } else {
87         checking = 1;
88         wantupd = 0;
89     }
90
91     if (player->god) {
92         whichcnum = natarg(player->argp[2], "for which country? ");
93         if (whichcnum < 0)
94             return RET_SYN;
95     } else
96         whichcnum = player->cnum;
97
98     if (!(natp = getnatp(whichcnum))) {
99         pr("Unable to find country. %d\n", whichcnum);
100         pr("Notify the Deity.\n");
101         return RET_FAIL;
102     }
103     if (!checking) {
104         if (wantupd) {
105             if (influx(natp)) {
106                 pr("Unable to request an update as the country is in flux\n");
107                 return RET_FAIL;
108             }
109             pr("You (%d) now want an update.\n", whichcnum);
110         } else {
111             pr("You (%d) now DON'T want an update.\n", whichcnum);
112         }
113         natp->nat_update = wantupd;
114         putnat(natp);
115     }
116
117     dowant = demand_update_want(&totwant, &totpop, whichcnum);
118     if (checking) {
119         if (dowant) {
120             pr("You want an update.\n");
121         } else
122             pr("You DON'T want an update, yet.\n");
123     }
124
125     pr("%d of a total of %d lunatics want an update.\n", totwant, totpop);
126
127     if (!checking && wantupd && demandupdatecheck()) {
128         pr("Here goes...\n");
129         update_trigger();
130     }
131     return RET_OK;
132 }