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