]> git.pond.sub.org Git - empserver/blob - src/lib/subs/rej.c
Oops on invalid arguments in setrel(), setcont(), setrej()
[empserver] / src / lib / subs / rej.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2010, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  rej.c: Various relations setting routines
29  *
30  *  Known contributors to this file:
31  *     Dave Pare, 1994
32  */
33
34 #include <config.h>
35
36 #include "file.h"
37 #include "nat.h"
38 #include "news.h"
39 #include "optlist.h"
40 #include "player.h"
41 #include "prototypes.h"
42 #include "server.h"
43
44 int
45 setrel(natid us, natid them, int rel)
46 {
47     struct natstr *mynp = getnatp(us);
48     struct natstr *themnp = getnatp(them);
49     char *myname = cname(us);
50     char *themname;
51     int oldrel;
52     char *whichway;
53     int n_up = 0;
54     int n_down = 0;
55     char *addendum = NULL;
56
57     if (CANT_HAPPEN(rel < AT_WAR))
58         rel = AT_WAR;
59     if (CANT_HAPPEN(rel > ALLIED))
60         rel = ALLIED;
61     if (CANT_HAPPEN(!mynp || !themnp))
62         return RET_FAIL;
63     if ((oldrel = getrel(mynp, them)) == rel)
64         return RET_FAIL;
65     themname = cname(them);
66     if (rel > oldrel)
67         whichway = "upgraded";
68     else
69         whichway = "downgraded";
70     if (rel == ALLIED) {
71         addendum = "Congratulations!";
72         n_up = N_DECL_ALLY;
73     } else if (rel == FRIENDLY) {
74         n_up = N_UP_FRIENDLY;
75         n_down = N_DOWN_FRIENDLY;
76     } else if (rel == NEUTRAL) {
77         n_up = N_UP_NEUTRAL;
78         n_down = N_DOWN_NEUTRAL;
79     } else if (rel == HOSTILE) {
80         addendum = "Another cold war...";
81         n_up = N_UP_HOSTILE;
82         n_down = N_DOWN_HOSTILE;
83     } else if (rel < HOSTILE) {
84         addendum = "Declaration made (give 'em hell).";
85         n_down = N_DECL_WAR;
86     }
87
88     if (addendum && us == player->cnum && !update_running)
89         pr("%s\n", addendum);
90     mpr(us, "Diplomatic relations with %s %s to \"%s\".\n",
91         themname, whichway, relates[rel]);
92     if (!(getrejects(us, themnp) & REJ_TELE))
93         mpr(them,
94             "Country %s (#%d) has %s their relations with you to \"%s\"!\n",
95             myname, us, whichway, relates[rel]);
96
97     putrel(mynp, them, rel);
98     putnat(mynp);
99
100     if (!player->god) {
101         if (oldrel == ALLIED)
102             nreport(us, N_DIS_ALLY, them, 1);
103         else if (oldrel < HOSTILE && rel >= HOSTILE)
104             nreport(us, N_DIS_WAR, them, 1);
105         if (rel > oldrel)
106             nreport(us, n_up, them, 1);
107         else
108             nreport(us, n_down, them, 1);
109     }
110     if (opt_HIDDEN)
111         setcont(them, us, FOUND_TELE);
112
113     return RET_OK;
114 }
115
116 int
117 setcont(natid us, natid them, int contact)
118 {
119     struct natstr *np = getnatp(us);
120
121     if (CANT_HAPPEN(!np))
122         return 0;
123     putcontact(np, them, contact);
124     putnat(np);
125     return 1;
126 }
127
128 int
129 setrej(natid us, natid them, int how, int what)
130 {
131     struct natstr *np = getnatp(us);
132
133     if (CANT_HAPPEN(!np))
134         return 0;
135     putreject(np, them, how, what);
136     putnat(np);
137     return 1;
138 }