Freeciv21
Develop your civilization from humble roots to a global empire
diptreaty.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // utility
16 #include "requirements.h"
17 
18 // Used in the network protocol
19 #define SPECENUM_NAME clause_type
20 #define SPECENUM_VALUE0 CLAUSE_ADVANCE
21 #define SPECENUM_VALUE0NAME "Advance"
22 #define SPECENUM_VALUE1 CLAUSE_GOLD
23 #define SPECENUM_VALUE1NAME "Gold"
24 #define SPECENUM_VALUE2 CLAUSE_MAP
25 #define SPECENUM_VALUE2NAME "Map"
26 #define SPECENUM_VALUE3 CLAUSE_SEAMAP
27 #define SPECENUM_VALUE3NAME "Seamap"
28 #define SPECENUM_VALUE4 CLAUSE_CITY
29 #define SPECENUM_VALUE4NAME "City"
30 #define SPECENUM_VALUE5 CLAUSE_CEASEFIRE
31 #define SPECENUM_VALUE5NAME "Ceasefire"
32 #define SPECENUM_VALUE6 CLAUSE_PEACE
33 #define SPECENUM_VALUE6NAME "Peace"
34 #define SPECENUM_VALUE7 CLAUSE_ALLIANCE
35 #define SPECENUM_VALUE7NAME "Alliance"
36 #define SPECENUM_VALUE8 CLAUSE_VISION
37 #define SPECENUM_VALUE8NAME "Vision"
38 #define SPECENUM_VALUE9 CLAUSE_EMBASSY
39 #define SPECENUM_VALUE9NAME "Embassy"
40 #define SPECENUM_COUNT CLAUSE_COUNT
41 #include "specenum_gen.h"
42 
43 #define is_pact_clause(x) \
44  ((x == CLAUSE_CEASEFIRE) || (x == CLAUSE_PEACE) || (x == CLAUSE_ALLIANCE))
45 
46 struct clause_info {
47  enum clause_type type;
48  bool enabled;
49  struct requirement_vector giver_reqs;
50  struct requirement_vector receiver_reqs;
51 };
52 
53 // For when we need to iterate over treaties
54 struct Clause;
55 #define SPECLIST_TAG clause
56 #define SPECLIST_TYPE struct Clause
57 #include "speclist.h"
58 
59 #define clause_list_iterate(clauselist, pclause) \
60  TYPED_LIST_ITERATE(struct Clause, clauselist, pclause)
61 #define clause_list_iterate_end LIST_ITERATE_END
62 
63 struct Clause {
64  enum clause_type type;
65  struct player *from;
66  int value;
67 };
68 
69 struct Treaty {
70  struct player *plr0, *plr1;
72  struct clause_list *clauses;
73 };
74 
75 bool diplomacy_possible(const struct player *pplayer,
76  const struct player *aplayer);
77 bool could_meet_with_player(const struct player *pplayer,
78  const struct player *aplayer);
79 bool could_intel_with_player(const struct player *pplayer,
80  const struct player *aplayer);
81 
82 void init_treaty(struct Treaty *ptreaty, struct player *plr0,
83  struct player *plr1);
84 bool add_clause(struct Treaty *ptreaty, struct player *pfrom,
85  enum clause_type type, int val);
86 bool remove_clause(struct Treaty *ptreaty, struct player *pfrom,
87  enum clause_type type, int val);
88 void clear_treaty(struct Treaty *ptreaty);
89 
90 void clause_infos_init();
91 void clause_infos_free();
92 struct clause_info *clause_info_get(enum clause_type type);
93 
94 bool clause_enabled(enum clause_type type, struct player *from,
95  struct player *to);
bool add_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val)
Add clause to treaty.
Definition: diptreaty.cpp:134
struct clause_info * clause_info_get(enum clause_type type)
Free memory associated with clause infos.
Definition: diptreaty.cpp:257
bool clause_enabled(enum clause_type type, struct player *from, struct player *to)
Is clause enabled in this game? Currently this does not consider clause requirements that may change ...
Definition: diptreaty.cpp:272
void clear_treaty(struct Treaty *ptreaty)
Free the clauses of a treaty.
Definition: diptreaty.cpp:100
void init_treaty(struct Treaty *ptreaty, struct player *plr0, struct player *plr1)
Initialize treaty structure between two players.
Definition: diptreaty.cpp:87
void clause_infos_free()
Free memory associated with clause infos.
Definition: diptreaty.cpp:244
void clause_infos_init()
Initialize clause info structures.
Definition: diptreaty.cpp:229
bool remove_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val)
Remove clause from treaty.
Definition: diptreaty.cpp:110
bool could_intel_with_player(const struct player *pplayer, const struct player *aplayer)
Returns TRUE iff pplayer can get intelligence about aplayer.
Definition: diptreaty.cpp:74
bool diplomacy_possible(const struct player *pplayer, const struct player *aplayer)
Returns TRUE iff pplayer could do diplomancy in the game at all.
Definition: diptreaty.cpp:28
bool could_meet_with_player(const struct player *pplayer, const struct player *aplayer)
Returns TRUE iff pplayer could do diplomatic meetings with aplayer.
Definition: diptreaty.cpp:56
enum clause_type type
Definition: diptreaty.h:64
struct player * from
Definition: diptreaty.h:65
int value
Definition: diptreaty.h:66
struct player * plr0
Definition: diptreaty.h:70
bool accept0
Definition: diptreaty.h:71
bool accept1
Definition: diptreaty.h:71
struct clause_list * clauses
Definition: diptreaty.h:72
struct player * plr1
Definition: diptreaty.h:70
struct requirement_vector receiver_reqs
Definition: diptreaty.h:50
struct requirement_vector giver_reqs
Definition: diptreaty.h:49
enum clause_type type
Definition: diptreaty.h:47
bool enabled
Definition: diptreaty.h:48
Definition: player.h:231