Skip to content

Commit

Permalink
#define MAX_FIGHTERS + some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Nov 21, 2014
1 parent c9cc2a1 commit 6ce2d5f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/graphics/Renderer.cpp
Expand Up @@ -1377,7 +1377,7 @@ void Renderer::render_parts()
cplayer = &sim->player;
else if(t==PT_STKM2)
cplayer = &sim->player2;
else if(t==PT_FIGH)
else if (t==PT_FIGH && sim->parts[i].tmp >= 0 && sim->parts[i].tmp < MAX_FIGHTERS)
cplayer = &sim->fighters[(unsigned char)sim->parts[i].tmp];
else
continue;
Expand Down
36 changes: 17 additions & 19 deletions src/simulation/Simulation.cpp
Expand Up @@ -148,8 +148,7 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
}
else if (parts[i].type == PT_FIGH)
{
//TODO: 100 should be replaced with a macro
for(int fcount = 0; fcount < 100; fcount++)
for (int fcount = 0; fcount < MAX_FIGHTERS; fcount++)
{
if(!fighters[fcount].spwn)
{
Expand Down Expand Up @@ -318,7 +317,7 @@ Snapshot * Simulation::CreateSnapshot()
snap->FanVelocityY.insert(snap->FanVelocityY.begin(), &fvy[0][0], &fvy[0][0]+((XRES/CELL)*(YRES/CELL)));
snap->stickmen.push_back(player2);
snap->stickmen.push_back(player);
snap->stickmen.insert(snap->stickmen.begin(), &fighters[0], &fighters[255]);
snap->stickmen.insert(snap->stickmen.begin(), &fighters[0], &fighters[MAX_FIGHTERS]);
snap->signs = signs;
return snap;
}
Expand Down Expand Up @@ -2686,6 +2685,16 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type
kill_part(i);
return;
}
else if ((t == PT_STKM || t == PT_STKM2 || t == PT_SPAWN || t == PT_SPAWN2) && elementCount[t])
{
kill_part(i);
return;
}
else if ((t == PT_STKM && player.spwn) || (t == PT_STKM2 && player2.spwn))
{
kill_part(i);
return;
}

if (parts[i].type == PT_STKM)
player.spwn = 0;
Expand All @@ -2709,17 +2718,6 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type
else if (parts[i].type == PT_SOAP)
Element_SOAP::detach(this, i);

if ((t == PT_STKM || t == PT_STKM2 || t == PT_SPAWN || t == PT_SPAWN2) && elementCount[t])
{
kill_part(i);
return;
}
else if ((t == PT_STKM && player.spwn) || (t == PT_STKM2 && player2.spwn))
{
kill_part(i);
return;
}

if (parts[i].type > 0 && parts[i].type < PT_NUM && elementCount[parts[i].type])
elementCount[parts[i].type]--;
elementCount[t]++;
Expand All @@ -2734,8 +2732,8 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type
Element_STKM::STKM_init_legs(this, &player2, i);
else if (t == PT_FIGH)
{
if (parts[i].tmp2 >= 0 && parts[i].tmp2 < 100)
Element_STKM::STKM_init_legs(this, &fighters[parts[i].tmp2], i);
if (parts[i].tmp >= 0 && parts[i].tmp < MAX_FIGHTERS)
Element_STKM::STKM_init_legs(this, &fighters[parts[i].tmp], i);
}

parts[i].type = t;
Expand Down Expand Up @@ -3097,8 +3095,8 @@ int Simulation::create_part(int p, int x, int y, int tv)
case PT_FIGH:
{
unsigned char fcount = 0;
while (fcount < 100 && fcount < (fighcount+1) && fighters[fcount].spwn==1) fcount++;
if (fcount < 100 && fighters[fcount].spwn==0)
while (fcount < MAX_FIGHTERS && fcount < (fighcount+1) && fighters[fcount].spwn==1) fcount++;
if (fcount < MAX_FIGHTERS && fighters[fcount].spwn==0)
{
parts[i].life = 100;
parts[i].tmp = fcount;
Expand Down Expand Up @@ -4407,7 +4405,7 @@ void Simulation::update_particles_i(int start, int inc)
stickman = &player;
else if (t == PT_STKM2)
stickman = &player2;
else if (t == PT_FIGH && parts[i].tmp >= 0 && parts[i].tmp < 256)
else if (t == PT_FIGH && parts[i].tmp >= 0 && parts[i].tmp < MAX_FIGHTERS)
stickman = &fighters[parts[i].tmp];

if (stickman)
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/Simulation.h
Expand Up @@ -64,7 +64,7 @@ class Simulation
//Stickman
playerst player;
playerst player2;
playerst fighters[256]; //255 is the maximum number of fighters
playerst fighters[MAX_FIGHTERS]; //Defined in Stickman.h
unsigned char fighcount; //Contains the number of fighters
bool gravWallChanged;
//Portals and Wifi
Expand Down
1 change: 1 addition & 0 deletions src/simulation/Stickman.h
@@ -1,6 +1,7 @@
#ifndef STICKMAN_H_
#define STICKMAN_H_

#define MAX_FIGHTERS 100
struct playerst
{
char comm; //command cell
Expand Down
5 changes: 5 additions & 0 deletions src/simulation/elements/FIGH.cpp
Expand Up @@ -49,6 +49,11 @@ Element_FIGH::Element_FIGH()
//#TPT-Directive ElementHeader Element_FIGH static int update(UPDATE_FUNC_ARGS)
int Element_FIGH::update(UPDATE_FUNC_ARGS)
{
if (parts[i].tmp < 0 || parts[i].tmp >= MAX_FIGHTERS)
{
sim->kill_part(i);
return 1;
}
playerst* figh = &sim->fighters[(unsigned char)parts[i].tmp];

unsigned int tarx, tary;
Expand Down

0 comments on commit 6ce2d5f

Please sign in to comment.