]> git.pond.sub.org Git - empserver/blob - src/lib/commands/zdon.c
c0579827f9771d478be745f547050054553baf0a
[empserver] / src / lib / commands / zdon.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2017, 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
45 #include <config.h>
46
47 #include "commands.h"
48 #include "optlist.h"
49 #include "server.h"
50
51 int
52 zdon(void)
53 {
54     int whichcnum;
55     struct natstr *natp;
56     char *p;
57
58     int checking;
59     int wantupd;
60     int totpop;
61     int totwant;
62     int dowant;
63     char buf[1024];
64
65     if (update_demand != UPD_DEMAND_SCHED
66         && update_demand != UPD_DEMAND_ASYNC) {
67         pr("Demand updates are not enabled.\n");
68         return RET_FAIL;
69     }
70     p = getstarg(player->argp[1], "Want update? [Yes|No|Check] ", buf);
71     if (!p)
72         return RET_SYN;
73     if (*p == 'y' || *p == 'Y') {
74         checking = 0;
75         wantupd = 1;
76     } else if (*p == 'n' || *p == 'N') {
77         checking = 0;
78         wantupd = 0;
79     } else {
80         checking = 1;
81         wantupd = 0;
82     }
83
84     if (player->god) {
85         whichcnum = natarg(player->argp[2], "for which country? ");
86         if (whichcnum < 0)
87             return RET_SYN;
88     } else
89         whichcnum = player->cnum;
90
91     if (!(natp = getnatp(whichcnum))) {
92         pr("Unable to find country. %d\n", whichcnum);
93         pr("Notify the Deity.\n");
94         return RET_FAIL;
95     }
96     if (!checking) {
97         if (wantupd) {
98             if (influx(natp)) {
99                 pr("Unable to request an update as the country is in flux\n");
100                 return RET_FAIL;
101             }
102             pr("You (%d) now want an update.\n", whichcnum);
103         } else {
104             pr("You (%d) now DON'T want an update.\n", whichcnum);
105         }
106         natp->nat_update = wantupd;
107         putnat(natp);
108     }
109
110     dowant = demand_update_want(&totwant, &totpop, whichcnum);
111     if (checking) {
112         if (dowant) {
113             pr("You want an update.\n");
114         } else
115             pr("You DON'T want an update, yet.\n");
116     }
117
118     pr("%d of a total of %d lunatics want an update.\n", totwant, totpop);
119
120     if (!checking && wantupd && demandupdatecheck()) {
121         pr("Here goes...\n");
122         update_trigger();
123     }
124     return RET_OK;
125 }