1 /**********************************************************************
2  *
3  *   FreeDoko a Doppelkopf-Game
4  *
5  *   Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders
6  *
7  *   This program is free software; you can redistribute it and/or
8  *   modify it under the terms of the GNU General Public License as
9  *   published by the Free Software Foundation; either version 2 of
10  *   the License, or (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *   You can find this license in the file 'gpl.txt'.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  *   MA  02111-1307  USA
22  *
23  *  Contact:
24  *    Diether Knof dknof@posteo.de
25  *
26  **********************************************************************/
27 
28 #pragma once
29 
30 #include "../basetypes.h"
31 
32 #include "players.h"
33 #include "../player/player.h"
34 class Rule;
35 class GamePointsTable;
36 class GameSummary;
37 class Human;
38 
39 
40 class Party;
41 extern unique_ptr<Party> party;
42 
43 using PartyPlayer = Player;
44 
45 class Party {
46   friend class Game;
47   public:
48   using Player = PartyPlayer;
49   using Players = PartyPlayers;
50 
51   Party();
52   Party(Party const&) = delete;
53   Party& operator=(Party const&) = delete;
54 
55   void init();
56 
57   // signals
58   static Signal<void(Party&)>& signal_open() noexcept;
59   Signal<void()>& signal_get_settings() noexcept;
60   Signal<void()>& signal_loaded() noexcept;
61   Signal<void()>& signal_start() noexcept;
62   Signal<void(unsigned)>& signal_start_round() noexcept;
63   Signal<void()>& signal_finish() noexcept;
64   Signal<void()>& signal_close() noexcept;
65   Signal<void()>& signal_seed_changed() noexcept;
66   Signal<void()>& signal_startplayer_changed() noexcept;
67 
68   Rule const& rule() const noexcept;
69   Rule& rule() noexcept;
70 
71   Players const& players() const noexcept;
72   Players& players() noexcept;
73 
74   bool random_seed() const noexcept;
75   Seed seed() const noexcept;
76   void set_seed(Seed seed) noexcept;
77   void set_random_seed() noexcept;
78   Seed next_seed() noexcept;
79 
80   bool random_startplayer() const noexcept;
81   unsigned startplayer() const noexcept;
82   void set_startplayer(unsigned startplayer) noexcept;
83   void set_random_startplayer() noexcept;
84 
85   int points() const noexcept;
86 
87   Game const& game() const noexcept;
88   Game& game() noexcept;
89 
90   void set_replay_game() noexcept;
91   bool is_replayed_game() const noexcept;
92 
93   // whether the party can be configured (seed, startplayer)
94   bool in_configuration() const noexcept;
95 
96   unsigned roundno() const noexcept;
97   unsigned remaining_rounds() const noexcept;
98   unsigned remaining_normal_games() const noexcept;
99   unsigned remaining_games() const noexcept;
100   unsigned gameno() const noexcept;
101   unsigned finished_games() const noexcept;
102   bool is_duty_soli_round() const noexcept;
103   bool is_duty_soli_round(unsigned round) const noexcept;
104   bool is_last_game() const noexcept;
105   bool is_finished() const noexcept;
106 
107   // the remaining points for the party
108   int remaining_points() const noexcept;
109 
110   bool starts_new_round(unsigned gameno) const noexcept;
111   unsigned round_of_game(unsigned gameno) const noexcept;
112   unsigned round_startgame(unsigned roundno) const noexcept;
113 
114   void add_game_summary(unique_ptr<GameSummary> game_summary);
115   GameSummary const& last_game_summary() const noexcept;
116   GameSummary const& game_summary(unsigned const gameno) const;
117 
118   vector<unsigned> const& bock_multipliers() const noexcept;
119   // the bock multiplier for the current game
120   unsigned current_bock_multiplier() const;
121   // the bock multiplier for the game gameno
122   unsigned bock_multiplier(unsigned gameno) const noexcept;
123 
124 
125   int pointsum() const;
126   int pointsum_till_game(unsigned gameno) const;
127   int pointsum_till_round(unsigned roundno) const;
128   int pointsum_in_round(unsigned roundno) const;
129   int pointsum(Player const& player) const;
130   int pointsum(unsigned playerno) const;
131   int pointsum_till_game(unsigned gameno, unsigned playerno) const;
132   int pointsum_till_round(unsigned roundno, unsigned playerno) const;
133   int pointsum_in_round(unsigned roundno, unsigned playerno) const;
134 
135   unsigned rang(unsigned playerno) const;
136   unsigned rang(Player const& player) const;
137 
138   unsigned played_duty_soli(unsigned playerno) const;
139   unsigned played_duty_soli(Player const& player) const;
140   unsigned played_duty_color_soli(unsigned playerno) const;
141   unsigned played_duty_color_soli(Player const& player) const;
142   unsigned played_duty_picture_soli(unsigned playerno) const;
143   unsigned played_duty_picture_soli(Player const& player) const;
144   unsigned played_duty_free_soli(unsigned playerno) const;
145   unsigned played_duty_free_soli(Player const& player) const;
146   unsigned played_lust_soli(unsigned playerno) const;
147   unsigned played_lust_soli(Player const& player) const;
148 
149   unsigned remaining_duty_soli() const;
150   unsigned remaining_duty_soli(unsigned playerno) const;
151   unsigned remaining_duty_soli(Player const& player) const;
152   unsigned remaining_duty_color_soli(unsigned playerno) const;
153   unsigned remaining_duty_color_soli(Player const& player) const;
154   unsigned remaining_duty_picture_soli(unsigned playerno) const;
155   unsigned remaining_duty_picture_soli(Player const& player) const;
156   unsigned remaining_duty_free_soli(unsigned playerno) const;
157   unsigned remaining_duty_free_soli(Player const& player) const;
158 
159   void write(ostream& ostr) const;
160   void write_pointstable(ostream& ostr) const;
161   bool read(istream& istr);
162 
163   // save the party
164   bool save(string const& filename) const;
165   // load the party
166   bool load(string const& filename);
167   // load the players
168   bool load_players();
169 
170 
171   // open the party
172   void open();
173   // reset the party
174   void reset();
175   // play the party (main program flow)
176   void play();
177   // play a game
178   void play_game();
179   // close the party
180   void close();
181 
182   // change of the rules
183   void rule_changed(int type, void const* old_value);
184 
185   private:
186   // save the party automatically
187   bool auto_save() const;
188   public:
189   void remove_auto_save() const;
190   // save the changes of the party (t.i. rules and players)
191   void save_changes() const;
192 
193   private:
194   // increment the round
195   void increment_round();
196 
197   private:
198   // rules for the party
199   unique_ptr<Rule> rule_;
200   // players
201   unique_ptr<Players> players_;
202   // starting seed
203   bool random_seed_ = true;
204   Seed first_seed_ = 0;
205   // starting startplayer
206   bool random_startplayer_ = false;
207   unsigned first_startplayer_ = 0;
208   // the game in which the round starts
209   vector<unsigned> round_startgame_;
210   // Anzahl der gespielten normalen Spiele;
211   unsigned finished_normal_games_ = 0;
212 
213   // the number of the duty soli round
214   optional<unsigned> duty_soli_round_;
215 
216   // the points for the party
217   int points_;
218   // current game
219   unique_ptr<Game> game_;
220   // the current seed
221   Seed seed_ = 0;
222   // the current startplayer
223   unsigned startplayer_ = 0;
224   // whether to replay the last game
225   bool replay_game_ = false;
226   // whether this is a replayed game
227   bool is_replayed_game_ = false;
228 
229   // game summaries
230   vector<unique_ptr<GameSummary>> game_summaries_;
231   // the multipliers for bock games
232   vector<unsigned> bock_multipliers_;
233 
234   // set_ai_players
235   // partie typ (tutorial...)
236   // pflichtstsoli
237   // punkte topf
238   // tunier status
239 
240   // Signals
241   static Signal<void(Party&)> signal_open_;
242   Signal<void()> signal_get_settings_;
243   Signal<void()> signal_loaded_;
244   Signal<void()> signal_start_;
245   Signal<void(unsigned)> signal_start_round_;
246   Signal<void()> signal_finish_;
247   Signal<void()> signal_close_;
248   Signal<void()> signal_seed_changed_;
249   Signal<void()> signal_startplayer_changed_;
250 }; // class Party
251 
252 ostream& operator<<(ostream& ostr, Party const& p);
253