Commit 33b68769 authored by Nicolas LIENART's avatar Nicolas LIENART

Centrale now have limited amount of ammo

parent f09b3a40
......@@ -13,11 +13,11 @@ inconstructible 255 0 234
# Player info
argent 2000
# Construction Data
laser 1 1 2 2 0 200 100
missile 2 1 1 1 0 300 150
laser 1 1 2 2 0 200 100 1
missile 2 1 1 1 0 300 150 2
radar 0 0 0 1 2 200 100
armement 1 0 0 0 2 400 200
centrale 0 1 0 2 2 400 200
centrale 0 1 0 2 2 400 200 10
munition 0 0 1 0 2 400 200
# Monster Data
solder 1.0 1.0 1.0 1.0
......
......@@ -13,11 +13,11 @@ inconstructible 255 0 234
# Player info
argent 2120
# Construction Data (DEGAT ALIM CAD PORTEE RANGE VAL VAL)
laser 1 1 5 2 0 200 100
missile 2 1 2 1 0 300 150
laser 1 1 5 2 0 200 100 1
missile 2 1 2 1 0 300 150 2
radar 0 0 0 1 2 200 100
armement 1 0 0 0 2 400 200
centrale 0 1 0 2 2 400 200
centrale 0 1 0 2 2 400 200 10
munition 0 0 1 0 2 400 200
# Monster Data (PDV ATTACK MASS VALUE)
solder 1.0 1.0 0.6 10.0
......
......@@ -13,11 +13,11 @@ inconstructible 255 0 234
# Player info
argent 3000
# Construction Data (DEGAT ALIM CAD PORTEE RANGE VAL VAL)
laser 1 1 5 2 0 200 100
missile 2 1 2 1 0 300 150
laser 1 1 5 2 0 200 100 1
missile 2 1 2 1 0 300 150 2
radar 0 0 0 1 2 200 100
armement 1 0 0 0 2 400 200
centrale 0 1 0 2 2 400 200
centrale 0 1 0 2 2 400 200 10
munition 0 0 1 0 2 400 200
# Monster Data (PDV ATTACK MASS VALUE)
solder 1.0 1.0 0.4 10.0
......
......@@ -84,6 +84,7 @@ void case_initPlateau()
memcpy(tmp , mapData->listWaves->next->monsters, sizeof(TypeMonster)*mapData->listWaves->next->monster_total);
plateau->currentWave.monsters = tmp;
plateau->energies = calloc(mapData->Xsplit*mapData->Ysplit, sizeof(int));
plateau->tours = calloc(mapData->Xsplit*mapData->Ysplit, sizeof(Tour*));
if (!plateau->tours) {
return EXIT_FAILURE;
......@@ -179,6 +180,18 @@ GeneralType case_getGeneralConstructionType(TypeCase type)
}
}
double case_distanceBetweenIndexes(int index_case_1, int index_case_2)
{
int caseX_1, caseY_1;
int caseX_2, caseY_2;
case_getCasePosition(index_case_1, &caseX_1, &caseY_1);
case_getCasePosition(index_case_2, &caseX_2, &caseY_2);
double hypo = sqrt(pow(caseX_1 - caseX_2, 2) + pow(caseY_1 - caseY_2, 2));
return hypo;
}
void case_addConstruction(int caseX, int caseY)
{
int index_case = case_getCaseIndex(caseX, caseY);
......@@ -189,6 +202,10 @@ void case_addConstruction(int caseX, int caseY)
case_update(caseX, caseY, type);
if (type == CENTRALE) {
plateau->energies[index_case] = mapData->constructionData[CENTRALE].energy;
}
if (generalType == TOUR) {
printf("adding tower\n");
tour_add(type, index_case);
......@@ -434,7 +451,3 @@ void case_freePlateau() {
case_cleanCases();
free(plateau);
}
......@@ -21,6 +21,7 @@
#include "projectile.h"
TypeCase* case_loadFromPPM();
double case_distanceBetweenIndexes(int index_case_1, int index_case_2);
void case_gameData_init();
void case_initPlateau();
int case_RGBCompare(RGBcolor color1, RGBcolor color2);
......
......@@ -245,6 +245,12 @@ int itd_getConstructionData(FILE* file, TypeCase type)
mapData->constructionData[type].range = range;
mapData->constructionData[type].valeur_achat = valeur_achat;
mapData->constructionData[type].valeur_revente = valeur_revente;
if (type == CENTRALE || type == LASER || type == MISSILE) {
int energy;
int noOfColors = fscanf(file, "%d", &energy);
mapData->constructionData[type].energy = energy;
}
return CHK_SUCCESS;
}
}
......
......@@ -122,6 +122,7 @@ typedef struct ConstructionData {
TypeCase type;
int degats;
int alimentation;
int energy;
int cadence;
int portee;
int range;
......@@ -254,6 +255,7 @@ typedef struct TextureText {
typedef struct Tour {
TypeCase type;
int armement;
int index_case;
int centrale;
int munition;
float rechargement;
......@@ -411,6 +413,7 @@ typedef struct Plateau {
ListMonsters* listMonsters;
ListProjectiles* listProjectiles;
Wave currentWave;
int *energies;
Tour **tours;
} Plateau;
......
......@@ -52,6 +52,7 @@ Tour *tour_create(TypeCase type, int index_case)
case_getCasePosition(index_case, &caseX, &caseY);
new->type = type;
new->index_case = index_case;
new->armement = 0;
new->centrale = 0;
new->radar = 0;
......@@ -119,6 +120,45 @@ int tour_countBatiments(TypeCase type, int index_case)
return counter;
}
int tour_closestCentrale(int index_case)
{
TypeCase type = mapData->cases[index_case];
int closest = -1;
double closestDistance = 0;
int Xsplit = mapData->Xsplit;
int Ysplit = mapData->Ysplit;
int total_cases = Xsplit * Ysplit;
int range = mapData->constructionData[CENTRALE].range;
int counter = 0;
for (int i = index_case - range*Xsplit; i <= index_case + range*Xsplit; i+=Xsplit) {
if (i < 0 || i >= total_cases) {
continue;
}
for (int j = i-range; j <= i+range; j++) {
if (i/Xsplit != j/Xsplit || j < 0 || j >= total_cases) {
continue;
}
if (mapData->cases[j] == CENTRALE) {
if (plateau->energies[j] >= mapData->constructionData[type].energy) {
if (closest == -1) {
closestDistance = case_distanceBetweenIndexes(j, index_case);
closest = j;
}
else if (closestDistance > case_distanceBetweenIndexes(j, index_case)){
closestDistance = case_distanceBetweenIndexes(j, index_case);
closest = j;
}
}
}
}
}
return closest;
}
void tour_completeInfo(TypeCase type, int index_case)
{
int counter_batiment = tour_countBatiments(type, index_case);
......@@ -205,6 +245,17 @@ void tour_tire(Tour* tour)
tour->rechargement = tour_getCadence(tour->type);
tour->time_tir = SDL_GetTicks();
int index_closest_centrale = tour_closestCentrale(tour->index_case);
tour_reduceEnergyCentrale(index_closest_centrale, mapData->constructionData[tour->type].energy);
}
void tour_reduceEnergyCentrale(int index_case, int energy)
{
plateau->energies[index_case] -= energy;
if (plateau->energies[index_case] <= 0) {
mapData->cases[index_case] = TERRAIN;
}
}
float tour_calculCadence(Tour* tour)
......@@ -217,8 +268,11 @@ float tour_calculCadence(Tour* tour)
Bool tour_checkAlimentation(Tour* tour)
{
if (tour->centrale > 0) {
return TRUE;
int index_closest_centrale = tour_closestCentrale(tour->index_case);
if (index_closest_centrale != -1) {
if (plateau->energies[index_closest_centrale] >= mapData->constructionData[tour->type].energy) {
return TRUE;
}
}
else return FALSE;
}
......
......@@ -14,6 +14,8 @@
#include "projectile.h"
// Functions
void tour_reduceEnergyCentrale(int index_case, int energy);
int tour_closestCentrale(int index_case);
void tour_updateShootingAngle(Tour* tour);
ListTours* tour_initListTours();
int tour_getDegats(TypeCase type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment