diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f999b1..6123a1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ set(ASSETS_fx assets-fx/large_water.png assets-fx/title.png assets-fx/fn_keys.png + assets-fx/fn_1.png + assets-fx/fn_2.png ) set(ASSETS_cg) diff --git a/assets-fx/brownout.png b/assets-fx/brownout.png new file mode 100644 index 0000000..5ff8eab Binary files /dev/null and b/assets-fx/brownout.png differ diff --git a/assets-fx/fn_1.png b/assets-fx/fn_1.png new file mode 100644 index 0000000..a5d3ab2 Binary files /dev/null and b/assets-fx/fn_1.png differ diff --git a/assets-fx/fn_2.png b/assets-fx/fn_2.png new file mode 100644 index 0000000..f6925db Binary files /dev/null and b/assets-fx/fn_2.png differ diff --git a/assets-fx/large_tileset.png b/assets-fx/large_tileset.png index 05e0ecf..e0b07bc 100644 Binary files a/assets-fx/large_tileset.png and b/assets-fx/large_tileset.png differ diff --git a/assets-fx/title.png b/assets-fx/title.png index af7c008..dcface3 100644 Binary files a/assets-fx/title.png and b/assets-fx/title.png differ diff --git a/src/calccity.c b/src/calccity.c index 0ce9e8c..e46c061 100644 --- a/src/calccity.c +++ b/src/calccity.c @@ -1,3 +1,421 @@ #include "calccity.h" -static const char tiles_names = {}; \ No newline at end of file + +const struct building buildings[41] = { + + // Menu 1 + { + .name = "TERRE", + .id = (unsigned char []){48, 49, 110, 111, 112, 113, 114, 120, 121, 122, 123, 124, 130, 131, 132, 133, 134}, + .cost = 10, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "EAU", + .id = (unsigned char []){139}, + .cost = 15, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "FORET", + .id = (unsigned char []){76}, + .cost = 15, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "HABITATIONS TYPE 1", + .id = (unsigned char []){66}, + .cost = 100, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "HABITATIONS TYPE 2", + .id = (unsigned char []){67}, + .cost = 150, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "HABITATIONS TYPE 3", + .id = (unsigned char []){68}, + .cost = 200, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "BUREAUX TYPE 1", + .id = (unsigned char []){45}, + .cost = 50, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "BUREAUX TYPE 2", + .id = (unsigned char []){46}, + .cost = 100, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "BUREAUX TYPE 3", + .id = (unsigned char []){47}, + .cost = 150, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "USINE TYPE 1", + .id = (unsigned char []){54}, + .cost = 200, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "USINE TYPE 2", + .id = (unsigned char []){55}, + .cost = 300, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "USINE TYPE 3", + .id = (unsigned char []){56}, + .cost = 400, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "FERME TYPE 1", + .id = (unsigned char []){9}, + .cost = 50, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "FERME TYPE 2", + .id = (unsigned char []){19}, + .cost = 75, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "FERME TYPE 3", + .id = (unsigned char []){44}, + .cost = 100, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + + // Menu 2 + { + .name = "ROUTE", + .id = (unsigned char []){80, 81, 82, 83, 90, 91, 92, 93, 100, 101, 102}, + .cost = 10, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "PORT", + .id = (unsigned char []){62, 63, 64, 65}, + .cost = 500, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "AEROPORT", + .id = (unsigned char []){0, 1, 2, 12}, + .cost = 3500, + .size = {2, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "RAIL", + .id = (unsigned char []){84, 85, 86, 87, 94, 95, 96, 97, 104, 105, 106}, + .cost = 50, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "CENTRALE ELECTRIQUE 1", + .id = (unsigned char []){71}, + .cost = 500, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "CENTRALE ELECTRIQUE 2", + .id = (unsigned char []){72}, + .cost = 1000, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "CENTALE NUCLEAIRE", + .id = (unsigned char []){50, 51, 60, 61}, + .cost = 25000, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "INCINERATEUR", + .id = (unsigned char []){3, 4, 13, 14}, + .cost = 2500, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0}, + } + + { + .name = "STATION D'EPURATION", + .id = (unsigned char []){77}, + .cost = 50, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "TERRAIN DE SPORT", + .id = (unsigned char []){78}, + .cost = 250, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "AIRE DE JEUX", + .id = (unsigned char []){69}, + .cost = 150, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "STADE", + .id = (unsigned char []){42, 43, 52, 53}, + .cost = 10000, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "CASERNE DE POLICE", + .id = (unsigned char []){70}, + .cost = 250, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "CASERNE DE POMPIERS", + .id = (unsigned char []){58}, + .cost = 250, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "HOPITAL", + .id = (unsigned char []){59}, + .cost = 250, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "CENTRE ECOLOGIQUE", + .id = (unsigned char []){75}, + .cost = 2500, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "ECOLE TYPE 1", + .id = (unsigned char []){73}, + .cost = 250, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "ECOLE TYPE 2", + .id = (unsigned char []){74}, + .cost = 500, + .size = {1, 1}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "UNIVERSITE", + .id = (unsigned char []){28, 29, 38, 39}, + .cost = 2500, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "EGLISE ET CIMETIERE", + .id = (unsigned char []){10, 11, 20, 21}, + .cost = 2500, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + + // Others buildings + { + .name = "IMMEUBLE"; + .id = (unsigned char []){5, 6, 15, 56}, + .cost = 0, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0}, + } + + { + .name = "TOUR DE BUREAUX", + .id = (unsigned char []){7, 8, 17, 18}, + .cost = 0, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "USINE", + .id = (unsigned char []){30, 31, 40, 41}, + .cost = 0, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "CASERNE DE POLICE", + .id = (unsigned char []){26, 27, 36, 37}, + .cost = 0, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "CASERNE DE POMPIERS", + .id = (unsigned char []){22, 23, 32, 33}, + .cost = 0, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + + { + .name = "HOPITAL", + .id = (unsigned char []){24, 25, 34, 35}, + .cost = 0, + .size = {2, 2}, + .stat = {0}, + .taxes = {0}, + .funds = {0} + }, + +}; \ No newline at end of file diff --git a/src/calccity.h b/src/calccity.h index d44884e..45f759c 100644 --- a/src/calccity.h +++ b/src/calccity.h @@ -1,28 +1,43 @@ #ifndef _CALCCITY_H #define _CALCCITY_H -#include +#include struct calccity { - // human's statistics = {happyness, health, education, housing, work, food} - unsigned long humans[6]; - // population evolution = {population, birth_rate, death_rate, immigration, emigration} - unsigned long population[5]; + // main statistics + /* + housing, + health, + education, + food, + work, + transport, - // trade statistics = {import, export, production, commercial, industrial, annual_cost} - unsigned long trade[6]; + crime, + firehazard, + nuclearhazard, + pollution, - // production = {water, power} - unsigned long production[2]; + commercial, + industrial, + production, + import, + export, + annual_cost, + + water_consumption, + power_consumption, + power_supply, + grabage + graves, + */ + unsigned long stat[21]; - // consumption = {water, power} - unsigned long consumption[2]; - - // some others statistics = {treasure, crime, safety, fire_hazard, nuclear_hazard, pollution, transport, grabage, graves} + // some others statistics = {treasure, population, safety, hapyness, birth_rate, death_rate, immigration, emigration, water_supply} unsigned long misc[9]; - + // taxes in percents on {housing, trade, industry, export} unsigned int taxes[4]; @@ -49,6 +64,7 @@ struct camera int zoom; int cursor_x, cursor_y; + int cursor_size[2]; }; @@ -58,6 +74,53 @@ struct map }; +struct building +{ + char *name; + + unsigned char *id; + int cost; + unsigned char size[2]; + + /* + housing, + health, + education, + food, + work, + transport, + + crime, + firehazard, + nuclearhazard, + pollution, + + commercial, + industrial, + production, + import, + export, + annual_cost, + + water_consumption, + power_consumption, + power_supply, + grabage + graves, + */ + unsigned int stat[21]; + + // commercial, industrial, export + unsigned int taxes[3]; + + // police, firemen, education, heathcare + unsigned int funds[4]; + +}; + + #define ENGINE_TICK 100 +static const struct building buildings[41]; + #endif /* _CALCCITY_H */ \ No newline at end of file diff --git a/src/core.c b/src/core.c index ad1796d..75f2692 100644 --- a/src/core.c +++ b/src/core.c @@ -1,8 +1,10 @@ #include -#include +#include #include #include #include +#include +#include #include "core.h" @@ -44,6 +46,8 @@ void default_values(struct calccity *calccity, struct camera *camera, struct map memset(camera, 0, sizeof *camera); camera->cursor_x = 2; camera->cursor_y = 2; + camera->cursor_size[0] = 8; + camera->cursor_size[1] = 8; // Initialisation of struct map @@ -151,8 +155,6 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map int end = 0, key = 0; - //int build_mode = 0; - while (!end) { // Real-time clock system @@ -160,33 +162,14 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map tick = 0; next_step(calccity); - - // Display map - display_large_map(calccity, camera, map); - display_around(calccity, camera); + + dclear(C_WHITE); + main_display(calccity, camera, map, 1); + dupdate(); // Get and manage input key = rtc_key(); - keyboard_managment(calccity, camera, key); - - // Open the menu - switch (calccity->menu) - { - // Tax and funds - case 4: - menu_4(calccity); - break; - - case 5: - menu_5(calccity); - break; - - // Options - case 6: - end = menu_6(calccity); - break; - } - calccity->menu = 0; + end = keyboard_managment(calccity, camera, map, key); } // Free timer @@ -194,8 +177,10 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map } -void keyboard_managment(struct calccity *calccity, struct camera *camera, const int key) +int keyboard_managment(struct calccity *calccity, struct camera *camera, struct map *map, const int key) { + + int end = 0; switch (key) { case KEY_UP: @@ -204,12 +189,12 @@ void keyboard_managment(struct calccity *calccity, struct camera *camera, const break; case KEY_RIGHT: - if (camera->cursor_x < 14) camera->cursor_x ++; + if (camera->cursor_x < floor(120 / camera->cursor_size[0]) - 1) camera->cursor_x ++; else if (camera->x < 42) camera->x ++; break; case KEY_DOWN: - if (camera->cursor_y < 6) camera->cursor_y ++; + if (camera->cursor_y < floor(57 / camera->cursor_size[1]) - 1) camera->cursor_y ++; else if (camera->y < 46) camera->y ++; break; @@ -218,29 +203,95 @@ void keyboard_managment(struct calccity *calccity, struct camera *camera, const else if (camera->x > 0) camera->x --; break; - case KEY_F1: - calccity->menu = 1; + int build_mode = 0; + struct building selected_building = menu_1(calccity, camera, map, &build_mode); + + if (build_mode) + build(calccity, camera, map, &selected_building); break; case KEY_F2: - calccity->menu = 2; - break; - - case KEY_F3: - calccity->menu = 3; break; case KEY_F4: - calccity->menu = 4; + menu_4(calccity); break; case KEY_F5: - calccity->menu = 5; + menu_5(calccity); break; case KEY_F6: - calccity->menu = 6; + end = menu_6(calccity); break; } + return end; +} + + +void build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building) +{ + // 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); + + // Adjust cursor size + camera->cursor_size[0] = building->size[0] * 15; + camera->cursor_size[1] = building->size[1] * 15; + camera->cursor_x = 1; + camera->cursor_y = 1; + + int key = 0, end = 0; + + while (!end) + { + // Real-time clock system + while (!tick) sleep(); + tick = 0; + + next_step(calccity); + + dclear(C_WHITE); + main_display(calccity, camera, map, 1); + + dprint_opt(4, 8, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "$%d %d,%d", building->cost, building->size[0], building->size[1]); + dprint_opt(4, 15, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%s", building->name); + dupdate(); + + key = rtc_key(); + switch (key) + { + case KEY_UP: + if (camera->cursor_y > 0) camera->cursor_y --; + else if (camera->y > 0) camera->y --; + break; + + case KEY_RIGHT: + if (camera->cursor_x < floor(120 / camera->cursor_size[0]) - 1) camera->cursor_x ++; + else if (camera->x < 42) camera->x ++; + break; + + case KEY_DOWN: + if (camera->cursor_y < floor(57 / camera->cursor_size[1]) - 1) camera->cursor_y ++; + else if (camera->y < 46) camera->y ++; + break; + + case KEY_LEFT: + if (camera->cursor_x > 0) camera->cursor_x --; + else if (camera->x > 0) camera->x --; + break; + + case KEY_ALPHA: + end = 1; + break; + + case KEY_SHIFT: + end = 1; + break; + } + } + + if (t >= 0) timer_stop(t); } \ No newline at end of file diff --git a/src/core.h b/src/core.h index 408ea95..8d33b79 100644 --- a/src/core.h +++ b/src/core.h @@ -20,7 +20,10 @@ void next_step(struct calccity *calccity); // main_loop : game main loop void main_loop(struct calccity *calccity, struct camera *camera, struct map *map); -// keyboard_managment : get the key and manage input -void keyboard_managment(struct calccity *calccity, struct camera *camera, const int key); +// keyboard_managment : get the key, manage input and open menus +int keyboard_managment(struct calccity *calccity, struct camera *camera, struct map *map, const int key); + +// build : manage the build +void build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building); #endif /* _CORE_H */ \ No newline at end of file diff --git a/src/display.c b/src/display.c index a6ef94b..0b1d6c6 100644 --- a/src/display.c +++ b/src/display.c @@ -1,5 +1,6 @@ #include #include +#include #include "display.h" @@ -15,13 +16,19 @@ void title_screen(void) } +void main_display(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor) +{ + // Display map + display_large_map(calccity, camera, map); + display_around(calccity, camera, disp_cursor); +} + + void display_large_map(struct calccity *calccity, struct camera *camera, struct map *map) { extern const bopti_image_t img_large_tileset; extern const bopti_image_t img_large_water; - dclear(C_WHITE); - for (int y = 0; y < 4; y++) { for (int x = 0; x < 8; x ++) @@ -44,7 +51,7 @@ void display_large_map(struct calccity *calccity, struct camera *camera, struct } -void display_around(struct calccity *calccity, struct camera *camera) +void display_around(struct calccity *calccity, struct camera *camera, const int disp_cursor) { extern const bopti_image_t img_fn_keys; @@ -61,11 +68,13 @@ void display_around(struct calccity *calccity, struct camera *camera) dprint_opt(4, 1, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%d-%d", calccity->month, calccity->year); // Cursor - drect_border(8 * camera->cursor_x + 3, 8 * camera->cursor_y, 8 * camera->cursor_x + 11, 8 * camera->cursor_y + 8, C_WHITE, 1, C_BLACK); - dline(8 * camera->cursor_x + 6, 8 * camera->cursor_y + 4, 8 * camera->cursor_x + 8, 8 * camera->cursor_y + 4, C_BLACK); - dline(8 * camera->cursor_x + 7, 8 * camera->cursor_y + 3, 8 * camera->cursor_x + 7, 8 * camera->cursor_y + 5, C_BLACK); - - - dupdate(); + if (disp_cursor) + { + int middle_x = floor(camera->cursor_size[0] / 2) + 3; + int middle_y = floor(camera->cursor_size[1] / 2); + drect_border(camera->cursor_size[0] * camera->cursor_x + 3, camera->cursor_size[1] * camera->cursor_y, camera->cursor_size[0] * camera->cursor_x + 3 + camera->cursor_size[0], camera->cursor_size[1] * camera->cursor_y + camera->cursor_size[1], C_WHITE, 1, C_BLACK); + dline(camera->cursor_size[0] * camera->cursor_x + middle_x - 1, camera->cursor_size[1] * camera->cursor_y + middle_y , camera->cursor_size[0] * camera->cursor_x + middle_x + 1, camera->cursor_size[1] * camera->cursor_y + middle_y , C_BLACK); + dline(camera->cursor_size[0] * camera->cursor_x + middle_x , camera->cursor_size[1] * camera->cursor_y + middle_y - 1, camera->cursor_size[0] * camera->cursor_x + middle_x , camera->cursor_size[1] * camera->cursor_y + middle_y + 1, C_BLACK); + } } diff --git a/src/display.h b/src/display.h index 9e4f937..8f146ce 100644 --- a/src/display.h +++ b/src/display.h @@ -2,14 +2,18 @@ #define _DISPLAY_H #include "calccity.h" +#include "core.h" // title_screen : display title screen void title_screen(void); +// main_display : the general display function +void main_display(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor); + // display_large_map : display the current state of the large map void display_large_map(struct calccity *calccity, struct camera *camera, struct map *map); // display_around : display the screen frame and cursor -void display_around(struct calccity *calccity, struct camera *camera); +void display_around(struct calccity *calccity, struct camera *camera, const int disp_cursor); #endif /* _DISPLAY_H */ \ No newline at end of file diff --git a/src/menus.c b/src/menus.c index 425c888..29509ca 100644 --- a/src/menus.c +++ b/src/menus.c @@ -1,113 +1,57 @@ #include #include -#include +#include #include "menus.h" -void menu_5(struct calccity *calccity) +struct building menu_1(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode) { - int scroll = 0, key = 0; - int opt = GETKEY_DEFAULT & GETKEY_REP_ARROWS; - int timeout = 0; - - static const char *names[23] = { - "GENERAL", - "ARGENT", - "POPULATION", - "BONHEUR", - "SANTE", - "EDUCATION", - "LOGEMENT", - "TRAVAIL", - "NOURRITURE", - "EAU", - "ENERGIE", - "TRANSPORT", - "DECHETS", - "TOMBES", - "RISQUES", - "CRIME", - "RISQUE INCENDIE", - "RISQUE NUCLEAIRE", - "POLLUTION", - "COMMERCE", - "PRODUCTION", - "IMPORT", - "EXPORT" - }; - - long int values[23] = { - -1, - calccity->misc[0], - calccity->population[0], - calccity->humans[0], - calccity->humans[1], - calccity->humans[2], - calccity->humans[3], - calccity->humans[4], - calccity->humans[5], - calccity->production[0], - calccity->production[1], - calccity->misc[6], - calccity->misc[7], - calccity->misc[8], - -1, - calccity->misc[1], - calccity->misc[3], - calccity->misc[4], - calccity->misc[5], - -1, - calccity->trade[2], - calccity->trade[0], - calccity->trade[1] - }; + extern const bopti_image_t img_fn_1; + int key = 0, x = 0, y = 0; while (key != KEY_ALPHA) { dclear(C_WHITE); - - // Title - drect(0, 0, 127, 6, C_BLACK); - dtext(27, 1, C_WHITE, "STATISTIQUES"); + display_large_map(calccity, camera, map); + display_around(calccity, camera, 0); + drect(3, 57, 19, 64, C_INVERT); - // Frame - dhline(0, C_BLACK); - dhline(63, C_BLACK); - dvline(0, C_BLACK); - dvline(127, C_BLACK); - - // Scroll bar - dline(5, 6, 5, 63, C_BLACK); - drect(2, scroll + 8, 3, 8 + scroll + 38, C_BLACK); - - for (int i = 0; i < 8; i ++) - { - if (values[i + scroll] < 0) - { - drect(5, 7 + i * 7, 127, 13 + i * 7, C_BLACK); - dtext(12, 8 + i * 7, C_WHITE, names[i + scroll]); - } - else - dprint(7, 8 + i * 7, C_BLACK, "%s %lu", names[i + scroll], values[i + scroll]); - } + dimage(3, 11, &img_fn_1); + drect(9 * x + 4, 9 * y + 12, 9 * x + 4 + 7, 9 * y + 12 + 7, C_INVERT); dupdate(); - - key = getkey_opt(opt, &timeout).key; + + struct building default_building = buildings[x + 3 * y]; + + key = rtc_key(); switch (key) { case KEY_UP: - if (scroll > 0) scroll --; + if (y > 0) y --; + break; + + case KEY_LEFT: + if (x > 0) x --; break; case KEY_DOWN: - if (scroll < 15) scroll ++; + if (y < 4) y ++; + break; + + case KEY_RIGHT: + if (x < 2) x ++; + break; + + case KEY_SHIFT: + *build_mode = 1; + return buildings[x + y * 3]; break; } - } + *build_mode = 0; + return default_building; } @@ -174,6 +118,124 @@ void menu_4(struct calccity *calccity) } +void menu_5(struct calccity *calccity) +{ + int scroll = 0, key = 0; + int opt = GETKEY_DEFAULT & GETKEY_REP_ARROWS; + int timeout = 0; + + static const char *names[28] = { + "GENERAL", + "ARGENT", + "POPULATION", + "LOGEMENT", + "SANTE", + "EDUCATION", + "NOURRITURE", + "TRAVAIL", + "TRANSPORT", + "SECURITE", + "CRIME", + "RISQUE INCENDIE", + "RISQUE NUCLEAIRE", + "POLLUTION", + "ECONOMIE", + "COMMERCE", + "INDUSTRIE", + "PRODUCTION", + "IMPORT", + "EXPORT", + "COUT ANNUEL", + "DIVERS", + "CONSO. EAU", + "PRODU. EAU", + "CONSO. ENERGIE", + "PRODU. ENERGIE", + "DECHETS", + "TOMBES" + }; + + long values[28] = {0}; + int offset = 0; + + for (int i = 0; i < 28; i ++) + { + switch (i) + { + case 0: case 9: case 14: case 21: + values[i] = -1; + offset ++; + break; + + case 1: + values[i] = calccity->misc[0]; + offset ++; + break; + + case 2: + values[i] = calccity->misc[1]; + offset ++; + break; + + case 23: + values[i] = calccity->misc[8]; + offset ++; + break; + + default: + values[i] = calccity->stat[i - offset]; + break; + } + } + + while (key != KEY_ALPHA) + { + dclear(C_WHITE); + + // Title + drect(0, 0, 127, 6, C_BLACK); + dtext(27, 1, C_WHITE, "STATISTIQUES"); + + // Frame + dhline(0, C_BLACK); + dhline(63, C_BLACK); + dvline(0, C_BLACK); + dvline(127, C_BLACK); + + // Scroll bar + dline(5, 6, 5, 63, C_BLACK); + drect(2, scroll + 8, 3, 8 + scroll + 33, C_BLACK); + + for (int i = 0; i < 8; i ++) + { + if (values[i + scroll] < 0) + { + drect(5, 7 + i * 7, 127, 13 + i * 7, C_BLACK); + dtext(12, 8 + i * 7, C_WHITE, names[i + scroll]); + } + else + dprint(7, 8 + i * 7, C_BLACK, "%s %lu", names[i + scroll], values[i + scroll]); + } + + dupdate(); + + key = getkey_opt(opt, &timeout).key; + + switch (key) + { + case KEY_UP: + if (scroll > 0) scroll --; + break; + + case KEY_DOWN: + if (scroll < 20) scroll ++; + break; + } + + } +} + + int menu_6(struct calccity *calccity) { int choice = 0, key = 0; @@ -182,12 +244,12 @@ int menu_6(struct calccity *calccity) while (key != KEY_ALPHA) { - int prcnt = 100 - (calccity->time_speed * 100 / 10000); + int prcnt = 100 - (calccity->time_speed * 100 / 7500); dclear(C_WHITE); drect(0, 0, 127, 6, C_BLACK); - dtext(39, 1, C_WHITE, "OPTIONS"); + dtext(42, 1, C_WHITE, "OPTIONS"); dhline(0, C_BLACK); dhline(63, C_BLACK); diff --git a/src/menus.h b/src/menus.h index d1d3caa..bfb02c9 100644 --- a/src/menus.h +++ b/src/menus.h @@ -2,7 +2,10 @@ #define _MENUS_H #include "calccity.h" +#include "core.h" +// menu_1 : building 1 +struct building menu_1(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode); // menu_4 : tax and funds void menu_4(struct calccity *calccity);