]> git.pond.sub.org Git - empserver/blob - src/lib/subs/rej.c
20b3f0dfaf055a2475bd56e98c026952d0654f1c
[empserver] / src / lib / subs / rej.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2011, 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  */
32
33 #include <config.h>
34
35 #include "file.h"
36 #include "nat.h"
37 #include "news.h"
38 #include "optlist.h"
39 #include "player.h"
40 #include "prototypes.h"
41 #include "server.h"
42
43 void
44 setrel(natid us, natid them, int rel)
45 {
46     struct natstr *mynp = getnatp(us);
47     struct natstr *themnp = getnatp(them);
48     int oldrel;
49     char *whichway;
50     int n_up = 0;
51     int n_down = 0;
52     char *addendum = NULL;
53
54     if (CANT_HAPPEN(rel < AT_WAR))
55         rel = AT_WAR;
56     if (CANT_HAPPEN(rel > ALLIED))
57         rel = ALLIED;
58     if (CANT_HAPPEN(!mynp || !themnp))
59         return;
60     if (us == them)
61         return;
62     oldrel = relations_with(us, them);
63     if (oldrel == rel)
64         return;
65     if (rel > oldrel)
66         whichway = "upgraded";
67     else
68         whichway = "downgraded";
69     if (rel == ALLIED) {
70         addendum = "Congratulations!";
71         n_up = N_DECL_ALLY;
72     } else if (rel == FRIENDLY) {
73         n_up = N_UP_FRIENDLY;
74         n_down = N_DOWN_FRIENDLY;
75     } else if (rel == NEUTRAL) {
76         n_up = N_UP_NEUTRAL;
77         n_down = N_DOWN_NEUTRAL;
78     } else if (rel == HOSTILE) {
79         addendum = "Another cold war...";
80         n_up = N_UP_HOSTILE;
81         n_down = N_DOWN_HOSTILE;
82     } else if (rel < HOSTILE) {
83         addendum = "Declaration made (give 'em hell).";
84         n_down = N_DECL_WAR;
85     }
86
87     if (addendum && us == player->cnum && !update_running)
88         pr("%s\n", addendum);
89     mpr(us, "Diplomatic relations with %s %s to \"%s\".\n",
90         cname(them), whichway, relates[rel]);
91     if (!(getrejects(us, themnp) & REJ_TELE))
92         mpr(them,
93             "Country %s (#%d) has %s their relations with you to \"%s\"!\n",
94             cname(us), us, whichway, relates[rel]);
95
96     putrel(mynp, them, rel);
97     putnat(mynp);
98
99     if (!player->god) {
100         if (oldrel == ALLIED)
101             nreport(us, N_DIS_ALLY, them, 1);
102         else if (oldrel < HOSTILE && rel >= HOSTILE)
103             nreport(us, N_DIS_WAR, them, 1);
104         if (rel > oldrel)
105             nreport(us, n_up, them, 1);
106         else
107             nreport(us, n_down, them, 1);
108     }
109     if (opt_HIDDEN)
110         setcont(them, us, FOUND_TELE);
111 }
112
113 void
114 setcont(natid us, natid them, int contact)
115 {
116     struct natstr *np = getnatp(us);
117
118     if (CANT_HAPPEN(!np))
119         return;
120     putcontact(np, them, contact);
121     putnat(np);
122 }
123
124 void
125 setrej(natid us, natid them, int how, int what)
126 {
127     struct natstr *np = getnatp(us);
128
129     if (CANT_HAPPEN(!np))
130         return;
131     putreject(np, them, how, what);
132     putnat(np);
133 }