From da2a9b41727843beda6108c9144fc822eb1f5fa0 Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Sat, 29 May 2021 23:02:51 +0200 Subject: [PATCH] Fully operationnal purchase system --- Plague.g1a | Bin 45824 -> 46500 bytes src/core.c | 59 ---------------- src/core.h | 13 ++-- src/display_engine.c | 42 +++++------ src/display_engine.h | 4 +- src/main.c | 17 ++--- src/mutation_data.c | 44 +++++++----- src/mutation_engine.c | 159 ++++++++++++++++++++++++++++++++++++++++-- src/mutation_engine.h | 15 +++- 9 files changed, 223 insertions(+), 130 deletions(-) diff --git a/Plague.g1a b/Plague.g1a index 7c5eeb7bf59950cb259ae002de18b36ae3a210c9..88654ad10b8b1c944d8304268b4fbdb775e2b4ff 100644 GIT binary patch delta 5444 zcmZ`-eNaMgg_#M@L`NdLO?zvxdBw9X-oiHKokOqw9U960RhoQ8#M;j(9-3k zr_Cr_#&Nr-E?OyvwW%iZ>@H`@nWCmG$Jy;a5*rm=XP1uz8D(9!Wtpxiy0hmdMBJX8 zQ0JX{KJLf)-E+^okFHsE@EIF`^bD-MRy@S8 zUkq{!Od4a^c2g(`u0$BYj~nzjfZ?bQgc6}0A*KsqZV(}XT_|CZTSA$$}@f&LQVb%do>gz*GIUqP>o2!uDvz(xt=tOA4u!w3hqg3So4PeNESq&cIx zpt+*?vZvgkE>(@Ib)u~@XQ~V7MF(FxQ{3o&ieBVG&XkU5y{P4-BiWp#vxu5sI+N}t z=|#quM($psUUagu>80`Vy#&3;)OK$@=t-~oUOez_M|}E{G44WwPUJ=;e#$5b&sYkN znq_+w^)Da9XqUnoXHnRRCrnsV*vXzKka5_xuuEYi>;va&=+B#Eeks`6S(nE?wr%S14RObG+gCIfZ7@I{&k5no#HMJmezG&&JB!#1LIH-zo58`%n8c)XbIgUS%GQnY6)oyyd0#PV&bJpG>OPuP`co>1mVplq6}VB zp|iaB1DjdG-^qvW@Yje!&>}jHj`ohzJH_tZ=mKg8Oz6_HPQ zyQ6rCMIyf3(A~^yA{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4#VEP_9h~@C{-&#o$=I(%c)tOl9H0&1Ryd3Y zU?Kba0iYbVf~>U%cp3nXw_NLBB)^4v^V?Z6!gtv_T)~HnFg3WbdjMgJFWh~FDG&cV z?^Qoc;5ryzGZ5~=z4KX+ru=aG5#8(sx5V%;f+e&}AQ5)Wl9o@jr}`tv?DfI_1)t?) A!2kdN diff --git a/src/core.c b/src/core.c index b9554cb..d0496e3 100644 --- a/src/core.c +++ b/src/core.c @@ -113,62 +113,3 @@ int callback_tick(volatile int *tick) return TIMER_CONTINUE; } - -void manage_mutation(struct game *current_game, const int mutation_menu) -{ - int key = 0, end = 0; - struct cursor c = {0, 0, 0}; - - static volatile int tick = 1; - int t = timer_configure(TIMER_ANY, CURSOR_TICK*1000, GINT_CALL(callback_tick, &tick)); - if (t >= 0) timer_start(t); - - - while (!end) - { - // Cursor blinking gestion - while (!tick) sleep(); - tick = 0; - c.display = (c.display + 1) % 2; - - // Get and display the mutation menu - int table[4][8]; - get_mutation(current_game, mutation_menu, table); - display_mutation(table, c, mutation_menu); - - // Get the key - key = rtc_key(); - - // Manage input - if (key == KEY_EXIT) end = 1; - if (key == KEY_EXE && table[c.y][c.x] != 15 && table[c.y][c.x] != 0) mutation_buy(current_game, c, mutation_menu, table); - - if (key == KEY_LEFT && c.x > 0) c.x--; - if (key == KEY_RIGHT && c.x < 7) c.x++; - if (key == KEY_UP && c.y > 0) c.y--; - if (key == KEY_DOWN && c.y < 3) c.y++; - } - if (t >= 0) timer_stop(t); -} - - -void mutation_buy(struct game *current_game, const struct cursor c, const int mutation_menu, const int table[4][8]) -{ - int button_selected = 1, end = 0; - int key = 0; - - while (!end) - { - mutation_selected(c, mutation_menu, table, button_selected); - key = getkey().key; - - if (key == KEY_DOWN || key == KEY_UP) button_selected = (button_selected + 1) % 2; - if (key == KEY_EXIT) end = 1; - if (key == KEY_EXE) - { - if (!button_selected) end = 1; - // else evolution - } - - } -} diff --git a/src/core.h b/src/core.h index dc16d39..fdf14e5 100644 --- a/src/core.h +++ b/src/core.h @@ -20,9 +20,10 @@ struct game // DNA points int dna; - // Mutations counts and sprite selected - int abilities, symptoms, transmissions; - int abilities_sel, symptoms_sel, transmissions_sel; + // Mutations counts, mutations selected, mutations bought (symptoms; abilities; transmissions) + int mutations_count[3]; + int mutations_selected[3]; + int mutations_bought[3][14]; // Research data int research, limit; @@ -76,10 +77,4 @@ int rtc_key(void); // callback_timer : basic timer int callback_tick(volatile int *tick); -// manage_mutation : an independant sub-programm which allow to select and see the mutations. -void mutation_select(struct game *current_game, const int mutation_menu); - -// mutation_buy : UI interface to buy mutations and see informations on them -void mutation_buy(struct game *current_game, const struct cursor c, const int mutation_menu, const int table[4][8]); - #endif /* _PLAGUE_CORE_H */ \ No newline at end of file diff --git a/src/display_engine.c b/src/display_engine.c index 7280944..0e36e00 100644 --- a/src/display_engine.c +++ b/src/display_engine.c @@ -39,6 +39,9 @@ void display_foreground(const int background, const struct game *current_game) break; case 3: + + dprint(1, 35, C_BLACK, "C:%d S:%d L:%d", current_game->contagion, current_game->severity, current_game->lethality); + dprint(102, 37, C_BLACK, "%d", current_game->dna); length = 67 * current_game->contagion / 26; @@ -53,9 +56,9 @@ void display_foreground(const int background, const struct game *current_game) dline(57, 60, 57 + length, 60, C_BLACK); dline(57, 61, 57 + length, 61, C_BLACK); - if (current_game->symptoms_sel) dsubimage(5, 15, &img_mutations, 0, 16 * (current_game->symptoms_sel - 1), 15, 15, 0); - if (current_game->abilities_sel) dsubimage(35, 15, &img_mutations, 16, 16 * (current_game->abilities_sel - 1), 15, 15, 0); - if (current_game->transmissions_sel) dsubimage(65, 15, &img_mutations, 32, 16 * (current_game->transmissions_sel - 1), 15, 15, 0); + if (current_game->mutations_selected[0]) dsubimage(5, 15, &img_mutations, 0, 16 * (current_game->mutations_selected[0] - 1), 15, 15, 0); + if (current_game->mutations_selected[1]) dsubimage(35, 15, &img_mutations, 16, 16 * (current_game->mutations_selected[1] - 1), 15, 15, 0); + if (current_game->mutations_selected[2]) dsubimage(65, 15, &img_mutations, 32, 16 * (current_game->mutations_selected[2] - 1), 15, 15, 0); break; case 6: @@ -99,31 +102,12 @@ void display_mutation(const int table[4][8], const struct cursor c, const int mu } -void mutation_selected(const struct cursor c, const int mutation_menu, const int table[4][8], const int button_selected) +void display_mutation_buy(const struct cursor c, const int mutation_menu, const int table[4][8], const int button_selected) { extern const bopti_image_t img_mutations; const int id = table[c.y][c.x]; - extern struct mutation symptoms_data[14]; - extern struct mutation abilities_data[6]; - extern struct mutation transmissions_data[13]; - - struct mutation *mutation_data; - - switch (mutation_menu) - { - case 1: - mutation_data = &symptoms_data[id - 1]; - break; - - case 2: - mutation_data = &abilities_data[id - 1]; - break; - - case 3: - mutation_data = &transmissions_data[id - 1]; - break; - } + struct mutation *mutation_data = get_mutation_data(mutation_menu, id); dclear(C_WHITE); @@ -140,8 +124,14 @@ void mutation_selected(const struct cursor c, const int mutation_menu, const int else drect(81, 12, 123, 18, C_INVERT); dupdate(); - - +} + + +void output_error(const char *msg) +{ + dclear(C_WHITE); + dprint(0, 0, C_BLACK, msg); + dupdate(); } diff --git a/src/display_engine.h b/src/display_engine.h index 21670df..0ef9459 100644 --- a/src/display_engine.h +++ b/src/display_engine.h @@ -13,6 +13,8 @@ void display_foreground(const int background, const struct game *current_game); void display_mutation(const int table[4][8], const struct cursor c, const int mutation_menu); // mutation_selected : display the mutation's informations screen -void mutation_selected(const struct cursor c, const int mutation_menu, const int table[4][8], const int button_selected); +void display_mutation_buy(const struct cursor c, const int mutation_menu, const int table[4][8], const int button_selected); +// output_error : display text +void output_error(const char *msg); #endif /* _PLAGUE_DISPLAY_ENGINE_H */ \ No newline at end of file diff --git a/src/main.c b/src/main.c index a161c31..2396119 100644 --- a/src/main.c +++ b/src/main.c @@ -1,9 +1,9 @@ /* - Name ..............: Plague + Project name ......: Plague Version ...........: - dev - - Last modification .: 24 May 2021 + Last modification .: 29 May 2021 - Code provided with licence : + code provided with licence : GNU General Public Licence v3.0 */ @@ -14,6 +14,7 @@ #include "core.h" #include "display_engine.h" +#include "mutation_engine.h" // title_screen : display the title screen @@ -43,11 +44,11 @@ int main(void) .severity = 0, .lethality = 0, - .dna = 0, + .dna = 100, - .abilities = 1, .abilities_sel = 0, - .symptoms = 1, .symptoms_sel = 0, - .transmissions = 1, .transmissions_sel = 0, + .mutations_count = {0, 0, 0}, + .mutations_selected = {0, 0, 0}, + .mutations_bought = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, .research = 0, .limit = 100, @@ -110,7 +111,7 @@ void main_loop(struct game *current_game) if (background == -1) end = 1; if (background == 5) { - manage_mutation(current_game, mutation_menu); + mutation_select(current_game, mutation_menu); background = 3; } } diff --git a/src/mutation_data.c b/src/mutation_data.c index f298398..28410b1 100644 --- a/src/mutation_data.c +++ b/src/mutation_data.c @@ -1,5 +1,25 @@ #include "mutation_engine.h" + +const struct mutation symptoms_data[14] = +{ + {1, 1, 0, 2, 0, "NAUSEE"}, + {3, 2, 0, 4, 0, "VOMISSEMENT"}, + {2, 1, 0, 3, 0, "TOUX"}, + {2, 2, 0, 4, 0, "PNEUMONIE"}, + {4, 2, 5, 15, 1, "TUMEUR"}, + {2, 1, 0, 3, 0, "PLAIES"}, + {5, 4, 0, 10, 0, "LESIONS"}, + {5, 15, 15, 20, 0, "HEMORRAGIE"}, + {6, 7, 6, 17, 0, "INFECTION"}, + {2, 2, 2, 5, 0, "INFLAMMATION"}, + {2, 6, 4, 12, 1, "IMMUNITE"}, + {0, 4, 0, 5, 1, "PARANOIA"}, + {6, 15, 0, 20, 2, "FOLIE"}, + {0, 20, 25, 30, 2, "ARRET TOTAL"}, +}; + + const struct mutation abilities_data[6] = { {4, 0, 0, 10, 0, "FROID"}, @@ -10,23 +30,6 @@ const struct mutation abilities_data[6] = {0, 2, 2, 15, 1, "MEDICAMENT"}, }; -const struct mutation symptoms_data[14] = -{ - {1, 1, 0, 2, 0.5, "NAUSEE"}, - {3, 2, 0, 4, 0.5, "VOMISSEMENT"}, - {2, 1, 0, 3, 0.5, "TOUX"}, - {2, 2, 0, 4, 0.5, "PNEUMONIE"}, - {4, 2, 5, 15, 1, "TUMEUR"}, - {2, 1, 0, 3, 0.5, "PLAIES"}, - {5, 4, 0, 10, 0.5, "LESIONS"}, - {5, 15, 15, 20, 0.5, "HEMORRAGIE"}, - {6, 7, 6, 17, 0.5, "INFECTION"}, - {2, 2, 2, 5, 0.5, "INFLAMMATION"}, - {2, 6, 4, 12, 1, "IMMUNODEFICIENCE"}, - {0, 4, 0, 5, 1, "PARANOIA"}, - {6, 15, 0, 20, 2, "FOLIE"}, - {0, 20, 25, 30, 2, "ARRET TOTAL"}, -}; const struct mutation transmissions_data[13] = { @@ -42,5 +45,8 @@ const struct mutation transmissions_data[13] = { 6, 0, 0, 16, 0, "OISEAU 2"}, { 1, 0, 0, 8, 0, "SANG 1"}, { 4, 0, 0, 14, 0, "SANG 2"}, - { 9, 0, 0, 20, 0, "SANG 3"}, -}; \ No newline at end of file + { 9, 1, 1, 20, 0, "SANG 3"}, +}; + + +const struct mutation default_value = {0, 0, 0, 1, 0, "VIDE"}; \ No newline at end of file diff --git a/src/mutation_engine.c b/src/mutation_engine.c index a4dc60b..c33297a 100644 --- a/src/mutation_engine.c +++ b/src/mutation_engine.c @@ -1,3 +1,9 @@ +#include +#include +#include + +#include + #include "mutation_engine.h" void get_mutation(const struct game *current_game, const int mutation_menu, int table[4][8]) @@ -19,27 +25,168 @@ void get_mutation(const struct game *current_game, const int mutation_menu, int if (mutation_menu == 1) { - if (current_game->symptoms < 4) init_mat(8, 4, table, mt_symptoms_1.data); - else if (current_game->symptoms < 8) init_mat(8, 4, table, mt_symptoms_2.data); + if (current_game->mutations_count[0] < 4) init_mat(8, 4, table, mt_symptoms_1.data); + else if (current_game->mutations_count[0] < 8) init_mat(8, 4, table, mt_symptoms_2.data); else init_mat(8, 4, table, mt_symptoms_3.data); } if (mutation_menu == 2) { - if (current_game->abilities < 2) init_mat(8, 4, table, mt_abilities_1.data); - else if (current_game->abilities < 4) init_mat(8, 4, table, mt_abilities_2.data); + if (current_game->mutations_count[1] < 2) init_mat(8, 4, table, mt_abilities_1.data); + else if (current_game->mutations_count[1] < 4) init_mat(8, 4, table, mt_abilities_2.data); else init_mat(8, 4, table, mt_abilities_3.data); } if (mutation_menu == 3) { - if (current_game->transmissions < 5) init_mat(8, 4, table, mt_transmissions_1.data); - else if (current_game->transmissions < 10) init_mat(8, 4, table, mt_transmissions_2.data); + if (current_game->mutations_count[2] < 5) init_mat(8, 4, table, mt_transmissions_1.data); + else if (current_game->mutations_count[2] < 10) init_mat(8, 4, table, mt_transmissions_2.data); else init_mat(8, 4, table, mt_transmissions_3.data); } } +void mutation_select(struct game *current_game, const int mutation_menu) +{ + int key = 0, end = 0; + struct cursor c = {0, 0, 0}; + + static volatile int tick = 1; + int t = timer_configure(TIMER_ANY, CURSOR_TICK*1000, GINT_CALL(callback_tick, &tick)); + if (t >= 0) timer_start(t); + + + while (!end) + { + // Cursor blinking gestion + while (!tick) sleep(); + tick = 0; + c.display = (c.display + 1) % 2; + + // Get and display the mutation menu + int table[4][8]; + get_mutation(current_game, mutation_menu, table); + display_mutation(table, c, mutation_menu); + + // Get the key + key = rtc_key(); + + // Manage input + if (key == KEY_EXIT) end = 1; + if (key == KEY_EXE && table[c.y][c.x] != 15 && table[c.y][c.x] != 0) + { + end = mutation_buy(current_game, c, mutation_menu, table); + } + + if (key == KEY_LEFT && c.x > 0) c.x --; + if (key == KEY_RIGHT && c.x < 7) c.x ++; + if (key == KEY_UP && c.y > 0) c.y --; + if (key == KEY_DOWN && c.y < 3) c.y ++; + } + if (t >= 0) timer_stop(t); +} + + +int mutation_buy(struct game *current_game, const struct cursor c, const int mutation_menu, const int table[4][8]) +{ + int button_selected = 1; + int key = 0, id = table[c.y][c.x]; + + struct mutation *mutation_data = get_mutation_data(mutation_menu, table[c.y][c.x]); + + while (1) + { + display_mutation_buy(c, mutation_menu, table, button_selected); + key = getkey().key; + + if (key == KEY_DOWN || key == KEY_UP) button_selected = (button_selected + 1) % 2; + if (key == KEY_EXIT) return 1; + if (key == KEY_EXE) + { + if (!button_selected) return 0; + else + { + // if the player has'nt bought this mutation yet + if (!current_game->mutations_bought[mutation_menu - 1][id - 1]) + { + // if the player has enought DNA points + if (current_game->dna >= mutation_data->dna) + { + // Take DNA points and save the purchase + current_game->dna = current_game->dna - mutation_data->dna; + current_game->mutations_bought[mutation_menu - 1][id - 1] = 1; + current_game->mutations_count[mutation_menu - 1] ++; + current_game->mutations_selected[mutation_menu - 1] = id; + + // Update + update_disease(current_game); + } + else {output_error("Achat impossible"); getkey();} + } + + // if the player has already bought this mutation + else + { + current_game->mutations_selected[mutation_menu - 1] = id; + update_disease(current_game); + } + + } + return 1; + } + } + return 0; +} + + +void update_disease(struct game *current_game) +{ + struct mutation *symptom = get_mutation_data(1, current_game->mutations_selected[0]); + struct mutation *ability = get_mutation_data(2, current_game->mutations_selected[1]); + struct mutation *transmission = get_mutation_data(3, current_game->mutations_selected[2]); + + dclear(C_WHITE); + dprint(0, 0, C_BLACK, "SY C:%d S:%d L:%d", symptom->contagion, symptom->severity, symptom->lethality); + dprint(0, 8, C_BLACK, "AB C:%d S:%d L:%d", ability->contagion, ability->severity, ability->lethality); + dprint(0, 16, C_BLACK, "TR C:%d S:%d L:%d", transmission->contagion, transmission->severity, transmission->lethality); + dupdate(); + getkey(); + + current_game->contagion = symptom->contagion + ability->contagion + transmission->contagion; + current_game->severity = symptom->severity + ability->severity + transmission->severity; + current_game->lethality = symptom->lethality + ability->lethality + transmission->lethality; +} + + +struct mutation *get_mutation_data(const int mutation_menu, const int id) +{ + extern struct mutation symptoms_data[14]; + extern struct mutation abilities_data[6]; + extern struct mutation transmissions_data[13]; + extern struct mutation default_value; + + if (!id) return &default_value; + + struct mutation *mutation_data = &default_value; + + switch (mutation_menu) + { + case 1: + mutation_data = &symptoms_data[id - 1]; + break; + + case 2: + mutation_data = &abilities_data[id - 1]; + break; + + case 3: + mutation_data = &transmissions_data[id - 1]; + break; + } + return mutation_data; +} + + void init_mat(int x, int y, int dest[][x], int src[][x]) { for (int i = 0; i < x; i++) diff --git a/src/mutation_engine.h b/src/mutation_engine.h index a132110..206ba50 100644 --- a/src/mutation_engine.h +++ b/src/mutation_engine.h @@ -2,6 +2,7 @@ #define _MUTATION_ENGINE_H #include "core.h" +#include "display_engine.h" // mutation_table : contain the map of the mutation available struct mutation_table @@ -23,10 +24,20 @@ struct mutation // get_mutation : return the mutation table to display void get_mutation(const struct game *current_game, const int mutation_menu, int table[4][8]); +// manage_mutation : an independant sub-programm which allow to select and see the mutations. +void mutation_select(struct game *current_game, const int mutation_menu); + +// mutation_buy : UI interface to buy mutations and see informations on them +int mutation_buy(struct game *current_game, const struct cursor c, const int mutation_menu, const int table[4][8]); + +// update_disease : update the disease parameters +void update_disease(struct game *current_game); + +// get_mutation_data : get the information from a mutation +struct mutation * get_mutation_data(const int mutation_menu, const int id); + // init_mat : copy src into dest (for int) void init_mat(int x, int y, int dest[][x], int src[][x]); -// char_init_mat : copy src into dest (for char) -void char_init_mat(int x, char dest[x], char srx[x]); #endif /* _MUTATION_ENGINE_H */ \ No newline at end of file