[Change] Renamed pilots and mpilots to pilot_nstack and pilot_mstack.
This commit is contained in:
parent
c20fe36c27
commit
19e3e818a4
4
src/ai.c
4
src/ai.c
@ -71,7 +71,7 @@ static int nprofiles = 0;
|
|||||||
|
|
||||||
/* Extern pilot hacks. */
|
/* Extern pilot hacks. */
|
||||||
extern Pilot** pilot_stack;
|
extern Pilot** pilot_stack;
|
||||||
extern int pilots;
|
extern int pilot_nstack;
|
||||||
|
|
||||||
static int ai_minbrakedist(lua_State* L); /* Minimal breaking distance. */
|
static int ai_minbrakedist(lua_State* L); /* Minimal breaking distance. */
|
||||||
static int ai_accel(lua_State* L); /* Accelerate. */
|
static int ai_accel(lua_State* L); /* Accelerate. */
|
||||||
@ -477,7 +477,7 @@ static int ai_gettargetid(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int ai_getrndpilot(lua_State* L) {
|
static int ai_getrndpilot(lua_State* L) {
|
||||||
lua_pushnumber(L, pilot_stack[RNG(0, pilots-1)]->id);
|
lua_pushnumber(L, pilot_stack[RNG(0, pilot_nstack-1)]->id);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
src/pause.c
27
src/pause.c
@ -10,21 +10,21 @@ int paused = 0; /* Are we paused. */
|
|||||||
|
|
||||||
/* From pilot.c */
|
/* From pilot.c */
|
||||||
extern Pilot** pilot_stack;
|
extern Pilot** pilot_stack;
|
||||||
extern int pilots;
|
extern int pilot_nstack;
|
||||||
/* From space.c */
|
/* From space.c */
|
||||||
extern unsigned int spawn_timer;
|
extern unsigned int spawn_timer;
|
||||||
/* From main.c */
|
/* From main.c */
|
||||||
extern unsigned int gtime;
|
extern unsigned int gtime;
|
||||||
|
|
||||||
static void pilots_pause(void);
|
static void pilot_nstack_pause(void);
|
||||||
static void pilots_unpause(void);
|
static void pilot_nstack_unpause(void);
|
||||||
static void pilots_delay(unsigned int delay);
|
static void pilot_nstack_delay(unsigned int delay);
|
||||||
|
|
||||||
/* Pause the game. */
|
/* Pause the game. */
|
||||||
void pause_game(void) {
|
void pause_game(void) {
|
||||||
if(paused) return; /* Well well.. We are paused already. */
|
if(paused) return; /* Well well.. We are paused already. */
|
||||||
|
|
||||||
pilots_pause();
|
pilot_nstack_pause();
|
||||||
weapons_pause();
|
weapons_pause();
|
||||||
spfx_pause();
|
spfx_pause();
|
||||||
spawn_timer -= SDL_GetTicks();
|
spawn_timer -= SDL_GetTicks();
|
||||||
@ -35,7 +35,7 @@ void pause_game(void) {
|
|||||||
void unpause_game(void) {
|
void unpause_game(void) {
|
||||||
if(!paused) return; /* We are unpaused already. */
|
if(!paused) return; /* We are unpaused already. */
|
||||||
|
|
||||||
pilots_unpause();
|
pilot_nstack_unpause();
|
||||||
weapons_unpause();
|
weapons_unpause();
|
||||||
spfx_unpause();
|
spfx_unpause();
|
||||||
spawn_timer += SDL_GetTicks();
|
spawn_timer += SDL_GetTicks();
|
||||||
@ -45,15 +45,16 @@ void unpause_game(void) {
|
|||||||
|
|
||||||
/* Set the timers back. */
|
/* Set the timers back. */
|
||||||
void pause_delay(unsigned int delay) {
|
void pause_delay(unsigned int delay) {
|
||||||
pilots_delay(delay);
|
pilot_nstack_delay(delay);
|
||||||
weapons_delay(delay);
|
weapons_delay(delay);
|
||||||
spfx_delay(delay);
|
spfx_delay(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pilots_pause(void) {
|
/* Pilots pausing/unpausing. */
|
||||||
|
static void pilot_nstack_pause(void) {
|
||||||
int i, j;
|
int i, j;
|
||||||
unsigned int t = SDL_GetTicks();
|
unsigned int t = SDL_GetTicks();
|
||||||
for(i = 0; i < pilots; i++) {
|
for(i = 0; i < pilot_nstack; i++) {
|
||||||
pilot_stack[i]->ptimer -= t;
|
pilot_stack[i]->ptimer -= t;
|
||||||
|
|
||||||
pilot_stack[i]->tcontrol -= t;
|
pilot_stack[i]->tcontrol -= t;
|
||||||
@ -62,10 +63,10 @@ static void pilots_pause(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pilots_unpause(void) {
|
static void pilot_nstack_unpause(void) {
|
||||||
int i, j;
|
int i, j;
|
||||||
unsigned int t = SDL_GetTicks();
|
unsigned int t = SDL_GetTicks();
|
||||||
for(i = 0; i < pilots; i++) {
|
for(i = 0; i < pilot_nstack; i++) {
|
||||||
pilot_stack[i]->ptimer += t;
|
pilot_stack[i]->ptimer += t;
|
||||||
|
|
||||||
pilot_stack[i]->tcontrol += t;
|
pilot_stack[i]->tcontrol += t;
|
||||||
@ -74,9 +75,9 @@ static void pilots_unpause(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pilots_delay(unsigned int delay) {
|
static void pilot_nstack_delay(unsigned int delay) {
|
||||||
int i, j;
|
int i, j;
|
||||||
for(i = 0; i < pilots; i++) {
|
for(i = 0; i < pilot_nstack; i++) {
|
||||||
pilot_stack[i]->ptimer += delay;
|
pilot_stack[i]->ptimer += delay;
|
||||||
|
|
||||||
pilot_stack[i]->tcontrol += delay;
|
pilot_stack[i]->tcontrol += delay;
|
||||||
|
52
src/pilot.c
52
src/pilot.c
@ -26,10 +26,10 @@ static unsigned int pilot_id = PLAYER_ID;
|
|||||||
/* id for special mission cargo. */
|
/* id for special mission cargo. */
|
||||||
static unsigned int mission_cargo_id = 0;
|
static unsigned int mission_cargo_id = 0;
|
||||||
|
|
||||||
/* Stack of pilots - yes, they come in stacks now. */
|
/* Stack of pilots. */
|
||||||
Pilot** pilot_stack = NULL; /* Not static, it is used in player.c and weapon.c and ai.c */
|
Pilot** pilot_stack = NULL; /* Not static, it is used in player.c and weapon.c and ai.c */
|
||||||
int pilots = 0;
|
int pilot_nstack = 0;
|
||||||
static int mpilots = 0;
|
static int pilot_mstack = 0;
|
||||||
|
|
||||||
extern Pilot* player;
|
extern Pilot* player;
|
||||||
extern unsigned int player_crating;
|
extern unsigned int player_crating;
|
||||||
@ -66,15 +66,15 @@ unsigned int pilot_getNext(const unsigned int id) {
|
|||||||
/* Binary search. */
|
/* Binary search. */
|
||||||
int l, m, h;
|
int l, m, h;
|
||||||
l = 0;
|
l = 0;
|
||||||
h = pilots-1;
|
h = pilot_nstack-1;
|
||||||
while(l <= h) {
|
while(l <= h) {
|
||||||
m = (l+h)/2;
|
m = l+(h-l)/2; /* For impossible overflow returning negative value. */
|
||||||
if(pilot_stack[m]->id > id) h = m-1;
|
if(pilot_stack[m]->id > id) h = m-1;
|
||||||
else if(pilot_stack[m]->id < id) l = m+1;
|
else if(pilot_stack[m]->id < id) l = m+1;
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m == (pilots-1)) return PLAYER_ID;
|
if(m == (pilot_nstack-1)) return PLAYER_ID;
|
||||||
else return pilot_stack[m+1]->id;
|
else return pilot_stack[m+1]->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ unsigned int pilot_getNearest(const Pilot* p) {
|
|||||||
int i;
|
int i;
|
||||||
double d, td;
|
double d, td;
|
||||||
|
|
||||||
for(tp = 0, d = 0., i = 0; i < pilots; i++)
|
for(tp = 0, d = 0., i = 0; i < pilot_nstack; i++)
|
||||||
if(areEnemies(p->faction, pilot_stack[i]->faction)) {
|
if(areEnemies(p->faction, pilot_stack[i]->faction)) {
|
||||||
td = vect_dist(&pilot_stack[i]->solid->pos, &p->solid->pos);
|
td = vect_dist(&pilot_stack[i]->solid->pos, &p->solid->pos);
|
||||||
if(!pilot_isDisabled(pilot_stack[i]) && ((!tp) || (td < d))) {
|
if(!pilot_isDisabled(pilot_stack[i]) && ((!tp) || (td < d))) {
|
||||||
@ -100,7 +100,7 @@ unsigned pilot_getHostile(void) {
|
|||||||
unsigned int tp;
|
unsigned int tp;
|
||||||
int i;
|
int i;
|
||||||
double d, td;
|
double d, td;
|
||||||
for(tp = PLAYER_ID, d = 0., i = 0; i < pilots; i++)
|
for(tp = PLAYER_ID, d = 0., i = 0; i < pilot_nstack; i++)
|
||||||
if(pilot_isFlag(pilot_stack[i], PILOT_HOSTILE)) {
|
if(pilot_isFlag(pilot_stack[i], PILOT_HOSTILE)) {
|
||||||
td = vect_dist(&pilot_stack[i]->solid->pos, &player->solid->pos);
|
td = vect_dist(&pilot_stack[i]->solid->pos, &player->solid->pos);
|
||||||
if(!pilot_isDisabled(pilot_stack[i]) && ((tp == PLAYER_ID) || (td < d))) {
|
if(!pilot_isDisabled(pilot_stack[i]) && ((tp == PLAYER_ID) || (td < d))) {
|
||||||
@ -118,7 +118,7 @@ Pilot* pilot_get(const unsigned int id) {
|
|||||||
/* Binary search. */
|
/* Binary search. */
|
||||||
int l, m, h;
|
int l, m, h;
|
||||||
l = 0;
|
l = 0;
|
||||||
h = pilots-1;
|
h = pilot_nstack-1;
|
||||||
while(l <= h) {
|
while(l <= h) {
|
||||||
m = (l+h)/2;
|
m = (l+h)/2;
|
||||||
if(pilot_stack[m]->id > id) h = m-1;
|
if(pilot_stack[m]->id > id) h = m-1;
|
||||||
@ -954,25 +954,25 @@ unsigned int pilot_create(Ship* ship, char* name, int faction,
|
|||||||
/* Player. */
|
/* Player. */
|
||||||
if(!pilot_stack) {
|
if(!pilot_stack) {
|
||||||
pilot_stack = MALLOC_L(Pilot*);
|
pilot_stack = MALLOC_L(Pilot*);
|
||||||
pilots = 1;
|
pilot_nstack = 1;
|
||||||
mpilots = 1;
|
pilot_mstack = 1;
|
||||||
}
|
}
|
||||||
pilot_stack[0] = dyn;
|
pilot_stack[0] = dyn;
|
||||||
} else {
|
} else {
|
||||||
/* Add to the stack. */
|
/* Add to the stack. */
|
||||||
pilots++; /* There is a new pilot. */
|
pilot_nstack++; /* There is a new pilot. */
|
||||||
|
|
||||||
if(pilots >= mpilots) {
|
if(pilot_nstack >= pilot_mstack) {
|
||||||
/* Need to grow. About 20 at a time. */
|
/* Need to grow. About 20 at a time. */
|
||||||
mpilots += PILOT_CHUNK;
|
pilot_mstack += PILOT_CHUNK;
|
||||||
tp = pilot_stack;
|
tp = pilot_stack;
|
||||||
pilot_stack = realloc(pilot_stack, mpilots*sizeof(Pilot*));
|
pilot_stack = realloc(pilot_stack, pilot_mstack*sizeof(Pilot*));
|
||||||
if((pilot_stack != tp) && player)
|
if((pilot_stack != tp) && player)
|
||||||
/* Take into account possible mem move. */
|
/* Take into account possible mem move. */
|
||||||
player = pilot_stack[0];
|
player = pilot_stack[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
pilot_stack[pilots-1] = dyn;
|
pilot_stack[pilot_nstack-1] = dyn;
|
||||||
}
|
}
|
||||||
return dyn->id;
|
return dyn->id;
|
||||||
}
|
}
|
||||||
@ -1032,13 +1032,13 @@ void pilot_free(Pilot* p) {
|
|||||||
/* Destroy pilot from stack. */
|
/* Destroy pilot from stack. */
|
||||||
void pilot_destroy(Pilot* p) {
|
void pilot_destroy(Pilot* p) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < pilots; i++)
|
for(i = 0; i < pilot_nstack; i++)
|
||||||
if(pilot_stack[i] == p)
|
if(pilot_stack[i] == p)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pilots--;
|
pilot_nstack--;
|
||||||
|
|
||||||
while(i < pilots) {
|
while(i < pilot_nstack) {
|
||||||
pilot_stack[i] = pilot_stack[i+1];
|
pilot_stack[i] = pilot_stack[i+1];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -1049,19 +1049,19 @@ void pilot_destroy(Pilot* p) {
|
|||||||
void pilots_free(void) {
|
void pilots_free(void) {
|
||||||
int i;
|
int i;
|
||||||
if(player) pilot_free(player);
|
if(player) pilot_free(player);
|
||||||
for(i = 1; i < pilots; 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;
|
||||||
pilots = 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 < pilots; i++)
|
for(i = 1; i < pilot_nstack; i++)
|
||||||
pilot_free(pilot_stack[i]);
|
pilot_free(pilot_stack[i]);
|
||||||
pilots = 1;
|
pilot_nstack = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pilots_cleanAll(void) {
|
void pilots_cleanAll(void) {
|
||||||
@ -1070,13 +1070,13 @@ void pilots_cleanAll(void) {
|
|||||||
pilot_free(player);
|
pilot_free(player);
|
||||||
player = NULL;
|
player = NULL;
|
||||||
}
|
}
|
||||||
pilots = 0;
|
pilot_nstack = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update all pilots. */
|
/* Update all pilots. */
|
||||||
void pilots_update(double dt) {
|
void pilots_update(double dt) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < pilots; i++) {
|
for(i = 0; i < pilot_nstack; i++) {
|
||||||
if(pilot_stack[i]->think && !pilot_isDisabled(pilot_stack[i])) {
|
if(pilot_stack[i]->think && !pilot_isDisabled(pilot_stack[i])) {
|
||||||
/* Hyperspace gets special treatment. */
|
/* Hyperspace gets special treatment. */
|
||||||
if(pilot_isFlag(pilot_stack[i], PILOT_HYP_PREP))
|
if(pilot_isFlag(pilot_stack[i], PILOT_HYP_PREP))
|
||||||
@ -1096,7 +1096,7 @@ 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 < pilots; i++)
|
for(i = 1; i < pilot_nstack; i++)
|
||||||
/* Skip the player. */
|
/* Skip the player. */
|
||||||
if(pilot_stack[i]->render)
|
if(pilot_stack[i]->render)
|
||||||
pilot_stack[i]->render(pilot_stack[i]);
|
pilot_stack[i]->render(pilot_stack[i]);
|
||||||
|
@ -73,7 +73,7 @@ static int missions_ndone = 0;
|
|||||||
|
|
||||||
/* Pilot stuff for GUI. */
|
/* Pilot stuff for GUI. */
|
||||||
extern Pilot** pilot_stack;
|
extern Pilot** pilot_stack;
|
||||||
extern int pilots;
|
extern int pilot_nstack;
|
||||||
|
|
||||||
/* Space stuff for GUI. */
|
/* Space stuff for GUI. */
|
||||||
extern StarSystem* systems_stack;
|
extern StarSystem* systems_stack;
|
||||||
@ -641,7 +641,7 @@ void player_render(void) {
|
|||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
/* Render the pilots. */
|
/* Render the pilots. */
|
||||||
for(j = 0, i = 1; i < pilots; i++) {
|
for(j = 0, i = 1; i < pilot_nstack; i++) {
|
||||||
/* Skip the player. */
|
/* Skip the player. */
|
||||||
if(pilot_stack[i]->id == player_target) j = i;
|
if(pilot_stack[i]->id == player_target) j = i;
|
||||||
else gui_renderPilot(pilot_stack[i]);
|
else gui_renderPilot(pilot_stack[i]);
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/* Some stuff from pilot. */
|
/* Some stuff from pilot. */
|
||||||
extern Pilot** pilot_stack;
|
extern Pilot** pilot_stack;
|
||||||
extern int pilots;
|
extern int pilot_nstack;
|
||||||
|
|
||||||
/* Player stuff. */
|
/* Player stuff. */
|
||||||
extern unsigned int player_target;
|
extern unsigned int player_target;
|
||||||
@ -291,7 +291,7 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
|
|||||||
|
|
||||||
gl_getSpriteFromDir(&wsx, &wsy, gfx, w->solid->dir);
|
gl_getSpriteFromDir(&wsx, &wsy, gfx, w->solid->dir);
|
||||||
|
|
||||||
for(i = 0; i < pilots; i++) {
|
for(i = 0; i < pilot_nstack; i++) {
|
||||||
psx = pilot_stack[i]->tsx;
|
psx = pilot_stack[i]->tsx;
|
||||||
psy = pilot_stack[i]->tsy;
|
psy = pilot_stack[i]->tsy;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user