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