]> git.pond.sub.org Git - empserver/blob - src/lib/commands/anti.c
Update copyright notice.
[empserver] / src / lib / commands / anti.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  *  anti.c: Take action against che
29  * 
30  *  Known contributors to this file:
31  *     Pat Loney, 1992
32  *     Steve McClure, 1997
33  */
34
35
36 #include <stdio.h>
37 #include <ctype.h>
38 #include "misc.h"
39 #include "player.h"
40 #include "var.h"
41 #include "xy.h"
42 #include "sect.h"
43 #include "nat.h"
44 #include "news.h"
45 #include "nsc.h"
46 #include "item.h"
47 #include "file.h"
48 #include "commands.h"
49 #include "optlist.h"
50
51 /*
52  * format: anti <SECT>
53  */
54 int
55 anti(void)
56 {
57     struct sctstr sect;
58     int nsect;
59     struct nstr_sect nstr;
60     int mil, che, target;
61     int avail_mil;
62     int amil, ache;
63     int milkilled, chekilled;
64     double odds, damil, dache;
65     int mob;
66     int n_cheleft;
67
68     if (!snxtsct(&nstr, player->argp[1]))
69         return RET_SYN;
70     prdate();
71     nsect = 0;
72     while (nxtsct(&nstr, &sect)) {
73         if (!player->owner)
74             continue;
75         if (nsect++ == 0) {
76             pr("  sect    subversion activity report\n");
77             pr("  ----    --------------------------\n");
78         }
79         mil = sect.sct_item[I_MILIT];
80         che = sect.sct_che;
81         target = sect.sct_che_target;
82         avail_mil = sect.sct_mobil / 2;
83         if (mil <= avail_mil)
84             avail_mil = mil;
85         prxy("%4d,%-4d ", sect.sct_x, sect.sct_y, player->cnum);
86         if (avail_mil <= 0) {
87             pr("No available mil or mob in sector.\n");
88             continue;
89         }
90         pr("Sector mobility/troop strength will allow %d troops to engage.\n", avail_mil);
91
92         if (target == player->cnum) {
93             amil = mil;
94             ache = che;
95             milkilled = 0;
96             chekilled = 0;
97             mob = sect.sct_mobil;
98             while (amil != 0 && ache != 0 && mob > 1) {
99                 damil = amil;
100                 dache = ache;
101                 odds = (dache * 2.0 / (damil + dache));
102                 odds /= hap_fact(getnatp(sect.sct_own),
103                                  getnatp(sect.sct_oldown));
104                 mob = mob - 2;
105                 if (chance(odds)) {
106                     amil = amil - 1;
107                     milkilled = milkilled + 1;
108                 } else {
109                     ache = ache - 1;
110                     chekilled = chekilled + 1;
111                 }
112             }
113             if (mil - milkilled > 0) {
114                 sect.sct_mobil = sect.sct_mobil - chekilled - milkilled;
115                 sect.sct_item[I_MILIT] = mil - milkilled;
116                 if (ache == 0)
117                     sect.sct_che_target = 0;
118                 sect.sct_che = ache;
119                 putsect(&sect);
120                 pr("          Body count:  Military %d - Guerillas %d.\n",
121                    milkilled, chekilled);
122                 if (ache == 0) {
123                     pr("          Partisans cleared out of this sector for now.\n");
124                 } else {
125                     pr("          Partisans still active in this sector.\n");
126                 }
127             } else {
128                 if (opt_MOB_ACCESS) {
129                     sect.sct_mobil =
130                         -(etu_per_update / sect_mob_neg_factor);
131                 } else {
132                     sect.sct_mobil = 0;
133                 }
134                 sect.sct_loyal = sect.sct_loyal * 0.5;
135                 n_cheleft = (random() % 4);
136                 /* 75% chance some che will get left */
137                 if (n_cheleft) {
138                     /* Ok, now leave anywhere from 16% to 25% of the che */
139                     n_cheleft = (ache / (n_cheleft + 3));
140                     ache -= n_cheleft;
141                     sect.sct_che = n_cheleft;
142                 } else {
143                     sect.sct_che = 0;
144                     sect.sct_che_target = 0;
145                 }
146                 sect.sct_item[I_MILIT] = ache;
147                 if (sect.sct_own == sect.sct_oldown)
148                     sect.sct_oldown = 0;
149                 makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x,
150                          sect.sct_y);
151                 makenotlost(EF_SECTOR, sect.sct_oldown, 0, sect.sct_x,
152                             sect.sct_y);
153                 sect.sct_own = sect.sct_oldown;
154                 sect.sct_off = 1;       /* Turn the sector off */
155                 putsect(&sect);
156                 pr("          Partisans take over the sector.  You blew it.\n");
157                 wu(0, sect.sct_oldown,
158                    "Sector %s regained from Partisan activity.\n",
159                    xyas(nstr.x, nstr.y, sect.sct_oldown));
160             }
161         } else {
162             pr("          Body count:  Military 0 - Guerillas 0.\n");
163             pr("          Partisans cleared out of this sector for now.\n");
164         }
165     }
166     pr("%d sector%s\n", nsect, splur(nsect));
167     return RET_OK;
168 }