]> git.pond.sub.org Git - empserver/blob - src/lib/subs/rej.c
Update copyright notice
[empserver] / src / lib / subs / rej.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2015, 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  *  rej.c: Various relations setting routines
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1994
31  *     Markus Armbruster, 2005-2013
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     int oldrel;
50     char *whichway;
51     int n_up = 0;
52     int n_down = 0;
53     char *addendum = NULL;
54
55     if (CANT_HAPPEN(rel < AT_WAR))
56         rel = AT_WAR;
57     if (CANT_HAPPEN(rel > ALLIED))
58         rel = ALLIED;
59     if (CANT_HAPPEN(!mynp || !themnp))
60         return;
61     if (us == them)
62         return;
63     oldrel = relations_with(us, them);
64     if (oldrel == rel)
65         return;
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         cname(them), whichway, relates[rel]);
92     if (!(getrejects(us, themnp) & REJ_TELE))
93         mpr(them,
94             "Country %s has %s their relations with you to \"%s\"!\n",
95             prnat(mynp), 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
114 void
115 setcont(natid us, natid them, int contact)
116 {
117     struct natstr *np = getnatp(us);
118
119     if (CANT_HAPPEN(!np))
120         return;
121     putcontact(np, them, contact);
122     putnat(np);
123 }
124
125 void
126 setrej(natid us, natid them, int how, int what)
127 {
128     struct natstr *np = getnatp(us);
129
130     if (CANT_HAPPEN(!np))
131         return;
132     putreject(np, them, how, what);
133     putnat(np);
134 }