]> git.pond.sub.org Git - empserver/blob - src/lib/commands/zdon.c
8bb84d052bd77deb7fcff7fc5f843a512892d281
[empserver] / src / lib / commands / zdon.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, 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     natid 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     whichcnum = player->cnum;
79     p = NULL;
80     if (player->god) {
81         /* Deity syntax "country what" */
82         whichcnum = onearg(player->argp[1], "Which country no.? ");
83         if ((whichcnum > 0) && (getnatp(whichcnum)))
84             p = getstarg(player->argp[2], "Want update? [Yes|No|Check] ",
85                          buf);
86     } else {
87         p = getstarg(player->argp[1], "Want update? [Yes|No|Check] ", buf);
88     }
89     if (player->aborted)
90         return RET_FAIL;
91
92     checking = 1;
93     wantupd = 0;
94     if (p) {
95         if (*p == 'y' || *p == 'Y') {
96             checking = 0;
97             wantupd = 1;
98         } else if  (*p == 'n' || *p == 'N') {
99             checking = 0;
100             wantupd = 0;
101         }
102     }
103
104     if (!(natp = getnatp(whichcnum))) {
105         pr("Unable to find country. %d\n", whichcnum);
106         pr("Notify the Deity.\n");
107         return RET_FAIL;
108     }
109     if (!checking) {
110         if (wantupd) {
111             if (influx(natp)) {
112                 pr("Unable to request an update as the country is in flux\n");
113                 return RET_FAIL;
114             }
115             pr("You (%d) now want an update.\n", whichcnum);
116         } else {
117             pr("You (%d) now DON'T want an update.\n", whichcnum);
118         }
119         natp->nat_update = wantupd;
120         putnat(natp);
121     }
122
123     dowant = demand_update_want(&totwant, &totpop, whichcnum);
124     if (checking) {
125         if (dowant) {
126             pr("You want an update.\n");
127         } else
128             pr("You DON'T want an update, yet.\n");
129     }
130
131     pr("%d of a total of %d lunatics want an update.\n", totwant, totpop);
132
133     if (!checking && wantupd && demandupdatecheck()) {
134         pr("Here goes...\n");
135         update_trigger();
136     }
137     return RET_OK;
138 }