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