7 #include "../lib/include/stringptr.h"
10 #define CITY_MAX_INDUSTRYTYPES 5
12 #define MAX_BRANCHES 32
13 #define MAX_CONVOYS 64
14 #define MAX_NOTIFICATIONS 16
45 typedef Goodtype IndustryType
;
52 GC_D
, // regionalwaren
65 float consumation
[GT_MAX
];
69 size_t maxworkersperfactory
;
81 float avgPricePayed
[GT_MAX
];
109 size_t numShips
[ST_MAX
];
113 ShipCounter availableShips
;
122 IndustryType industry
[CITY_MAX_INDUSTRYTYPES
];
123 size_t numFactories
[CITY_MAX_INDUSTRYTYPES
];
124 size_t population
[PT_MAX
];
125 float populationMood
[PT_MAX
];
156 float condition
[ST_MAX
];
161 ShipCounter shipcounter
;
162 ShipLocationType loc
;
168 size_t captainSalary
;
185 NT_OUT_OF_PRODUCTIONGOODS
,
191 extern const stringptr
* NotificationNames
[NT_MAX
];
192 stringptr
* getNotificationName(NotificationType x
);
203 Notification notifications
[MAX_NOTIFICATIONS
];
209 AIP_SATISFY_MOODS
= 1,
210 AIP_PURCHASE_PRODUCTION_GOODS
= 2,
211 AIP_SELL_GOODS_FROM_STOCK
= 4
216 Goodtype req_production_good
;
217 size_t branch_req_goods
;
218 float amount_required
;
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
];
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
242 uint64_t date
; // seconds till genesis
243 size_t monthsperyear
;
246 size_t minutesperhour
;
247 size_t secondsperminute
;
253 SELL_FROM_OVERPRODUCTION
= 1,
255 SELL_FROM_CONVOY
= 4,
258 SELL_TO_PLAYERSTOCK
= 32,
260 SELL_TO_POPULATION
= 128
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
];
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
);
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
);
338 ShipTypes
getSlowestShip(Convoy
* convoy
);
340 int microsleep(long microsecs
);