[Change] Player no longer "hardcoded" into pilot_stack[0].
This commit is contained in:
parent
715fecfa03
commit
698b22a324
56
src/pilot.c
56
src/pilot.c
@ -950,30 +950,17 @@ unsigned int pilot_create(Ship* ship, char* name, int faction,
|
|||||||
}
|
}
|
||||||
pilot_init(dyn, ship, name, faction, ai, dir, pos, vel, flags);
|
pilot_init(dyn, ship, name, faction, ai, dir, pos, vel, flags);
|
||||||
|
|
||||||
if(flags & PILOT_PLAYER) {
|
/* See if memory needs to grow. */
|
||||||
/* Player. */
|
if(pilot_nstack+1 > pilot_mstack) { /* Needs to grow. */
|
||||||
if(!pilot_stack) {
|
pilot_mstack += PILOT_CHUNK;
|
||||||
pilot_stack = MALLOC_L(Pilot*);
|
tp = pilot_stack;
|
||||||
pilot_nstack = 1;
|
pilot_stack = realloc(pilot_stack, pilot_mstack*sizeof(Pilot*));
|
||||||
pilot_mstack = 1;
|
|
||||||
}
|
|
||||||
pilot_stack[0] = dyn;
|
|
||||||
} else {
|
|
||||||
/* Add to the stack. */
|
|
||||||
pilot_nstack++; /* There is a new pilot. */
|
|
||||||
|
|
||||||
if(pilot_nstack >= pilot_mstack) {
|
|
||||||
/* Need to grow. About 20 at a time. */
|
|
||||||
pilot_mstack += PILOT_CHUNK;
|
|
||||||
tp = pilot_stack;
|
|
||||||
pilot_stack = realloc(pilot_stack, pilot_mstack*sizeof(Pilot*));
|
|
||||||
if((pilot_stack != tp) && player)
|
|
||||||
/* Take into account possible mem move. */
|
|
||||||
player = pilot_stack[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
pilot_stack[pilot_nstack-1] = dyn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set the pilot in the stack. */
|
||||||
|
pilot_stack[pilot_nstack] = dyn;
|
||||||
|
pilot_nstack++; /* There's a new pilot. */
|
||||||
|
|
||||||
return dyn->id;
|
return dyn->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1049,20 +1036,26 @@ void pilot_destroy(Pilot* p) {
|
|||||||
/* Free the prisoned pilot! */
|
/* Free the prisoned pilot! */
|
||||||
void pilots_free(void) {
|
void pilots_free(void) {
|
||||||
int i;
|
int i;
|
||||||
if(player) pilot_free(player);
|
for(i = 0; i < pilot_nstack; i++)
|
||||||
for(i = 1; i < pilot_nstack; i++)
|
|
||||||
pilot_free(pilot_stack[i]);
|
pilot_free(pilot_stack[i]);
|
||||||
free(pilot_stack);
|
free(pilot_stack);
|
||||||
pilot_stack = NULL;
|
pilot_stack = NULL;
|
||||||
|
player = NULL;
|
||||||
pilot_nstack = 0;
|
pilot_nstack = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up the pilots - Leaves the player. */
|
/* Clean up the pilots - Leaves the player. */
|
||||||
void pilots_clean(void) {
|
void pilots_clean(void) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 1; i < pilot_nstack; i++)
|
for(i = 0; i < pilot_nstack; i++)
|
||||||
pilot_free(pilot_stack[i]);
|
/* We'll set player at priveleged position. */
|
||||||
pilot_nstack = 1;
|
if((player != NULL) && (pilot_stack[i] == player))
|
||||||
|
pilot_stack[0] = player;
|
||||||
|
else /* Rest get killed. */
|
||||||
|
pilot_free(pilot_stack[i]);
|
||||||
|
|
||||||
|
if(player != NULL) /* Set stack to 1 if pilot exists. */
|
||||||
|
pilot_nstack = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pilots_cleanAll(void) {
|
void pilots_cleanAll(void) {
|
||||||
@ -1097,10 +1090,11 @@ void pilots_update(double dt) {
|
|||||||
/* Render all the pilots. */
|
/* Render all the pilots. */
|
||||||
void pilots_render(void) {
|
void pilots_render(void) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 1; i < pilot_nstack; i++)
|
for(i = 0; i < pilot_nstack; i++) {
|
||||||
/* Skip the player. */
|
if(player == pilot_stack[i]) continue; /* Skip the player. */
|
||||||
if(pilot_stack[i]->render != NULL)
|
if(pilot_stack[i]->render != NULL) /* Render. */
|
||||||
pilot_stack[i]->render(pilot_stack[i]);
|
pilot_stack[i]->render(pilot_stack[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the fleet node. */
|
/* Parse the fleet node. */
|
||||||
|
@ -373,7 +373,11 @@ void player_swapShip(char* shipname) {
|
|||||||
|
|
||||||
/* Now swap the players. */
|
/* Now swap the players. */
|
||||||
player_stack[i] = player;
|
player_stack[i] = player;
|
||||||
pilot_stack[0] = player = ship;
|
for(j = 0; j < pilot_nstack; j++) /* Find pilot in stack to swap. */
|
||||||
|
if(pilot_stack[j] == player) {
|
||||||
|
pilot_stack[j] = player = ship;
|
||||||
|
break;
|
||||||
|
}
|
||||||
gl_bindCamera(&player->solid->pos); /* Let's not forget the camera. */
|
gl_bindCamera(&player->solid->pos); /* Let's not forget the camera. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user