]> 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-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  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  */
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 <stdio.h>
53 #include "misc.h"
54 #include "player.h"
55 #include "nat.h"
56 #include "file.h"
57 #include "empthread.h"
58 #include "commands.h"
59 #include "optlist.h"
60 #include "server.h"
61
62 int
63 zdon(void)
64 {
65     natid whichcnum;
66     struct natstr *natp;
67     register s_char *p;
68
69     int update;
70     int checking;
71     int wantupd;
72     int totpop;
73     int totwant;
74     int dowant;
75     s_char buf[1024];
76
77     if (!opt_DEMANDUPDATE) {
78         pr("Demand updates are not enabled.\n");
79         return RET_FAIL;
80     }
81     whichcnum = player->cnum;
82     p = NULL;
83     if (player->god) {
84         /* Deity syntax "country what" */
85         whichcnum = onearg(player->argp[1], "Which country no.? ");
86         if ((whichcnum > 0) && (getnatp(whichcnum)))
87             p = getstarg(player->argp[2], "Want update? [Yes|No|Check] ",
88                          buf);
89     } else {
90         p = getstarg(player->argp[1], "Want update? [Yes|No|Check] ", buf);
91     }
92     if (player->aborted)
93         return RET_FAIL;
94
95     if (!p) {
96         /* Default response is checking only */
97         checking = 1;
98     } else {
99         checking = 0;
100         if (*p == 'n' || *p == 'N') {
101             wantupd = 0;
102         } else if (*p == 'y' || *p == 'Y') {
103             wantupd = 1;
104         } else {
105             /* Default response is checking only */
106             checking = 1;
107         }
108     }
109
110     if (!checking) {
111         if (!(natp = getnatp(whichcnum))) {
112             pr("Unable to find country. %d\n", whichcnum);
113             pr("Notify the Deity.\n");
114             return RET_FAIL;
115         }
116         if (wantupd) {
117             update = natp->nat_update | WUPD_WANT;
118             natp->nat_missed = 0;
119             pr("You (%d) now want an update.\n", whichcnum);
120         } else {
121             update = natp->nat_update & ~WUPD_WANT;
122             pr("You (%d) now DON'T want an update.\n", whichcnum);
123         }
124         natp->nat_update = update;
125         putnat(natp);
126     }
127
128     dowant = demand_update_want(&totwant, &totpop, whichcnum);
129     if (checking) {
130         if (dowant) {
131             pr("You want an update.\n");
132         } else
133             pr("You DON'T want an update, yet.\n");
134     }
135
136     pr("%d of a total of %d lunatics want an update.\n", totwant, totpop);
137
138     if (!checking && wantupd && demandupdatecheck()) {
139         pr("Here goes...\n");
140         empth_sem_signal(update_sem);
141     }
142     return RET_OK;
143 }