dev #5

Closed
Shadow wants to merge 12 commits from dev into master
9 changed files with 130 additions and 22 deletions

View File

@ -16,6 +16,7 @@ set(SOURCES
src/mutation_engine.c
src/data.c
src/epidemic_engine.c
src/save.c
# ...
)
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets

Binary file not shown.

View File

@ -1,6 +1,7 @@
#include <gint/timer.h>
#include <gint/clock.h>
#include <gint/keyboard.h>
#include <math.h>
#include "core.h"
#include "mutation_engine.h"
@ -53,12 +54,12 @@ void next_frame(struct game *current_game)
current_game->time = 0;
// Update the game
if (current_game->dna <= 100) current_game->dna += 1;
current_game->research += current_game->priority;
if (current_game->dna <= 100) current_game->dna += 1 + floor(current_game->severity / 25);
if (current_game->research < current_game->limit) current_game->research += current_game->priority;
epidemic_simulation(current_game);
// Check the end of the game
if (current_game->research > current_game->limit)
if (current_game->research >= current_game->limit)
{
const char *msg[5] = {"Vous avez", "perdu.", "", "", ""};
message(msg);

View File

@ -3,6 +3,8 @@
#include <gint/defs/types.h>
// Duration for internal clock (ms)
#define ENGINE_TICK 50
#define CURSOR_TICK 150

View File

@ -4,17 +4,17 @@
// (contation, severity, lethality, DNA cost, change to cure requirement)
const struct mutation symptoms_data[14] =
{
{15, 10, 0, 2, 0, "NAUSEE"},
{25, 10, 0, 4, 0, "VOMISSEMENT"},
{10, 10, 0, 2, 0, "NAUSEE"},
{25, 10, 0, 10, 0, "VOMISSEMENT"},
{20, 10, 0, 3, 0, "TOUX"},
{15, 20, 0, 4, 0, "PNEUMONIE"},
{15, 20, 0, 10, 0, "PNEUMONIE"},
{10, 30, 20, 15, 25, "TUMEUR"},
{25, 10, 0, 4, 0, "PLAIES"},
{10, 10, 0, 10, 0, "LESIONS"},
{30, 20, 20, 20, 30, "HEMORRAGIE"},
{25, 15, 10, 17, 0, "INFECTION"},
{15, 10, 10, 5, 0, "INFLAMMATION"},
{10, 15, 20, 12, 0, "IMMUNITE"},
{25, 10, 20, 20, 0, "INFLAMMATION"},
{10, 15, 20, 15, 0, "IMMUNITE"},
{ 0, 20, 0, 15, 120, "PARANOIA"},
{ 0, 15, 0, 20, 100, "FOLIE"},
{ 0, 30, 30, 30, 250, "ARRET TOTAL"},
@ -25,8 +25,8 @@ const struct mutation abilities_data[6] =
{
{15, 0, 0, 10, 0, "FROID"},
{15, 0, 0, 15, 0, "CHAUD"},
{ 0, 20, 4, 25, 20, "GENETIQUE"},
{10, 40, 8, 30, 50, "MUTATION+"},
{ 0, 10, 4, 25, 20, "GENETIQUE"},
{10, 40, 20, 30, 50, "MUTATION+"},
{30, 0, 0, 30, 0, "ENVIRON"},
{ 0, 15, 30, 15, 30, "MEDICAMENT"},
};

View File

@ -1,7 +1,7 @@
/*
Project name ......: Plague
Version ...........: - dev -
Last modification .: 29 May 2021
Version ...........: 2.0
Last modification .: 04 June 2021
code and assets provided with licence :
GNU General Public Licence v3.0
@ -17,7 +17,7 @@
#include "core.h"
#include "display_engine.h"
#include "mutation_engine.h"
#include "save.h"
// title_screen : display the title screen
static void title_screen(void);
@ -41,6 +41,7 @@ int main(void)
struct plane plane_4 = {104, 20, 3, 104, 50, 104, 20};
struct plane plane_5 = {68, 44, 4, 34, 44, 68, 44};
struct game current_game =
{
.contagion = 0,
@ -65,21 +66,19 @@ int main(void)
.grid = {64, 128, NULL},
};
/* allocate memory */
// Allocate memory
current_game.grid.data = calloc(current_game.grid.width * current_game.grid.height, sizeof(uint8_t));
if (current_game.grid.data == NULL)
{
const char *msg[5] = {"CALLOC", "FAILED", "", "", ""};
message(msg);
}
current_game.grid.data[95 + 20 * current_game.grid.width] = 1;
current_game.humans[0] = (current_game.grid.width * current_game.grid.height) - 1;
read_save(&current_game);
main_loop(&current_game);
/* free memory */
write_save(&current_game);
// Free memory
free(current_game.grid.data);
return 1;

View File

@ -158,7 +158,7 @@ void update_disease(struct game *current_game)
// research parameters
current_game->limit = RESEARCH_LIMIT + symptom->changement + ability->changement + transmission->changement;
current_game->priority = floor((current_game->severity + current_game->lethality) / 200);
current_game->priority = floor((current_game->severity + current_game->lethality) / 40);
}

93
src/save.c Normal file
View File

@ -0,0 +1,93 @@
#include <gint/bfile.h>
#include <gint/defs/types.h>
#include <gint/std/stdlib.h>
#include "save.h"
/* BUG
Démarrer le jeu, quitter, revenir sur le jeu, quitter -> la calto plante
=> Premier démarrage du jeu : ok (valeur par défaut bien initialisée)
=> Quand on revient sur le jeu, pas de problème : tout est sauvé correctement (sauvé correctement et chargé correctement)
=> On quitte : bug
*/
// Name of the savefile
static const uint16_t *filename = u"\\\\fls0\\Plague.sav";
void read_save(struct game *current_game)
{
struct BFile_FileInfo fileInfo;
int fd, handle;
uint16_t foundpath[30];
// Sizes of data and init
const int planes_size = sizeof(*current_game->planes) * (NB_PLANES + 1);
struct plane *new_planes[NB_PLANES + 1];
for (int i = 0; i < NB_PLANES; i ++)
{
new_planes[i] = current_game->planes[i];
}
const int data_size = current_game->grid.width * current_game->grid.height;
uint8_t *data = current_game->grid.data;
// Check if the savefile exists
char checkfile = BFile_FindFirst(filename, &handle, foundpath, &fileInfo);
BFile_FindClose(handle);
// If file doesn't exists
if (checkfile == -1)
{
int size = sizeof(struct game) + planes_size + data_size;
BFile_Create(filename, BFile_File, &size);
}
// Loading game data
else
{
fd = BFile_Open(filename, BFile_ReadOnly);
BFile_Read(fd, current_game, sizeof(struct game), 0);
// Overwritten struct plane* planes
for (int i = 0; i < NB_PLANES; i ++)
{
current_game->planes[i] = new_planes[i];
}
// Loa
for (int i = 0; i < NB_PLANES; i ++)
{
BFile_Read(fd, current_game->planes[i], sizeof(struct plane), -1);
}
BFile_Read(fd, data, data_size, -1);
BFile_Close(fd);
current_game->grid.data = data;
}
}
void write_save(const struct game *current_game)
{
// Remove the old savefile
BFile_Remove(filename);
// Create a new one
const int data_size = current_game->grid.width * current_game->grid.height;
int size = sizeof(struct game) + NB_PLANES * sizeof(struct plane) + data_size;
BFile_Create(filename, BFile_File, &size);
int fd = BFile_Open(filename, BFile_WriteOnly);
// Write data
BFile_Write(fd, current_game, sizeof(struct game));
for (int i = 0; i < NB_PLANES ; i ++)
{
BFile_Write(fd, current_game->planes[i], sizeof(struct plane));
}
BFile_Write(fd, current_game->grid.data, data_size);
// Close file
BFile_Close(fd);
}

12
src/save.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef _SAVE_H
#define _SAVE_H
#include "core.h"
// read_save : read or create a new save
void read_save(struct game *current_game);
// write_save : write the savefile
void write_save(const struct game *current_game);
#endif /* _SAVE_H */