update build system to use RcB2
[rofl0r-pato.git] / pato.h
blob7d5049471bb85bdfc391266ea5efb149806f1fb8
1 #ifndef _PATO_H
2 #define _PATO_H
4 #include <stddef.h>
5 #include <stdint.h>
7 #include "../lib/include/stringptr.h"
9 #define MAX_PLAYERS 64
10 #define CITY_MAX_INDUSTRYTYPES 5
11 #define MAX_CITIES 64
12 #define MAX_BRANCHES 32
13 #define MAX_CONVOYS 64
14 #define MAX_NOTIFICATIONS 16
16 typedef enum {
17 GT_NONE = 0,
18 GT_WOOD,
19 GT_MEAT,
20 GT_VEG,
21 GT_BARLEYJUICE,
22 GT_CROP,
23 GT_BRICK,
24 GT_ORE,
25 GT_HEMP,
26 GT_HONEY,
27 GT_COPPER,
28 GT_SALT,
29 GT_WOOL,
30 GT_TOOL,
31 GT_ROPE,
32 GT_MET,
33 GT_CERAMICS,
34 GT_HAM,
35 GT_CLOTH,
36 GT_BEER,
37 GT_FUR,
38 GT_CHEESE,
39 GT_PITCH,
40 GT_FISH,
41 GT_WINE,
42 GT_MAX
43 } Goodtype;
45 typedef Goodtype IndustryType;
47 typedef enum {
48 GC_NONE = 0,
49 GC_A, // grundwaren
50 GC_B, // rohstoffe
51 GC_C, // fertigwaren
52 GC_D, // regionalwaren
53 GC_MAX
54 } Goodcategory;
56 typedef struct {
57 stringptr* name;
58 Goodtype type;
59 Goodcategory cat;
60 } Good;
62 typedef struct {
63 size_t buildcost;
64 float yield;
65 float consumation[GT_MAX];
66 } Factory;
68 typedef struct {
69 size_t maxworkersperfactory;
70 size_t workersalary;
71 } FactoryCommon;
73 typedef struct {
74 size_t buildcost;
75 size_t storage;
76 } Warehouse;
79 typedef struct {
80 float stock[GT_MAX];
81 float avgPricePayed[GT_MAX];
82 } Market;
84 typedef struct {
85 float x;
86 float y;
87 } Coords;
89 typedef enum {
90 PT_NONE = 0,
91 PT_BEGGAR,
92 PT_WORKER,
93 PT_COMMONER,
94 PT_ARISTOCRAT,
95 PT_MAX
96 } populationType;
98 typedef enum {
99 ST_NONE = 0,
100 ST_A,
101 ST_B,
102 ST_C,
103 ST_D,
104 ST_MAX
105 } ShipTypes;
107 typedef struct {
108 size_t total;
109 size_t numShips[ST_MAX];
110 } ShipCounter;
112 typedef struct {
113 ShipCounter availableShips;
114 } Shipyard;
116 typedef struct {
117 stringptr* name;
118 Market market;
119 Coords coords;
120 float tax;
121 long long money;
122 IndustryType industry[CITY_MAX_INDUSTRYTYPES];
123 size_t numFactories[CITY_MAX_INDUSTRYTYPES];
124 size_t population[PT_MAX];
125 float populationMood[PT_MAX];
126 Shipyard shipyard;
127 } City;
129 typedef struct {
130 stringptr* name;
131 size_t maxload;
132 size_t buildTime;
133 size_t buildCost;
134 size_t speed;
135 size_t agility;
136 size_t stability;
137 size_t maxCannons;
138 size_t minCrew;
139 size_t maxCrew;
140 size_t woodReq;
141 size_t clothReq;
142 size_t pitchReq;
143 size_t ropeReq;
144 size_t runningCost;
145 } ShipProps;
147 typedef enum {
148 SLT_NONE = 0,
149 SLT_SEA,
150 SLT_CITY,
151 SLT_MAX
152 } ShipLocationType;
155 typedef struct {
156 float condition[ST_MAX];
157 } ShipCondition;
159 typedef struct {
160 stringptr* name;
161 ShipCounter shipcounter;
162 ShipLocationType loc;
163 size_t locCity;
164 size_t fromCity;
165 size_t stepsdone;
166 Coords coords;
167 size_t numSailors;
168 size_t captainSalary;
169 float totalload;
170 Market load;
171 float condition;
172 } Convoy;
174 typedef enum {
175 PLT_NONE = 0,
176 PLT_CPU,
177 PLT_USER,
178 PLT_MAX
179 } PlayerType;
181 typedef enum {
182 NT_NONE = 0,
183 NT_NO_MONEY,
184 NT_BAD_MOOD,
185 NT_OUT_OF_PRODUCTIONGOODS,
186 NT_STOCK_FULL,
187 NT_SHIPS_BOUGHT,
188 NT_MAX
189 } NotificationType;
191 extern const stringptr* NotificationNames[NT_MAX];
192 stringptr* getNotificationName(NotificationType x);
194 typedef struct {
195 NotificationType nt;
196 size_t val1;
197 size_t val2;
198 float fval1;
199 float fval2;
200 } Notification;
202 typedef struct {
203 Notification notifications[MAX_NOTIFICATIONS];
204 size_t last;
205 } Inbox;
207 typedef enum {
208 AIP_NONE = 0,
209 AIP_SATISFY_MOODS = 1,
210 AIP_PURCHASE_PRODUCTION_GOODS = 2,
211 AIP_SELL_GOODS_FROM_STOCK = 4
212 } AIPlan;
214 typedef struct {
215 size_t moodybranch;
216 Goodtype req_production_good;
217 size_t branch_req_goods;
218 float amount_required;
219 } Plandata;
221 typedef struct {
222 stringptr* name;
223 PlayerType type;
224 size_t numBranches;
225 size_t branchFactories[MAX_BRANCHES][CITY_MAX_INDUSTRYTYPES + 1]; // number of factories of each type. plus warehouses.
226 Market branchStock[MAX_BRANCHES];
227 size_t branchCity[MAX_BRANCHES];
228 size_t branchWorkers[MAX_BRANCHES];
229 size_t numConvoys;
230 Convoy convoys[MAX_CONVOYS];
231 size_t numShipLocations;
232 size_t shipLocations[MAX_CITIES]; // stores the city "id" with single ships (those not in a convoy)
233 ShipCounter singleShips[MAX_CITIES]; // stored in the order of shipLocations
234 ShipCondition singleShipConditions[MAX_CITIES]; // same
235 long long money;
236 Inbox inbox;
237 AIPlan plan;
238 Plandata plandata;
239 } Player;
241 typedef struct {
242 uint64_t date; // seconds till genesis
243 size_t monthsperyear;
244 size_t dayspermonth;
245 size_t hoursperday;
246 size_t minutesperhour;
247 size_t secondsperminute;
248 size_t _dayseconds;
249 float _fdaysperyear;
250 } World;
252 typedef enum {
253 SELL_FROM_OVERPRODUCTION = 1,
254 SELL_FROM_STOCK = 2,
255 SELL_FROM_CONVOY = 4,
256 SELL_FROM_CITY = 8,
257 SELL_TO_CITY = 16,
258 SELL_TO_PLAYERSTOCK = 32,
259 SELL_TO_CONVOY = 64,
260 SELL_TO_POPULATION = 128
261 } sellFlags;
263 //lookup table for producer cities for certain goods.
264 extern size_t producers[GT_MAX][MAX_CITIES];
265 extern size_t producerCount[GT_MAX];
266 extern size_t numCities;
267 extern size_t numPlayers;
268 extern float populationConsumation[PT_MAX][GT_MAX];
270 extern World world;
271 extern Player Players[MAX_PLAYERS];
272 extern City Cities[MAX_CITIES];
273 extern const Notification emptyNotification;
274 extern const unsigned long long goodcat_minprice[];
275 extern const unsigned long long rentTax[PT_MAX];
276 extern FactoryCommon factoryProps;
277 extern Factory Factories[GT_MAX];
278 extern char externalGoodRequiredForProduction[GT_MAX]; // if another good is req. for the production of this
279 extern char goodRequiredForProduction[GT_MAX]; // if this good is required for the production of another good
280 extern Warehouse Storage;
281 extern Warehouse Branchoffice;
282 extern const Good Goods[];
284 extern size_t GAME_SPEED;
286 extern const ShipProps shipProps[];
287 extern const stringptr* populationDesc[];
289 float getPopulationConsumationPerPopulationType(Goodtype g, size_t c, populationType p);
290 float getPopulationConsumation(Goodtype g, size_t c);
292 PlayerType playerTypeFromString(stringptr* pt);
293 Notification makeNotification(NotificationType nt, size_t val1, size_t val2, float fval1, float fval2);
294 void notify(size_t player, Notification n);
295 stringptr* stringFromPopulationType(populationType p);
296 Goodtype goodTypeFromString(stringptr* good);
297 stringptr* stringFromGoodType(Goodtype g);
298 void initWorld(void);
299 void initConsumationTable(void);
300 void initCities(void);
301 ptrdiff_t findCityFromString(stringptr* name);
302 ShipLocationType shipLocationTypeFromString(stringptr* loc);
303 void initPlayers(void);
304 void initBuildings(void);
305 size_t getMaxWorkerCount(size_t branch, size_t player);
306 size_t getFreeJobs(size_t branch, size_t player);
307 void getPlayersWithFreeWorkCapacity(size_t city, size_t* totalcapacity, size_t* num_players, size_t* affected_players, size_t* free_jobs);
308 ptrdiff_t getShipLocationIDFromCity(size_t city, size_t player);
309 ptrdiff_t getCityIDFromBranch(size_t branch, size_t player);
310 ptrdiff_t getBranchIDFromCity(size_t city, size_t player);
311 stringptr* getPlayerName(size_t playerid);
312 size_t getPlayerMaxBranchStorage(size_t branch, size_t player);
313 float getPlayerFreeBranchStorage(size_t branch, size_t player);
314 size_t getPlayerFactoryCount(size_t branch, size_t player);
315 size_t getCityPopulation(size_t city);
316 float calculatePrice(size_t city, Goodtype g, float amount, unsigned sell);
317 void sell(size_t city, size_t player, size_t branch, size_t convoy, Goodtype g, float amount, sellFlags flags);
318 void newDay(void);
319 size_t buyShips(size_t city, size_t player, size_t shipcount, ShipTypes t);
320 void addToConvoy(Convoy* c, size_t shiploc, size_t player, size_t numships, ShipTypes t);
321 ptrdiff_t makeConvoy(size_t city, size_t shiploc, size_t player, size_t numships, ShipTypes t);
322 size_t getMinCrew(size_t convoy, size_t player);
323 void hireCrew(size_t convoy, size_t player, size_t numsailors);
324 void hireCaptain(size_t convoy, size_t player);
325 unsigned requireProductionGood(size_t player, size_t branch, Goodtype t);
326 void sellWholeStock(size_t player, size_t branch, unsigned skiprequired);
327 unsigned convoysAvailable(size_t player, size_t branch);
328 float calculateDistance(Coords* a, Coords* b);
329 ptrdiff_t findNearestCityWithGood(size_t city, Goodtype neededgood);
330 void embark(Convoy* convoy, size_t to_city);
331 void land(Convoy* convoy);
332 float getConvoyMaxStorage(Convoy* c);
333 void moveGoodsConvoy(Convoy* c, Market* m, Goodtype g, float amount, unsigned fromConvoy);
334 float getSaneAmount(size_t player, size_t city, float amount, Goodtype g);
335 void purchaseFactories(size_t player, size_t city, Goodtype g, size_t amount);
336 unsigned canProduce(size_t city, Goodtype g);
337 void aiThink(void);
338 ShipTypes getSlowestShip(Convoy* convoy);
339 void newSec(void);
340 int microsleep(long microsecs);
342 #endif