Freeciv21
Develop your civilization from humble roots to a global empire
tradecalculation.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9 **************************************************************************/
10 #pragma once
11 
12 #include <QList>
13 
14 struct city;
15 
16 /**************************************************************************
17  Helper item for trade calculation
18 ***************************************************************************/
19 class trade_city {
20 public:
21  trade_city(struct city *pcity);
22 
23  bool done;
24  int over_max;
26  int trade_num; // already created + generated
27  QList<struct city *> curr_tr_cities;
28  QList<struct city *> new_tr_cities;
29  QList<struct city *> pos_cities;
30  struct city *city;
31  struct tile *tile;
32 };
33 
34 /**************************************************************************
35  Struct of 2 tiles, used for drawing trade routes.
36  Also assigned caravan if it was sent
37 ***************************************************************************/
38 struct qtiles {
39  struct tile *t1;
40  struct tile *t2;
41  struct unit *autocaravan;
42 
43  bool operator==(const qtiles &a) const
44  {
45  return (t1 == a.t1 && t2 == a.t2 && autocaravan == a.autocaravan);
46  }
47 };
48 
49 /**************************************************************************
50  Class trade generator, used for calulating possible trade routes
51 ***************************************************************************/
53 public:
55 
56  bool hover_city;
57  QList<qtiles> lines;
58  QList<struct city *> virtual_cities;
59  QList<trade_city *> cities;
60 
61  void add_all_cities();
62  void add_city(struct city *pcity);
63  void add_tile(struct tile *ptile);
64  void calculate();
65  void clear_trade_planing();
66  void remove_city(struct city *pcity);
67  void remove_virtual_city(struct tile *ptile);
68 
69 private:
70  bool discard_any(trade_city *tc, int freeroutes);
71  int find_over_max(struct city *pcity);
73  void check_if_done(trade_city *tc1, trade_city *tc2);
74  void discard();
75  void discard_trade(trade_city *tc1, trade_city *tc2);
76  void find_certain_routes();
77 };
struct tile * tile
QList< struct city * > pos_cities
QList< struct city * > new_tr_cities
trade_city(struct city *pcity)
Constructor for trade city used to trade calculation.
QList< struct city * > curr_tr_cities
struct city * city
void add_city(struct city *pcity)
Adds single city to trade generator.
void find_certain_routes()
Adds routes for cities which can only have maximum possible trade routes.
trade_city * find_most_free()
Finds city with highest trade routes possible.
void discard_trade(trade_city *tc1, trade_city *tc2)
Drops trade routes between given cities.
void add_tile(struct tile *ptile)
Adds/removes tile to trade generator.
trade_generator()
Constructor for trade calculator.
void remove_virtual_city(struct tile *ptile)
Removes virtual city from trade generator.
QList< trade_city * > cities
void add_all_cities()
Adds all cities to trade generator.
void clear_trade_planing()
Clears genrated routes, virtual cities, cities.
void discard()
Drops all possible trade routes.
void remove_city(struct city *pcity)
Removes single city from trade generator.
QList< qtiles > lines
bool discard_any(trade_city *tc, int freeroutes)
Drops all trade routes for given city.
void check_if_done(trade_city *tc1, trade_city *tc2)
Marks cities with full trade routes to finish searching.
QList< struct city * > virtual_cities
int find_over_max(struct city *pcity)
Finds highest number of trade routes over maximum for all cities, skips given city.
void calculate()
Finds trade routes to establish.
Definition: city.h:291
struct tile * t1
struct tile * t2
bool operator==(const qtiles &a) const
struct unit * autocaravan
Definition: tile.h:42
Definition: unit.h:134