]> 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-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  anti.c: Take action against che
28  *
29  *  Known contributors to this file:
30  *     Pat Loney, 1992
31  *     Steve McClure, 1997
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37 #include "item.h"
38 #include "optlist.h"
39
40 /*
41  * format: anti <SECT>
42  */
43 int
44 anti(void)
45 {
46     struct sctstr sect;
47     int nsect;
48     struct nstr_sect nstr;
49     int mil, che, target;
50     int avail_mil;
51     int amil, ache;
52     int milkilled, chekilled;
53     double odds, damil, dache;
54     int mob;
55     int n_cheleft;
56
57     if (!snxtsct(&nstr, player->argp[1]))
58         return RET_SYN;
59     prdate();
60     nsect = 0;
61     while (nxtsct(&nstr, &sect)) {
62         if (!player->owner)
63             continue;
64         if (nsect++ == 0) {
65             pr("  sect    subversion activity report\n");
66             pr("  ----    --------------------------\n");
67         }
68         mil = sect.sct_item[I_MILIT];
69         che = sect.sct_che;
70         target = sect.sct_che_target;
71         avail_mil = sect.sct_mobil / 2;
72         if (mil <= avail_mil)
73             avail_mil = mil;
74         prxy("%4d,%-4d ", sect.sct_x, sect.sct_y);
75         if (avail_mil <= 0) {
76             pr("No available mil or mob in sector.\n");
77             continue;
78         }
79         pr("Sector mobility/troop strength will allow %d troops to engage.\n",
80            avail_mil);
81
82         if (target == player->cnum) {
83             amil = mil;
84             ache = che;
85             milkilled = 0;
86             chekilled = 0;
87             mob = sect.sct_mobil;
88             while (amil != 0 && ache != 0 && mob > 1) {
89                 damil = amil;
90                 dache = ache;
91                 odds = (dache * 2.0 / (damil + dache));
92                 odds /= hap_fact(getnatp(sect.sct_own),
93                                  getnatp(sect.sct_oldown));
94                 mob = mob - 2;
95                 if (chance(odds)) {
96                     amil = amil - 1;
97                     milkilled = milkilled + 1;
98                 } else {
99                     ache = ache - 1;
100                     chekilled = chekilled + 1;
101                 }
102             }
103             if (mil - milkilled > 0) {
104                 sect.sct_mobil = sect.sct_mobil - chekilled - milkilled;
105                 sect.sct_item[I_MILIT] = mil - milkilled;
106                 if (ache == 0)
107                     sect.sct_che_target = 0;
108                 sect.sct_che = ache;
109                 putsect(&sect);
110                 pr("          Body count:  Military %d - Guerillas %d.\n",
111                    milkilled, chekilled);
112                 if (ache == 0) {
113                     pr("          Partisans cleared out of this sector for now.\n");
114                 } else {
115                     pr("          Partisans still active in this sector.\n");
116                 }
117             } else {
118                 if (opt_MOB_ACCESS) {
119                     sect.sct_mobil =
120                         -(etu_per_update / sect_mob_neg_factor);
121                 } else {
122                     sect.sct_mobil = 0;
123                 }
124                 sect.sct_loyal = sect.sct_loyal * 0.5;
125                 n_cheleft = (random() % 4);
126                 /* 75% chance some che will get left */
127                 if (n_cheleft) {
128                     /* Ok, now leave anywhere from 16% to 25% of the che */
129                     n_cheleft = (ache / (n_cheleft + 3));
130                     ache -= n_cheleft;
131                     sect.sct_che = n_cheleft;
132                 } else {
133                     sect.sct_che = 0;
134                     sect.sct_che_target = 0;
135                 }
136                 sect.sct_item[I_MILIT] = ache;
137                 if (sect.sct_own == sect.sct_oldown)
138                     sect.sct_oldown = 0;
139                 sect.sct_own = sect.sct_oldown;
140                 sect.sct_off = 1;       /* Turn the sector off */
141                 putsect(&sect);
142                 pr("          Partisans take over the sector.  You blew it.\n");
143                 wu(0, sect.sct_oldown,
144                    "Sector %s regained from partisan activity.\n",
145                    xyas(nstr.x, nstr.y, sect.sct_oldown));
146             }
147         } else {
148             pr("          Body count:  Military 0 - Guerillas 0.\n");
149             pr("          Partisans cleared out of this sector for now.\n");
150         }
151     }
152     pr("%d sector%s\n", nsect, splur(nsect));
153     return RET_OK;
154 }