1 #include "temple.h"
2 
3 #include "building/distribution.h"
4 #include "building/monument.h"
5 #include "city/resource.h"
6 #include "game/resource.h"
7 
8 #define INFINITE 10000
9 #define MAX_FOOD 600
10 #define MAX_MESS_HALL_FOOD 1600
11 
building_temple_get_storage_destination(building * temple)12 int building_temple_get_storage_destination(building *temple)
13 {
14     if (building_is_venus_temple(temple->type)) {
15         if (!building_distribution_is_good_accepted(INVENTORY_WINE, temple) || !temple->data.market.wine_demand) {
16             return 0;
17         }
18         building *grand_temple = building_get(building_monument_get_venus_gt());
19         if (grand_temple->id != 0 && grand_temple->road_network_id == temple->road_network_id &&
20             temple->data.market.inventory[INVENTORY_WINE] < BASELINE_STOCK && grand_temple->loads_stored > 0) {
21             temple->data.market.fetch_inventory_id = INVENTORY_WINE;
22             return grand_temple->id;
23         }
24         return 0;
25     }
26 
27     if (!building_is_ceres_temple(temple->type)) { // Ceres module 2
28         return 0;
29     }
30 
31     int inventory = resource_to_inventory(city_resource_ceres_temple_food());
32     if (inventory == INVENTORY_NONE) {
33         return 0;
34     }
35     if (!building_distribution_is_good_accepted(inventory, temple) &&
36         (!building_distribution_is_good_accepted(INVENTORY_OIL, temple) || !temple->data.market.oil_demand)) {
37         return 0;
38     }
39 
40     inventory_storage_info data[INVENTORY_MAX];
41     if (!building_distribution_get_inventory_storages(data, temple->type,
42             temple->road_network_id, temple->road_access_x, temple->road_access_y, INFINITE)) {
43         return 0;
44     }
45 
46     if (building_distribution_is_good_accepted(inventory, temple) &&
47         data[inventory].building_id && temple->data.market.inventory[inventory] < MAX_FOOD) {
48         temple->data.market.fetch_inventory_id = inventory;
49         return data[inventory].building_id;
50     }
51     if (building_distribution_is_good_accepted(INVENTORY_OIL, temple) && temple->data.market.oil_demand &&
52         data[INVENTORY_OIL].building_id && temple->data.market.inventory[INVENTORY_OIL] < BASELINE_STOCK) {
53         temple->data.market.fetch_inventory_id = INVENTORY_OIL;
54         return data[INVENTORY_OIL].building_id;
55     }
56     return 0;
57 }
58 
building_temple_mars_food_to_deliver(building * temple,int mess_hall_id)59 int building_temple_mars_food_to_deliver(building *temple, int mess_hall_id)
60 {
61     int most_stocked_food_id = -1;
62     int next;
63     building *mess_hall = building_get(mess_hall_id);
64     for (int i = 0; i < INVENTORY_MAX_FOOD; i++) {
65         next = temple->data.market.inventory[i];
66         if (next > most_stocked_food_id && next >= 100 && mess_hall->data.market.inventory[i] <= MAX_MESS_HALL_FOOD) {
67             most_stocked_food_id = i;
68         }
69     }
70     return most_stocked_food_id;
71 }
72