Import of Empire 4.2.12
This commit is contained in:
commit
d8b7fdfae1
817 changed files with 126589 additions and 0 deletions
134
src/lib/subs/trechk.c
Normal file
134
src/lib/subs/trechk.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Empire - A multi-player, client/server Internet based war game.
|
||||
* Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
|
||||
* Ken Stevens, Steve McClure
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* ---
|
||||
*
|
||||
* See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
|
||||
* related information and legal notices. It is expected that any future
|
||||
* projects/authors will amend these files as needed.
|
||||
*
|
||||
* ---
|
||||
*
|
||||
* trechk.c: Check to see if an actor has violated a treaty.
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Steve McClure, 1998-1999
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Check to see if an actor has a treaty forbidding a given action,
|
||||
* and if so, see if the actor wishes to break the treaty.
|
||||
* All applicable treaties are checked. All treaties must be broken
|
||||
* if the action is to be allowed. Propsed treaties are warned about,
|
||||
* but no mention of broken pending treaties are made in the news.
|
||||
*/
|
||||
|
||||
#include "misc.h"
|
||||
#include "treaty.h"
|
||||
#include "nat.h"
|
||||
#include "news.h"
|
||||
#include "file.h"
|
||||
#include "xy.h"
|
||||
#include "nsc.h"
|
||||
#include "prototypes.h"
|
||||
#include "optlist.h"
|
||||
|
||||
int
|
||||
trechk(register natid actor, register natid victim, int provision)
|
||||
{
|
||||
register natid cn;
|
||||
s_char buf[1024];
|
||||
int news_verb;
|
||||
int involved[MAXNOC];
|
||||
struct trtstr treaty;
|
||||
time_t now;
|
||||
int conditions;
|
||||
natid other;
|
||||
int broken;
|
||||
int applied;
|
||||
struct nstr_item nstr;
|
||||
|
||||
if (!opt_TREATIES)
|
||||
return 1;
|
||||
(void) time(&now);
|
||||
broken = 0;
|
||||
applied = 0;
|
||||
for (cn = 0; cn < MAXNOC; cn++)
|
||||
involved[cn] = 0;
|
||||
snxtitem_all(&nstr, EF_TREATY);
|
||||
while (nxtitem(&nstr, (s_char *)&treaty)) {
|
||||
if (treaty.trt_status == TS_FREE)
|
||||
continue;
|
||||
if (treaty.trt_exp < now)
|
||||
continue;
|
||||
if (actor == treaty.trt_cna) {
|
||||
conditions = treaty.trt_acond;
|
||||
other = treaty.trt_cnb;
|
||||
} else if (actor == treaty.trt_cnb) {
|
||||
conditions = treaty.trt_bcond;
|
||||
other = treaty.trt_cna;
|
||||
} else
|
||||
continue;
|
||||
if ((conditions & provision) == 0)
|
||||
continue;
|
||||
if (victim != other) {
|
||||
switch (provision) {
|
||||
/* These are violations no matter who the victim is */
|
||||
case NEWSHP:
|
||||
case NEWLND:
|
||||
case NEWNUK:
|
||||
case NEWPLN:
|
||||
case TRTENL:
|
||||
break;
|
||||
default:
|
||||
/* The rest are only violations against the victim */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* treaty applies to actor */
|
||||
applied++;
|
||||
pr("This action is in contravention of ");
|
||||
if (treaty.trt_status == TS_PROPOSED)
|
||||
pr("pending ");
|
||||
pr(" treaty #%d (with %s)\n", nstr.cur, cname(other));
|
||||
getstring("Do you wish to go ahead anyway? [yn] ", buf);
|
||||
if (*buf == 'n' || *buf == 'N')
|
||||
broken = 0;
|
||||
else
|
||||
broken = 1;
|
||||
if (treaty.trt_status == TS_SIGNED)
|
||||
involved[other]++;
|
||||
}
|
||||
if (applied > 0) {
|
||||
news_verb = N_HONOR_TRE;
|
||||
if (broken > 0)
|
||||
news_verb = N_VIOL_TRE;
|
||||
for (cn=0; cn < MAXNOC; cn++)
|
||||
if (involved[cn] > 0)
|
||||
nreport(actor, news_verb, cn, 1);
|
||||
}
|
||||
if (applied && !broken) {
|
||||
/*
|
||||
* if any treaty applied, and none were broken
|
||||
* the intended action is NOT performed.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue