1 #include "house_service.h"
2 
3 #include "building/building.h"
4 #include "building/monument.h"
5 #include "city/culture.h"
6 
decay(unsigned char * value)7 static void decay(unsigned char *value)
8 {
9     if (*value > 0) {
10         *value = *value - 1;
11     } else {
12         *value = 0;
13     }
14 }
15 
house_service_decay_culture(void)16 void house_service_decay_culture(void)
17 {
18     for (building_type type = BUILDING_HOUSE_SMALL_TENT; type <= BUILDING_HOUSE_LUXURY_PALACE; type++) {
19         for (building *b = building_first_of_type(type); b; b = b->next_of_type) {
20             if (b->state != BUILDING_STATE_IN_USE || !b->house_size) {
21                 continue;
22             }
23             decay(&b->data.house.theater);
24             decay(&b->data.house.amphitheater_actor);
25             decay(&b->data.house.amphitheater_gladiator);
26             decay(&b->data.house.colosseum_gladiator);
27             decay(&b->data.house.colosseum_lion);
28             decay(&b->house_arena_gladiator);
29             decay(&b->house_arena_lion);
30             decay(&b->house_tavern_meat_access);
31             decay(&b->house_tavern_wine_access);
32             decay(&b->data.house.hippodrome);
33             decay(&b->data.house.school);
34             decay(&b->data.house.library);
35             decay(&b->data.house.academy);
36             decay(&b->data.house.barber);
37             decay(&b->data.house.clinic);
38             decay(&b->data.house.bathhouse);
39             decay(&b->data.house.hospital);
40             decay(&b->data.house.temple_ceres);
41             decay(&b->data.house.temple_neptune);
42             decay(&b->data.house.temple_mercury);
43             decay(&b->data.house.temple_mars);
44             decay(&b->data.house.temple_venus);
45             decay(&b->house_pantheon_access);
46             if (b->days_since_offering < 125) {
47                 ++b->days_since_offering;
48             }
49         }
50     }
51 }
52 
house_service_decay_tax_collector(void)53 void house_service_decay_tax_collector(void)
54 {
55     for (building_type type = BUILDING_HOUSE_SMALL_TENT; type <= BUILDING_HOUSE_LUXURY_PALACE; type++) {
56         for (building *b = building_first_of_type(type); b; b = b->next_of_type) {
57             if (b->state == BUILDING_STATE_IN_USE && b->house_tax_coverage) {
58                 b->house_tax_coverage--;
59             }
60         }
61     }
62 }
63 
house_service_decay_houses_covered(void)64 void house_service_decay_houses_covered(void)
65 {
66     for (int i = 1; i < building_count(); i++) {
67         building *b = building_get(i);
68         if (b->state != BUILDING_STATE_UNUSED && b->type != BUILDING_TOWER) {
69             if (b->houses_covered <= 1) {
70                 b->houses_covered = 0;
71             } else {
72                 b->houses_covered--;
73             }
74         }
75     }
76 }
77 
house_service_calculate_culture_aggregates(void)78 void house_service_calculate_culture_aggregates(void)
79 {
80     int venus_module2 = building_monument_gt_module_is_active(VENUS_MODULE_2_DESIRABILITY_ENTERTAINMENT);
81     int completed_colosseum = building_monument_working(BUILDING_COLOSSEUM);
82     int completed_hippodrome = building_monument_working(BUILDING_HIPPODROME);
83 
84     for (building_type type = BUILDING_HOUSE_SMALL_TENT; type <= BUILDING_HOUSE_LUXURY_PALACE; type++) {
85         for (building *b = building_first_of_type(type); b; b = b->next_of_type) {
86             if (b->state != BUILDING_STATE_IN_USE || !b->house_size) {
87                 continue;
88             }
89             int arena_total = 0;
90             int colosseum_total = 0;
91 
92             // Entertainment
93             b->data.house.entertainment = 0;
94 
95             if (b->data.house.theater) {
96                 b->data.house.entertainment += 10;
97             }
98 
99             if (b->house_tavern_wine_access) {
100                 b->data.house.entertainment += 10;
101                 if (b->house_tavern_meat_access) {
102                     b->data.house.entertainment += 5;
103                 }
104             }
105 
106             if (b->data.house.amphitheater_actor) {
107                 if (b->data.house.amphitheater_gladiator) {
108                     b->data.house.entertainment += 15;
109                 } else {
110                     b->data.house.entertainment += 10;
111                 }
112             }
113 
114             if (b->house_arena_gladiator) {
115                 arena_total = b->house_arena_lion ? 20 : 10;
116             }
117 
118             if (b->data.house.colosseum_gladiator) {
119                 colosseum_total = b->data.house.colosseum_lion ? 25 : 15;
120             }
121 
122             b->data.house.entertainment += arena_total > colosseum_total ? arena_total : colosseum_total;
123 
124             if (b->data.house.hippodrome) {
125                 b->data.house.entertainment += 30;
126             }
127 
128             if (completed_hippodrome) {
129                 b->data.house.entertainment += 5;
130             }
131 
132             if (completed_colosseum) {
133                 b->data.house.entertainment += 5;
134             }
135 
136             // Venus Module 2 Entertainment Bonus
137             if (venus_module2 && b->data.house.temple_venus) {
138                 b->data.house.entertainment += 10;
139             }
140 
141             // Education
142             b->data.house.education = 0;
143             if (b->data.house.school || b->data.house.library) {
144                 b->data.house.education = 1;
145                 if (b->data.house.school && b->data.house.library) {
146                     b->data.house.education = 2;
147                     if (b->data.house.academy) {
148                         b->data.house.education = 3;
149                     }
150                 }
151             }
152 
153             // religion
154             b->data.house.num_gods = 0;
155             if (b->data.house.temple_ceres) {
156                 ++b->data.house.num_gods;
157             }
158             if (b->data.house.temple_neptune) {
159                 ++b->data.house.num_gods;
160             }
161             if (b->data.house.temple_mercury) {
162                 ++b->data.house.num_gods;
163             }
164             if (b->data.house.temple_mars) {
165                 ++b->data.house.num_gods;
166             }
167             if (b->data.house.temple_venus) {
168                 ++b->data.house.num_gods;
169             }
170 
171             // health
172             b->data.house.health = 0;
173             if (b->data.house.clinic) {
174                 ++b->data.house.health;
175             }
176             if (b->data.house.hospital) {
177                 ++b->data.house.health;
178             }
179         }
180     }
181 }
182