]> git.pond.sub.org Git - empserver/blob - src/lib/commands/zdon.c
f9768705aa15f89d363f78e9214e859cb9a6a4f9
[empserver] / src / lib / commands / zdon.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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 <config.h>
53
54 #include <stdio.h>
55 #include "misc.h"
56 #include "player.h"
57 #include "nat.h"
58 #include "file.h"
59 #include "empthread.h"
60 #include "commands.h"
61 #include "optlist.h"
62 #include "server.h"
63
64 int
65 zdon(void)
66 {
67     natid whichcnum;
68     struct natstr *natp;
69     register s_char *p;
70
71     int update;
72     int checking;
73     int wantupd;
74     int totpop;
75     int totwant;
76     int dowant;
77     s_char buf[1024];
78
79     if (!opt_DEMANDUPDATE) {
80         pr("Demand updates are not enabled.\n");
81         return RET_FAIL;
82     }
83     whichcnum = player->cnum;
84     p = NULL;
85     if (player->god) {
86         /* Deity syntax "country what" */
87         whichcnum = onearg(player->argp[1], "Which country no.? ");
88         if ((whichcnum > 0) && (getnatp(whichcnum)))
89             p = getstarg(player->argp[2], "Want update? [Yes|No|Check] ",
90                          buf);
91     } else {
92         p = getstarg(player->argp[1], "Want update? [Yes|No|Check] ", buf);
93     }
94     if (player->aborted)
95         return RET_FAIL;
96
97     if (!p) {
98         /* Default response is checking only */
99         checking = 1;
100     } else {
101         checking = 0;
102         if (*p == 'n' || *p == 'N') {
103             wantupd = 0;
104         } else if (*p == 'y' || *p == 'Y') {
105             wantupd = 1;
106         } else {
107             /* Default response is checking only */
108             checking = 1;
109         }
110     }
111
112     if (!checking) {
113         if (!(natp = getnatp(whichcnum))) {
114             pr("Unable to find country. %d\n", whichcnum);
115             pr("Notify the Deity.\n");
116             return RET_FAIL;
117         }
118         if (wantupd) {
119             if (influx(natp)) {
120                 pr("Unable to request an update as the country is in flux\n");
121                 return RET_FAIL;
122             }
123             update = natp->nat_update | WUPD_WANT;
124             natp->nat_missed = 0;
125             pr("You (%d) now want an update.\n", whichcnum);
126         } else {
127             update = natp->nat_update & ~WUPD_WANT;
128             pr("You (%d) now DON'T want an update.\n", whichcnum);
129         }
130         natp->nat_update = update;
131         putnat(natp);
132     }
133
134     dowant = demand_update_want(&totwant, &totpop, whichcnum);
135     if (checking) {
136         if (dowant) {
137             pr("You want an update.\n");
138         } else
139             pr("You DON'T want an update, yet.\n");
140     }
141
142     pr("%d of a total of %d lunatics want an update.\n", totwant, totpop);
143
144     if (!checking && wantupd && demandupdatecheck()) {
145         pr("Here goes...\n");
146         empth_sem_signal(update_sem);
147     }
148     return RET_OK;
149 }