]> git.pond.sub.org Git - empserver/blob - src/lib/subs/rej.c
Change setrel(), setcont(), setrej() to return void
[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 void
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;
63     oldrel = getrel(mynp, them);
64     if (oldrel == rel)
65         return;
66     themname = cname(them);
67     if (rel > oldrel)
68         whichway = "upgraded";
69     else
70         whichway = "downgraded";
71     if (rel == ALLIED) {
72         addendum = "Congratulations!";
73         n_up = N_DECL_ALLY;
74     } else if (rel == FRIENDLY) {
75         n_up = N_UP_FRIENDLY;
76         n_down = N_DOWN_FRIENDLY;
77     } else if (rel == NEUTRAL) {
78         n_up = N_UP_NEUTRAL;
79         n_down = N_DOWN_NEUTRAL;
80     } else if (rel == HOSTILE) {
81         addendum = "Another cold war...";
82         n_up = N_UP_HOSTILE;
83         n_down = N_DOWN_HOSTILE;
84     } else if (rel < HOSTILE) {
85         addendum = "Declaration made (give 'em hell).";
86         n_down = N_DECL_WAR;
87     }
88
89     if (addendum && us == player->cnum && !update_running)
90         pr("%s\n", addendum);
91     mpr(us, "Diplomatic relations with %s %s to \"%s\".\n",
92         themname, whichway, relates[rel]);
93     if (!(getrejects(us, themnp) & REJ_TELE))
94         mpr(them,
95             "Country %s (#%d) has %s their relations with you to \"%s\"!\n",
96             myname, us, whichway, relates[rel]);
97
98     putrel(mynp, them, rel);
99     putnat(mynp);
100
101     if (!player->god) {
102         if (oldrel == ALLIED)
103             nreport(us, N_DIS_ALLY, them, 1);
104         else if (oldrel < HOSTILE && rel >= HOSTILE)
105             nreport(us, N_DIS_WAR, them, 1);
106         if (rel > oldrel)
107             nreport(us, n_up, them, 1);
108         else
109             nreport(us, n_down, them, 1);
110     }
111     if (opt_HIDDEN)
112         setcont(them, us, FOUND_TELE);
113 }
114
115 void
116 setcont(natid us, natid them, int contact)
117 {
118     struct natstr *np = getnatp(us);
119
120     if (CANT_HAPPEN(!np))
121         return;
122     putcontact(np, them, contact);
123     putnat(np);
124 }
125
126 void
127 setrej(natid us, natid them, int how, int what)
128 {
129     struct natstr *np = getnatp(us);
130
131     if (CANT_HAPPEN(!np))
132         return;
133     putreject(np, them, how, what);
134     putnat(np);
135 }