2021-10-31 15:12:30 +01:00
|
|
|
#include <gint/keyboard.h>
|
2021-11-05 16:37:09 +01:00
|
|
|
#include <gint/display.h>
|
2021-10-31 15:12:30 +01:00
|
|
|
#include <gint/std/string.h>
|
|
|
|
#include <gint/timer.h>
|
|
|
|
#include <gint/clock.h>
|
2021-11-05 16:37:09 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
2021-10-31 15:12:30 +01:00
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
|
|
|
|
|
|
|
|
int callback_tick(volatile int *tick)
|
|
|
|
{
|
|
|
|
*tick = 1;
|
|
|
|
return TIMER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void default_values(struct calccity *calccity, struct camera *camera, struct map *map)
|
|
|
|
{
|
2021-11-04 18:08:43 +01:00
|
|
|
srand(20211104);
|
|
|
|
|
2021-10-31 15:12:30 +01:00
|
|
|
// Initialisation of struct calccity
|
|
|
|
memset(calccity, 0, sizeof *calccity);
|
|
|
|
|
|
|
|
// Treasure
|
2021-11-04 18:08:43 +01:00
|
|
|
calccity->misc[0] = 5000;
|
2021-10-31 15:12:30 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
2021-11-04 18:08:43 +01:00
|
|
|
{
|
2021-10-31 15:12:30 +01:00
|
|
|
calccity->taxes[i] = 10;
|
2021-11-04 18:08:43 +01:00
|
|
|
calccity->funds[i] = 100;
|
|
|
|
}
|
2021-10-31 15:12:30 +01:00
|
|
|
|
|
|
|
calccity->month = 1;
|
|
|
|
calccity->year = 1900;
|
|
|
|
|
|
|
|
calccity->disaster = 1;
|
|
|
|
calccity->animation = 1;
|
2021-11-04 18:08:43 +01:00
|
|
|
calccity->time_speed = 5100;
|
2021-10-31 15:12:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Initialisation of struct camera
|
|
|
|
memset(camera, 0, sizeof *camera);
|
2021-11-04 18:08:43 +01:00
|
|
|
camera->cursor_x = 2;
|
|
|
|
camera->cursor_y = 2;
|
2021-11-05 16:37:09 +01:00
|
|
|
camera->cursor_size[0] = 8;
|
|
|
|
camera->cursor_size[1] = 8;
|
2021-10-31 15:12:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Initialisation of struct map
|
|
|
|
for (int y = 0; y < 50; y++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < 50; x++)
|
|
|
|
{
|
|
|
|
// Water
|
|
|
|
if ((x * y == 0) || (x == 49 || y == 49))
|
2021-11-07 16:44:29 +01:00
|
|
|
{
|
2021-10-31 15:12:30 +01:00
|
|
|
map->data[y][x] = 139;
|
2021-11-07 16:44:29 +01:00
|
|
|
map->id[y][x] = 1;
|
|
|
|
}
|
|
|
|
|
2021-10-31 15:12:30 +01:00
|
|
|
// Ground
|
|
|
|
else
|
2021-11-07 16:44:29 +01:00
|
|
|
{
|
2021-10-31 15:12:30 +01:00
|
|
|
map->data[y][x] = 48 + rand() % 2;
|
2021-11-07 16:44:29 +01:00
|
|
|
map->id[y][x] = 0;
|
|
|
|
}
|
2021-11-04 18:08:43 +01:00
|
|
|
|
|
|
|
// Shorelines
|
|
|
|
switch (y)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
switch (x)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
map->data[y][x] = 110;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 48:
|
|
|
|
map->data[y][x] = 112;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (x != 0 && x != 49) map->data[y][x] = 111;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 48:
|
|
|
|
switch (x)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
map->data[y][x] = 130;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 48:
|
|
|
|
map->data[y][x] = 132;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (x != 0 && x != 49) map->data[y][x] = 131;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (y != 0 && y != 49)
|
|
|
|
{
|
|
|
|
if (x == 1) map->data[y][x] = 120;
|
|
|
|
if (x == 48) map->data[y][x] = 122;
|
|
|
|
}
|
|
|
|
}
|
2021-10-31 15:12:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int rtc_key(void)
|
|
|
|
{
|
|
|
|
int opt = GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & ~GETKEY_MOD_ALPHA & ~GETKEY_REP_ARROWS;
|
|
|
|
int timeout = 1;
|
|
|
|
|
|
|
|
key_event_t ev = getkey_opt(opt, &timeout);
|
|
|
|
if(ev.type == KEYEV_NONE) return 0;
|
|
|
|
|
|
|
|
return ev.key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-07 16:44:29 +01:00
|
|
|
void next_step(struct calccity *calccity, struct map *map)
|
2021-11-04 18:08:43 +01:00
|
|
|
{
|
|
|
|
calccity->tick += ENGINE_TICK;
|
|
|
|
|
|
|
|
// In-game animation
|
|
|
|
if (calccity->animation && !(calccity->tick % 1000))
|
2021-11-07 16:44:29 +01:00
|
|
|
{
|
|
|
|
calccity->blinker_water = (calccity->blinker_water + 1 ) % 2;
|
|
|
|
calccity->blinker_alert = (calccity->blinker_alert + 1) % 3;
|
|
|
|
}
|
2021-11-04 18:08:43 +01:00
|
|
|
|
|
|
|
// In-game time
|
|
|
|
if (!(calccity->tick % calccity->time_speed))
|
|
|
|
{
|
|
|
|
calccity->month ++;
|
|
|
|
if (calccity->month > 12)
|
|
|
|
{
|
2021-11-07 18:31:23 +01:00
|
|
|
update_stat(calccity, map);
|
|
|
|
end_year(calccity);
|
2021-11-04 18:08:43 +01:00
|
|
|
calccity->month = 1;
|
|
|
|
calccity->year ++;
|
|
|
|
}
|
|
|
|
}
|
2022-02-06 10:22:25 +01:00
|
|
|
|
|
|
|
// Disasters gestion soon™
|
2021-11-04 18:08:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-31 15:12:30 +01:00
|
|
|
void main_loop(struct calccity *calccity, struct camera *camera, struct map *map)
|
|
|
|
{
|
|
|
|
// Timer initialisation
|
|
|
|
static volatile int tick = 1;
|
|
|
|
int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000, GINT_CALL(callback_tick, &tick));
|
|
|
|
if (t >= 0) timer_start(t);
|
|
|
|
|
2021-11-06 14:23:42 +01:00
|
|
|
struct building building = {0};
|
2021-11-07 16:44:29 +01:00
|
|
|
int end = 0, key = 0, build_mode = -1;
|
2021-10-31 15:12:30 +01:00
|
|
|
|
|
|
|
while (!end)
|
|
|
|
{
|
2021-11-04 18:08:43 +01:00
|
|
|
// Real-time clock system
|
|
|
|
while (!tick) sleep();
|
|
|
|
tick = 0;
|
2021-10-31 15:12:30 +01:00
|
|
|
|
2021-11-07 16:44:29 +01:00
|
|
|
if (build_mode < 0) next_step(calccity, map);
|
2021-11-05 16:37:09 +01:00
|
|
|
|
|
|
|
dclear(C_WHITE);
|
2021-11-06 14:23:42 +01:00
|
|
|
display_main(calccity, camera, map, 1);
|
2021-11-07 16:44:29 +01:00
|
|
|
if (build_mode >= 0)
|
2021-11-06 14:23:42 +01:00
|
|
|
{
|
2022-02-06 10:22:25 +01:00
|
|
|
int width;
|
|
|
|
dsize(building.name, NULL, &width, NULL);
|
|
|
|
drect(4, 6, 5 + width, 17, C_WHITE);
|
|
|
|
dprint_opt(5, 7, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "$%d", building.cost);
|
|
|
|
dprint_opt(5, 13, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%s", building.name);
|
2021-11-06 14:23:42 +01:00
|
|
|
}
|
2021-11-05 16:37:09 +01:00
|
|
|
dupdate();
|
2021-10-31 15:12:30 +01:00
|
|
|
|
2021-11-04 18:08:43 +01:00
|
|
|
// Get and manage input
|
|
|
|
key = rtc_key();
|
2022-02-06 10:22:25 +01:00
|
|
|
keyboard_managment(camera, key, build_mode);
|
2021-11-06 14:23:42 +01:00
|
|
|
|
|
|
|
// Menu gestion
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case KEY_F1: case KEY_F2:
|
2021-11-06 20:39:36 +01:00
|
|
|
camera->zoom = 0;
|
2021-11-06 14:23:42 +01:00
|
|
|
exit_build_mode(camera, &build_mode);
|
|
|
|
|
|
|
|
if (key == KEY_F1) building = menu_12(calccity, camera, map, &build_mode, 1);
|
|
|
|
if (key == KEY_F2) building = menu_12(calccity, camera, map, &build_mode, 2);
|
2021-11-07 16:44:29 +01:00
|
|
|
if (build_mode >= 0)
|
2021-11-06 14:23:42 +01:00
|
|
|
{
|
|
|
|
camera->cursor_size[0] = building.size[0] * 15;
|
|
|
|
camera->cursor_size[1] = building.size[1] * 15;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_F4:
|
|
|
|
menu_4(calccity);
|
2021-11-07 18:31:23 +01:00
|
|
|
update_stat(calccity, map);
|
2021-11-06 14:23:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_F5:
|
|
|
|
menu_5(calccity);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_F6:
|
|
|
|
end = menu_6(calccity);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:44:29 +01:00
|
|
|
if (build_mode >= 0)
|
2021-11-06 14:23:42 +01:00
|
|
|
{
|
|
|
|
// Build annulation
|
|
|
|
if (key == KEY_ALPHA)
|
|
|
|
exit_build_mode(camera, &build_mode);
|
|
|
|
|
|
|
|
// Build validation
|
|
|
|
if (key == KEY_SHIFT && can_build(calccity, camera, map, &building))
|
|
|
|
{
|
2021-11-06 20:39:36 +01:00
|
|
|
unsigned short loc_x = building.size[0] * floor(camera->x + camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1));
|
|
|
|
unsigned short loc_y = building.size[1] * floor(camera->y + camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
|
2022-02-06 10:22:25 +01:00
|
|
|
|
|
|
|
if (build_mode == 5 || build_mode == 8 || build_mode == 11 || build_mode == 27 || build_mode == 28 || build_mode == 29)
|
|
|
|
{
|
|
|
|
building = large_building(map, build_mode, &loc_x, &loc_y);
|
|
|
|
for (int y = loc_y; y < loc_y + building.size[1]; y ++)
|
|
|
|
{
|
|
|
|
for (int x = loc_x; x < loc_x + building.size[0]; x ++)
|
|
|
|
map->id[y][x] = 0;
|
|
|
|
}
|
|
|
|
update_stat(calccity, map);
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:44:29 +01:00
|
|
|
unsigned char index = 0;
|
2021-11-06 14:23:42 +01:00
|
|
|
for (int y = loc_y; y < loc_y + building.size[1]; y ++)
|
|
|
|
{
|
|
|
|
for (int x = loc_x; x < loc_x + building.size[0]; x ++)
|
|
|
|
{
|
|
|
|
map->data[y][x] = building.id[index];
|
|
|
|
index ++;
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 16:44:29 +01:00
|
|
|
map->id[loc_y][loc_x] = build_mode;
|
2021-11-06 14:23:42 +01:00
|
|
|
calccity->misc[0] -= building.cost;
|
2021-11-07 16:44:29 +01:00
|
|
|
update_stat(calccity, map);
|
2021-11-06 14:23:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-10-31 15:12:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Free timer
|
|
|
|
if (t >= 0) timer_stop(t);
|
2021-11-04 18:08:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-06 10:22:25 +01:00
|
|
|
void keyboard_managment(struct camera *camera, const int key, const int build_mode)
|
2021-11-04 18:08:43 +01:00
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case KEY_UP:
|
2021-11-06 20:39:36 +01:00
|
|
|
if (!camera->zoom && camera->cursor_y > 0) camera->cursor_y --;
|
2021-11-04 18:08:43 +01:00
|
|
|
else if (camera->y > 0) camera->y --;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_RIGHT:
|
2021-11-06 14:23:42 +01:00
|
|
|
if (camera->cursor_x < 14) camera->cursor_x ++;
|
2021-11-06 20:39:36 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!camera->zoom && camera->x < 42) camera->x ++;
|
|
|
|
if (camera->zoom && camera->x < 35) camera->x ++;
|
|
|
|
}
|
2021-11-04 18:08:43 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_DOWN:
|
2021-11-06 14:23:42 +01:00
|
|
|
if (camera->cursor_y < 6) camera->cursor_y ++;
|
2021-11-06 20:39:36 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!camera->zoom && camera->y < 46) camera->y ++;
|
|
|
|
if (camera->zoom && camera->y < 43) camera->y ++;
|
|
|
|
}
|
2021-11-04 18:08:43 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_LEFT:
|
2021-11-06 20:39:36 +01:00
|
|
|
if (!camera->zoom && camera->cursor_x > 0) camera->cursor_x --;
|
2021-11-04 18:08:43 +01:00
|
|
|
else if (camera->x > 0) camera->x --;
|
|
|
|
break;
|
2021-11-06 20:39:36 +01:00
|
|
|
|
|
|
|
case KEY_PLUS:
|
|
|
|
camera->zoom = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_MINUS:
|
2022-02-06 10:22:25 +01:00
|
|
|
if (build_mode == -1)
|
|
|
|
{
|
|
|
|
if (camera->x > 35) camera->x = 35;
|
|
|
|
if (camera->y > 43) camera->y = 43;
|
|
|
|
camera->zoom = 1;
|
|
|
|
}
|
2021-11-06 20:39:36 +01:00
|
|
|
break;
|
2021-11-04 18:08:43 +01:00
|
|
|
}
|
2021-11-05 16:37:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-06 14:23:42 +01:00
|
|
|
bool can_build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building)
|
2021-11-05 16:37:09 +01:00
|
|
|
{
|
2021-11-06 20:39:36 +01:00
|
|
|
unsigned short loc_x = building->size[0] * floor(camera->x + camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1));
|
|
|
|
unsigned short loc_y = building->size[1] * floor(camera->y + camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
|
2021-11-05 16:37:09 +01:00
|
|
|
|
2021-11-06 14:23:42 +01:00
|
|
|
// Not enougth money
|
|
|
|
if (calccity->misc[0] < building->cost)
|
2021-11-05 16:37:09 +01:00
|
|
|
{
|
2021-11-06 14:23:42 +01:00
|
|
|
display_message("VOUS N'AVEZ PAS ASSEZ D'ARGENT POUR CONSTRUIRE.");
|
|
|
|
return false;
|
|
|
|
}
|
2021-11-05 16:37:09 +01:00
|
|
|
|
|
|
|
|
2021-11-06 14:23:42 +01:00
|
|
|
for (int y = loc_y; y < loc_y + building->size[1]; y ++)
|
|
|
|
{
|
|
|
|
for (int x = loc_x; x < loc_x + building->size[0]; x ++)
|
|
|
|
{
|
|
|
|
// Build on water
|
|
|
|
if (map->data[y][x] == 139)
|
|
|
|
{
|
|
|
|
display_message("VOUS NE POUVEZ PAS CONSTRUIRE SUR L'EAU.");
|
|
|
|
return false;
|
|
|
|
}
|
2021-11-05 16:37:09 +01:00
|
|
|
|
2021-11-06 14:23:42 +01:00
|
|
|
// Build on another building
|
2021-11-07 16:44:29 +01:00
|
|
|
if (map->data[y][x] != 48 && map->data[y][x] != 49 && map->data[y][x] < 110 && building->id[0] != 48)
|
2021-11-06 14:23:42 +01:00
|
|
|
{
|
|
|
|
display_message("VOUS NE POUVEZ PAS CONSTRUIRE SUR BATIMENT EXISTANT.");
|
|
|
|
return false;
|
|
|
|
}
|
2021-11-05 16:37:09 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-06 14:23:42 +01:00
|
|
|
return true;
|
|
|
|
}
|
2021-11-05 17:33:19 +01:00
|
|
|
|
2021-11-06 14:23:42 +01:00
|
|
|
|
|
|
|
void exit_build_mode(struct camera *camera, int *build_mode)
|
|
|
|
{
|
2021-11-07 16:44:29 +01:00
|
|
|
*build_mode = -1;
|
2021-11-05 17:33:19 +01:00
|
|
|
camera->cursor_size[0] = 8;
|
|
|
|
camera->cursor_size[1] = 8;
|
2021-11-07 16:44:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-06 10:22:25 +01:00
|
|
|
struct building large_building(struct map *map, const int build_mode, short unsigned int *loc_x, short unsigned int *loc_y)
|
2021-11-07 16:44:29 +01:00
|
|
|
{
|
|
|
|
extern const struct building buildings[42];
|
2022-02-06 10:22:25 +01:00
|
|
|
const short unsigned int Y[16] = {*loc_y - 1, *loc_y - 1, *loc_y, *loc_y, *loc_y - 1, *loc_y - 1, *loc_y, *loc_y, *loc_y, *loc_y, *loc_y + 1, *loc_y + 1, *loc_y, *loc_y, *loc_y + 1, *loc_y + 1};
|
|
|
|
const short unsigned int X[16] = {*loc_x - 1, *loc_x, *loc_x - 1, *loc_x, *loc_x, *loc_x + 1, *loc_x, *loc_x + 1, *loc_x - 1, *loc_x, *loc_x - 1, *loc_x, *loc_x, *loc_x + 1, *loc_x, *loc_x + 1};
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i ++)
|
2021-11-07 16:44:29 +01:00
|
|
|
{
|
2022-02-06 10:22:25 +01:00
|
|
|
int check = 0;
|
|
|
|
for (int j = 0; j < 4; j ++)
|
2021-11-07 16:44:29 +01:00
|
|
|
{
|
2022-02-06 10:22:25 +01:00
|
|
|
short unsigned int y = Y[4 * i + j];
|
|
|
|
short unsigned int x = X[4 * i + j];
|
|
|
|
if (map->id[y][x] == build_mode) check ++;
|
2021-11-07 16:44:29 +01:00
|
|
|
}
|
|
|
|
|
2022-02-06 10:22:25 +01:00
|
|
|
if (check == 3)
|
|
|
|
{
|
|
|
|
*loc_x = X[4 * i];
|
|
|
|
*loc_y = Y[4 * i];
|
|
|
|
|
|
|
|
switch (build_mode)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
return buildings[35];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
return buildings[36];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
return buildings[37];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 27:
|
|
|
|
return buildings[38];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 28:
|
|
|
|
return buildings[39];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 29:
|
|
|
|
return buildings[40];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buildings[build_mode];
|
|
|
|
}
|
2021-11-07 16:44:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
void update_stat(struct calccity *calccity, struct map *map)
|
|
|
|
{
|
|
|
|
|
|
|
|
extern const struct building buildings[42];
|
|
|
|
|
|
|
|
// Reset stat
|
|
|
|
for (int i = 0; i < 23; i ++)
|
|
|
|
calccity->stat[i] = 0;
|
|
|
|
|
|
|
|
// Buildings stats
|
|
|
|
for (int y = 0; y < 50; y ++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < 50; x ++)
|
|
|
|
{
|
|
|
|
if (map->id[y][x] > 1)
|
|
|
|
{
|
|
|
|
struct building building = buildings[map->id[y][x]];
|
|
|
|
|
|
|
|
for (int i = 0; i < 23; i ++)
|
|
|
|
{
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
// TAXES : commercial & work
|
|
|
|
case 4: case 10:
|
|
|
|
calccity->stat[i] += building.stat[i] + building.taxes[0] * calccity->taxes[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
// TAXES : industrial & production
|
|
|
|
case 11: case 12:
|
|
|
|
calccity->stat[i] += building.stat[i] + building.taxes[1] * calccity->taxes[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
// TAXES : import & export
|
|
|
|
case 13: case 14:
|
|
|
|
calccity->stat[i] += building.stat[i] + building.taxes[2] * calccity->taxes[3];
|
|
|
|
break;
|
|
|
|
|
|
|
|
// FUNDS : health
|
|
|
|
case 1:
|
|
|
|
calccity->stat[i] += floor(building.stat[i] * (calccity->funds[3] / 100));
|
|
|
|
break;
|
|
|
|
|
|
|
|
// FUNDS : crime
|
|
|
|
case 6:
|
|
|
|
calccity->stat[i] += floor(building.stat[i] * (calccity->funds[0] / 100));
|
|
|
|
break;
|
|
|
|
|
|
|
|
// FUNDS : firehazard
|
|
|
|
case 7:
|
|
|
|
calccity->stat[i] += floor(building.stat[i] * (calccity->funds[1] / 100));
|
|
|
|
break;
|
|
|
|
|
|
|
|
// FUNDS : education
|
|
|
|
case 2:
|
|
|
|
calccity->stat[i] += floor(building.stat[i] * (calccity->funds[2] / 100));
|
|
|
|
break;
|
|
|
|
|
|
|
|
// special calculation of the annual cost
|
|
|
|
case 15:
|
|
|
|
for (int j = 0; j < 4; j ++)
|
|
|
|
{
|
|
|
|
if (building.funds[j])
|
|
|
|
calccity->stat[i] += building.funds[j] * calccity->funds[j];
|
|
|
|
}
|
|
|
|
calccity->stat[i] += building.stat[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
calccity->stat[i] += building.stat[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
calccity->stat[17] -= calccity->stat[16];
|
|
|
|
if (calccity->stat[17] < 0) calccity->stat[17] = 0;
|
|
|
|
|
|
|
|
calccity->stat[19] -= calccity->stat[18];
|
|
|
|
if (calccity->stat[19] < 0) calccity->stat[19] = 0;
|
|
|
|
|
|
|
|
// Others stats
|
|
|
|
calccity->stat[0] -= floor(calccity->misc[1] / 2);
|
|
|
|
calccity->stat[1] -= floor(calccity->misc[1] / 10);
|
|
|
|
calccity->stat[2] -= floor(0.3 * (calccity->misc[1] + calccity->stat[14]) - 0.7 * calccity->stat[13]);
|
|
|
|
calccity->stat[3] -= floor(calccity->misc[1] / 10);
|
|
|
|
calccity->stat[4] -= floor(calccity->misc[1] / 2);
|
|
|
|
calccity->stat[5] -= floor(calccity->misc[1] / 2);
|
|
|
|
|
|
|
|
calccity->stat[6] += floor(calccity->misc[1] / 10);
|
|
|
|
calccity->stat[7] += floor(calccity->misc[1] / 2);
|
|
|
|
calccity->stat[9] += floor(calccity->misc[1] / 2);
|
|
|
|
|
|
|
|
calccity->stat[20] += floor(calccity->misc[1] / 1000);
|
|
|
|
calccity->stat[21] -= floor(calccity->misc[1] / 1000);
|
|
|
|
|
|
|
|
// Happyness
|
2021-11-07 18:31:23 +01:00
|
|
|
if (calccity->misc[1])
|
|
|
|
calccity->stat[22] = floor((calccity->misc[1] + calccity->stat[22] + calccity->stat[0] + calccity->stat[1] + calccity->stat[2] + calccity->stat[3] - calccity->stat[6] - calccity->stat[7] - calccity->stat[9] - 10 * calccity->taxes[0]) / calccity->misc[1]);
|
|
|
|
|
|
|
|
|
|
|
|
calccity->misc[3] = 0;
|
|
|
|
calccity->misc[4] = 0;
|
2021-11-07 16:44:29 +01:00
|
|
|
|
|
|
|
// Population out
|
|
|
|
if (calccity->stat[17] < 0 || calccity->stat[19] < 0 || calccity->stat[3] < 0) calccity->misc[4] += 20;
|
|
|
|
if ((calccity->stat[20] > 0 || calccity->stat[1] < 0) && calccity->misc[1] > 30000) calccity->misc[4] += 13;
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i ++)
|
|
|
|
if (calccity->stat[i] <= 0) calccity->misc[4] += 25;
|
|
|
|
|
|
|
|
if (calccity->stat[5] <= -1000) calccity->misc[4] += 30;
|
|
|
|
if (calccity->stat[6] > 1000) calccity->misc[4] += 30;
|
|
|
|
if (calccity->stat[7] > 1000) calccity->misc[4] += 30;
|
|
|
|
if (calccity->stat[9] > 1000) calccity->misc[4] += 4;
|
|
|
|
if (calccity->stat[22] < 0) calccity->misc[4] += 4;
|
|
|
|
|
|
|
|
if (calccity->misc[1] > 100 && calccity->taxes[0] > 10) calccity->misc[4] += 5;
|
|
|
|
if (calccity->misc[1] > 100 && calccity->taxes[0] > 30) calccity->misc[4] += 10;
|
|
|
|
if (calccity->misc[1] > 500 && calccity->taxes[0] > 50) calccity->misc[4] += 50;
|
|
|
|
if (calccity->misc[1] > 1000 && calccity->taxes[0] > 70) calccity->misc[4] += 100;
|
|
|
|
|
|
|
|
// Population in
|
|
|
|
if (calccity->stat[17] > 0 && calccity->stat[19] > 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 6; i ++)
|
2021-11-07 18:31:23 +01:00
|
|
|
if (calccity->stat[i] > 0) calccity->misc[3] += 25;
|
2021-11-07 16:44:29 +01:00
|
|
|
|
2021-11-07 18:31:23 +01:00
|
|
|
if (calccity->stat[6] < 0) calccity->misc[3] += 20;
|
|
|
|
if (calccity->stat[7] < 0) calccity->misc[3] += 20;
|
|
|
|
if (calccity->stat[9] < 0) calccity->misc[3] += 20;
|
2021-11-07 16:44:29 +01:00
|
|
|
|
2021-11-07 18:31:23 +01:00
|
|
|
if (calccity->stat[12] > 0) calccity->misc[3] += 20;
|
2021-11-07 16:44:29 +01:00
|
|
|
if (calccity->taxes[0] <= 10) calccity->misc[3] += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
calccity->misc[1] = calccity->misc[1] + calccity->misc[3] - calccity->misc[4];
|
|
|
|
if (calccity->misc[1] < 0) calccity->misc[1] = 0;
|
2021-11-07 18:31:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void end_year(struct calccity *calccity)
|
|
|
|
{
|
|
|
|
dclear(C_WHITE);
|
|
|
|
|
|
|
|
drect(0, 0, 127, 6, C_BLACK);
|
|
|
|
dprint_opt(33, 1, C_WHITE, C_NONE, 0, 0, "BILAN %d", calccity->year);
|
|
|
|
|
|
|
|
dhline(0, C_BLACK);
|
|
|
|
dhline(63, C_BLACK);
|
|
|
|
dvline(0, C_BLACK);
|
|
|
|
dvline(127, C_BLACK);
|
|
|
|
|
2021-11-07 18:35:10 +01:00
|
|
|
int taxe_housing = calccity->taxes[0] * calccity->misc[1] / 100;
|
|
|
|
int taxe_trade = calccity->taxes[1] * calccity->stat[10] / 100;
|
|
|
|
int taxe_industry = calccity->taxes[2] * calccity->stat[11] / 100;
|
|
|
|
int taxe_export = calccity->taxes[3] * calccity->stat[14] / 100;
|
2021-11-07 18:31:23 +01:00
|
|
|
|
|
|
|
int entry = taxe_housing + taxe_trade + taxe_industry + taxe_export;
|
|
|
|
|
|
|
|
dprint_opt(4, 8, C_BLACK, C_WHITE, 0, 0, "TAXE HABITATION %d", taxe_housing);
|
|
|
|
dprint_opt(4, 15, C_BLACK, C_WHITE, 0, 0, "TAXE COMMERCE %d", taxe_trade);
|
|
|
|
dprint_opt(4, 22, C_BLACK, C_WHITE, 0, 0, "TAXE INDUSTRIE %d", taxe_industry);
|
|
|
|
dprint_opt(4, 29, C_BLACK, C_WHITE, 0, 0, "TAXE EXPORT %d", taxe_export);
|
|
|
|
dprint_opt(4, 36, C_BLACK, C_WHITE, 0, 0, "TOTAL %d", entry);
|
|
|
|
dprint_opt(4, 43, C_BLACK, C_WHITE, 0, 0, "COUT ANNUEL %d", calccity->stat[15]);
|
|
|
|
dprint_opt(4, 50, C_BLACK, C_WHITE, 0, 0, "BILAN %d", entry - calccity->stat[15]);
|
|
|
|
|
2021-11-07 18:35:10 +01:00
|
|
|
calccity->misc[0] = calccity->misc[0] + entry - calccity->stat[15];
|
2021-11-07 18:31:23 +01:00
|
|
|
if (calccity->misc[0] < 0) calccity->misc[0] = 0;
|
|
|
|
|
|
|
|
dupdate();
|
|
|
|
|
|
|
|
int key = 0;
|
|
|
|
int opt = GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & ~GETKEY_MOD_ALPHA & ~GETKEY_REP_ARROWS;
|
|
|
|
int timeout = 0;
|
|
|
|
|
|
|
|
while (key != KEY_ALPHA)
|
|
|
|
key = getkey_opt(opt, &timeout).key;
|
2021-10-31 15:12:30 +01:00
|
|
|
}
|