Merge branch 'dev'

This commit is contained in:
Allanis 2014-04-15 21:09:14 +01:00
commit 930e8bc53c
6 changed files with 55 additions and 110 deletions

View File

@ -527,10 +527,10 @@ void ai_think(Pilot* pilot) {
cur_pilot->target = cur_pilot->id; cur_pilot->target = cur_pilot->id;
/* Control function if pilot is idle or tick is up. */ /* Control function if pilot is idle or tick is up. */
if((cur_pilot->tcontrol < SDL_GetTicks()) || (cur_pilot->task == NULL)) { if((cur_pilot->tcontrol < 0.) || (cur_pilot->task == NULL)) {
ai_run(L, "control"); /* Run control. */ ai_run(L, "control"); /* Run control. */
lua_getglobal(L, "control_rate"); lua_getglobal(L, "control_rate");
cur_pilot->tcontrol = SDL_GetTicks() + (int)(1000.*lua_tonumber(L, -1)); cur_pilot->tcontrol = lua_tonumber(L, -1);
} }
if(cur_pilot->task) if(cur_pilot->task)
/* Pilot has a currently running task. */ /* Pilot has a currently running task. */
@ -1492,8 +1492,8 @@ static int ai_settimer(lua_State* L) {
int n; /* Get the timer. */ int n; /* Get the timer. */
if(lua_isnumber(L, 1)) n = lua_tonumber(L,1); if(lua_isnumber(L, 1)) n = lua_tonumber(L,1);
cur_pilot->timer[n] = (lua_isnumber(L,2)) ? cur_pilot->timer[n] = (lua_isnumber(L,2)) ? lua_tonumber(L,2)/1000. : 0;
lua_tonumber(L,2) + SDL_GetTicks() : 0;
return 0; return 0;
} }
@ -1504,7 +1504,7 @@ static int ai_timeup(lua_State* L) {
int n; /* Get the timer. */ int n; /* Get the timer. */
if(lua_isnumber(L,1)) n = lua_tonumber(L,1); if(lua_isnumber(L,1)) n = lua_tonumber(L,1);
lua_pushboolean(L, cur_pilot->timer[n] < SDL_GetTicks()); lua_pushboolean(L, cur_pilot->timer[n] < 0.);
return 1; return 1;
} }

View File

@ -15,36 +15,25 @@
int paused = 0; /* Are we paused. */ int paused = 0; /* Are we paused. */
double dt_mod = 1.; /**< dt modifier. */ double dt_mod = 1.; /**< dt modifier. */
/* From pilot.c */
extern Pilot** pilot_stack;
extern int pilot_nstack;
/* From main.c */ /* From main.c */
extern unsigned int gtime; extern unsigned int time;
static void pilot_pause(void);
static void pilot_unpause(void);
static void pilot_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. */
pilot_pause();
paused = 1; /* We should unpause it. */ paused = 1; /* We should unpause it. */
} }
void unpause_game(void) { void unpause_game(void) {
if(!paused) return; /* We are unpaused already. */ if(!paused) return; /* We are unpaused already. */
pilot_unpause();
paused = 0; paused = 0;
} }
/* Set the timers back. */ /* Set the timers back. */
void pause_delay(unsigned int delay) { void pause_delay(unsigned int delay) {
pilot_delay(delay); (void)delay;
} }
/** /**
@ -54,41 +43,3 @@ void pause_setSpeed(double mod) {
dt_mod = mod; dt_mod = mod;
} }
/* Pilots pausing/unpausing. */
static void pilot_pause(void) {
int i, j;
unsigned int t = SDL_GetTicks();
for(i = 0; i < pilot_nstack; i++) {
pilot_stack[i]->ptimer -= t;
/* Pause timers. */
pilot_stack[i]->tcontrol -= t;
for(j = 0; j < MAX_AI_TIMERS; j++)
pilot_stack[i]->timer[j] -= t;
}
}
static void pilot_unpause(void) {
int i, j;
unsigned int t = SDL_GetTicks();
for(i = 0; i < pilot_nstack; i++) {
pilot_stack[i]->ptimer += t;
/* Rerun timers. */
pilot_stack[i]->tcontrol += t;
for(j = 0; j < MAX_AI_TIMERS; j++)
pilot_stack[i]->timer[j] += t;
}
}
static void pilot_delay(unsigned int delay) {
int i, j;
for(i = 0; i < pilot_nstack; i++) {
pilot_stack[i]->ptimer += delay;
pilot_stack[i]->tcontrol += delay;
for(j = 0; j < MAX_AI_TIMERS; j++)
pilot_stack[i]->timer[j] += delay;
}
}

View File

@ -481,11 +481,12 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
*/ */
void pilot_dead(Pilot* p) { void pilot_dead(Pilot* p) {
if(pilot_isFlag(p, PILOT_DEAD)) return; /* She's already dead. */ if(pilot_isFlag(p, PILOT_DEAD)) return; /* She's already dead. */
/* Basically just set the timers.. */ /* Basically just set the timers.. */
if(p->id == PLAYER_ID) player_dead(); if(p->id == PLAYER_ID) player_dead();
p->timer[0] = SDL_GetTicks(); /* No need for AI anymore. */ p->timer[0] = 0.; /* No need for AI anymore. */
p->ptimer = p->timer[0] + 1000 + (unsigned int)sqrt(10*p->armour_max*p->shield_max); p->ptimer = 1. + sqrt(10*p->armour_max * p->shield_max) / 1000.;
p->timer[1] = p->timer[0]; /* Explosion timer. */ p->timer[1] = 0.; /* Explosion timer. */
/* Flag cleanup - fixes some issues. */ /* Flag cleanup - fixes some issues. */
if(pilot_isFlag(p, PILOT_HYP_PREP)) pilot_rmFlag(p, PILOT_HYP_PREP); if(pilot_isFlag(p, PILOT_HYP_PREP)) pilot_rmFlag(p, PILOT_HYP_PREP);
@ -709,16 +710,25 @@ void pilot_render(Pilot* p) {
*/ */
static void pilot_update(Pilot* pilot, const double dt) { static void pilot_update(Pilot* pilot, const double dt) {
int i; int i;
unsigned int t, l; unsigned int l;
double a, px, py, vx, vy; double a, px, py, vx, vy;
char buf[16]; char buf[16];
PilotOutfit* o; PilotOutfit* o;
/* She's dead D: */ /* Update timers. */
if(pilot_isFlag(pilot, PILOT_DEAD)) { pilot->ptimer -= dt;
t = SDL_GetTicks(); pilot->tcontrol -= dt;
for(i = 0; i < MAX_AI_TIMERS; i++)
pilot->timer[i] -= dt;
for(i = 0; i < pilot->noutfits; i++) {
o = &pilot->outfits[i];
if(o->timer > 0.)
o->timer -= dt;
}
if(t > pilot->ptimer) { /* Completely destroyed with final explosion. */ /* She's dead. */
if(pilot_isFlag(pilot, PILOT_DEAD)) {
if(pilot->ptimer < 0.) { /* Completely destroyed with final explosion. */
if(pilot->id == PLAYER_ID) /* Player handled differently. */ if(pilot->id == PLAYER_ID) /* Player handled differently. */
player_destroyed(); player_destroyed();
pilot_setFlag(pilot, PILOT_DELETE); /* It'll get deleted next frame. */ pilot_setFlag(pilot, PILOT_DELETE); /* It'll get deleted next frame. */
@ -726,7 +736,7 @@ static void pilot_update(Pilot* pilot, const double dt) {
} }
/* Pilot death sound. */ /* Pilot death sound. */
if(!pilot_isFlag(pilot, PILOT_DEATH_SOUND) && (t > pilot->ptimer - 50)) { if(!pilot_isFlag(pilot, PILOT_DEATH_SOUND) && (pilot->ptimer < 0.050)) {
/* Play random explosion sound. */ /* Play random explosion sound. */
snprintf(buf, 16, "explosion%d", RNG(0,2)); snprintf(buf, 16, "explosion%d", RNG(0,2));
sound_playPos(sound_get(buf), pilot->solid->pos.x, pilot->solid->pos.y); sound_playPos(sound_get(buf), pilot->solid->pos.x, pilot->solid->pos.y);
@ -735,7 +745,7 @@ static void pilot_update(Pilot* pilot, const double dt) {
} }
/* Final explosion. */ /* Final explosion. */
else if(!pilot_isFlag(pilot, PILOT_EXPLODED) && (t > pilot->ptimer - 200)) { else if(!pilot_isFlag(pilot, PILOT_EXPLODED) && (pilot->ptimer < 0.200)) {
/* Damage from explosion. */ /* Damage from explosion. */
a = sqrt(pilot->solid->mass); a = sqrt(pilot->solid->mass);
expl_explode(pilot->solid->pos.x, pilot->solid->pos.y, expl_explode(pilot->solid->pos.x, pilot->solid->pos.y,
@ -751,10 +761,8 @@ static void pilot_update(Pilot* pilot, const double dt) {
pilot->commodities[i].quantity); pilot->commodities[i].quantity);
} }
/* Reset random explosion time. */ /* Reset random explosion time. */
else if(t > pilot->timer[1]) { else if(pilot->timer[1] < 0.) {
pilot->timer[1] = t + pilot->timer[1] = 0.08 * (pilot->ptimer - pilot->timer[1]) / pilot->ptimer;
(unsigned int)(100*(double)(pilot->ptimer - pilot->timer[1]) /
(double)(pilot->ptimer - pilot->timer[0]));
/* Random position on ship. */ /* Random position on ship. */
a = RNGF()*2.*M_PI; a = RNGF()*2.*M_PI;
@ -832,13 +840,6 @@ static void pilot_update(Pilot* pilot, const double dt) {
} else /* Normal limit. */ } else /* Normal limit. */
limit_speed(&pilot->solid->vel, pilot->speed, dt); limit_speed(&pilot->solid->vel, pilot->speed, dt);
} }
/* Update outfits. */
for(i = 0; i < pilot->noutfits; i++) {
o = &pilot->outfits[i];
if(o->timer > 0.)
o->timer -= dt;
}
} }
/* Pilot is getting ready or is in, hyperspace. */ /* Pilot is getting ready or is in, hyperspace. */
@ -849,7 +850,7 @@ static void pilot_hyperspace(Pilot* p) {
if(pilot_isFlag(p, PILOT_HYPERSPACE)) { if(pilot_isFlag(p, PILOT_HYPERSPACE)) {
/* Has the jump happened? */ /* Has the jump happened? */
if(SDL_GetTicks() > p->ptimer) { if(p->ptimer < 0.) {
if(p == player) { if(p == player) {
player_brokeHyperspace(); player_brokeHyperspace();
} else { } else {
@ -863,9 +864,8 @@ static void pilot_hyperspace(Pilot* p) {
} }
/* Engines getting ready for the jump. */ /* Engines getting ready for the jump. */
else if(pilot_isFlag(p, PILOT_HYP_BEGIN)) { else if(pilot_isFlag(p, PILOT_HYP_BEGIN)) {
if(SDL_GetTicks() > p->ptimer) { if(p->ptimer < 0.) { /* Engines ready. */
/* Engines are ready. */ p->ptimer = HYPERSPACE_FLY_DELAY;
p->ptimer = SDL_GetTicks() + HYPERSPACE_FLY_DELAY;
pilot_setFlag(p, PILOT_HYPERSPACE); pilot_setFlag(p, PILOT_HYPERSPACE);
} }
} else { } else {
@ -888,7 +888,7 @@ static void pilot_hyperspace(Pilot* p) {
if(ABS(diff) < MAX_DIR_ERR) { if(ABS(diff) < MAX_DIR_ERR) {
/* We should prepare for the jump now. */ /* We should prepare for the jump now. */
p->solid->dir_vel = 0.; p->solid->dir_vel = 0.;
p->ptimer = SDL_GetTicks() + HYPERSPACE_ENGINE_DELAY; p->ptimer = HYPERSPACE_ENGINE_DELAY;
pilot_setFlag(p, PILOT_HYP_BEGIN); pilot_setFlag(p, PILOT_HYP_BEGIN);
} }
} }

View File

@ -7,17 +7,17 @@
#include "sound.h" #include "sound.h"
#include "economy.h" #include "economy.h"
#define PLAYER_ID 1 /**< Player pilot ID. */ #define PLAYER_ID 1 /**< Player pilot ID. */
/* Hyperspace parameters. */ /* Hyperspace parameters. */
#define HYPERSPACE_ENGINE_DELAY 3000 /**< Warm up the engines. */ #define HYPERSPACE_ENGINE_DELAY 3. /**< Warm up the engines. */
#define HYPERSPACE_FLY_DELAY 5000 /**< Time taken to hyperspace. */ #define HYPERSPACE_FLY_DELAY 5. /**< Time taken to hyperspace. */
#define HYPERSPACE_STARS_BLUR 2000 /**< Time stars blur. */ #define HYPERSPACE_STARS_BLUR 2. /**< Time stars blur. */
#define HYPERSPACE_STARS_LENGTH 1000 /**< Length the stars blur to at max. */ #define HYPERSPACE_STARS_LENGTH 1000 /**< Length the stars blur to at max. */
#define HYPERSPACE_FADEOUT 1000 /**< Time fadeout. */ #define HYPERSPACE_FADEOUT 1. /**< Time fadeout. */
#define HYPERSPACE_FUEL 100 /**< Amount of fuel taken. */ #define HYPERSPACE_FUEL 100 /**< Amount of fuel taken. */
#define HYPERSPACE_THRUST 2000. /**< How much thrust you use in hyperspace. */ #define HYPERSPACE_THRUST 2000. /**< How much thrust you use in hyperspace. */
#define HYPERSPACE_VEL HYPERSPACE_THRUST*(HYPERSPACE_FLY_DELAY/1000) /**< Vel at hyp.*/ #define HYPERSPACE_VEL HYPERSPACE_THRUST*HYPERSPACE_FLY_DELAY /**< Vel at hyp.*/
#define HYPERSPACE_ENTER_MIN HYPERSPACE_VEL*0.5 /**< Min entering distance. */ #define HYPERSPACE_ENTER_MIN HYPERSPACE_VEL*0.5 /**< Min entering distance. */
#define HYPERSPACE_ENTER_MAX HYPERSPACE_VEL*0.6 /**< Max entering distance. */ #define HYPERSPACE_ENTER_MAX HYPERSPACE_VEL*0.6 /**< Max entering distance. */
#define HYPERSPACE_EXIT_MIN 1500. /**< Min distance to begin jumping. */ #define HYPERSPACE_EXIT_MIN 1500. /**< Min distance to begin jumping. */
@ -165,7 +165,7 @@ typedef struct Pilot_ {
/* Misc. */ /* Misc. */
uint32_t flags; /**< Used for AI etc. */ uint32_t flags; /**< Used for AI etc. */
unsigned int ptimer; /**< Generic timer for internal pilot use. */ double ptimer; /**< Generic timer for internal pilot use. */
int lockons; /**< Stores how many seeking weapons are targetting pilot. */ int lockons; /**< Stores how many seeking weapons are targetting pilot. */
/* Hook attached to the pilot. */ /* Hook attached to the pilot. */
@ -174,15 +174,15 @@ typedef struct Pilot_ {
/* Escort stuff. */ /* Escort stuff. */
unsigned int parent; /**< Pilots parent. */ unsigned int parent; /**< Pilots parent. */
unsigned int* escorts; /**< Pilots escorts. */ unsigned int* escorts; /**< Pilots escorts. */
int nescorts; /**< Number of pilot escorts. */ int nescorts; /**< Number of pilot escorts. */
/* AI. */ /* AI. */
unsigned int target; /**< AI target. */ unsigned int target; /**< AI target. */
AI_Profile* ai; /**< Ai personality profile. */ AI_Profile* ai; /**< Ai personality profile. */
unsigned int tcontrol; /**< Timer for control tick. */ double tcontrol; /**< Timer for control tick. */
unsigned int timer[MAX_AI_TIMERS]; /**< Timers for AI. */ double timer[MAX_AI_TIMERS]; /**< Timers for AI. */
Task* task; /**< Current action. */ Task* task; /**< Current action. */
} Pilot; } Pilot;
/** /**

View File

@ -1181,12 +1181,10 @@ void player_renderGUI(double dt) {
} }
} }
/* Hyperspace FLASH BANG!!! */ /* Hyperspace FLASH BANG!!! */
if(pilot_isFlag(player, PILOT_HYPERSPACE)) { if(pilot_isFlag(player, PILOT_HYPERSPACE) &&
i = (int)player->ptimer - HYPERSPACE_FADEOUT; (player->ptimer < HYPERSPACE_FADEOUT)) {
if(paused) i += t;
j = (int) t;
if(i < j) { if(i < j) {
x = (double)(j-i) / HYPERSPACE_FADEOUT; x = (HYPERSPACE_FADEOUT-player->ptimer) / HYPERSPACE_FADEOUT;
glColor4d(1.,1.,1., x); /* We'll | I'll, make this more effiecent later. */ glColor4d(1.,1.,1., x); /* We'll | I'll, make this more effiecent later. */
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2d(-SCREEN_W/2., -SCREEN_H/2.); glVertex2d(-SCREEN_W/2., -SCREEN_H/2.);

View File

@ -1211,21 +1211,15 @@ void space_renderOverlay(const double dt) {
/* Render stars. */ /* Render stars. */
static void space_renderStars(const double dt) { static void space_renderStars(const double dt) {
int i; int i;
unsigned int t, timer;
double x, y, m, b; double x, y, m, b;
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); /* Translation matrix. */ glPushMatrix(); /* Translation matrix. */
glTranslated(-(double)SCREEN_W/2., -(double)SCREEN_H/2., 0); glTranslated(-(double)SCREEN_W/2., -(double)SCREEN_H/2., 0);
t = SDL_GetTicks();
if(!player_isFlag(PLAYER_DESTROYED) && !player_isFlag(PLAYER_CREATING) && if(!player_isFlag(PLAYER_DESTROYED) && !player_isFlag(PLAYER_CREATING) &&
pilot_isFlag(player, PILOT_HYPERSPACE) && /* Hyperspace fancy effect. */ pilot_isFlag(player, PILOT_HYPERSPACE) && /* Hyperspace fancy effect. */
((!paused && (player->ptimer - HYPERSPACE_STARS_BLUR < t)) || (player->ptimer < HYPERSPACE_STARS_BLUR)) {
(paused && (player->ptimer < HYPERSPACE_STARS_BLUR)))) {
timer = player->ptimer - HYPERSPACE_STARS_BLUR;
if(paused) timer += t;
/* Fancy hyperspace effects. */ /* Fancy hyperspace effects. */
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
@ -1237,9 +1231,11 @@ static void space_renderStars(const double dt) {
glBegin(GL_LINES); glBegin(GL_LINES);
/* Lines will be based on velocity. */ /* Lines will be based on velocity. */
m = HYPERSPACE_STARS_LENGTH * (double)(t-timer) / (HYPERSPACE_STARS_BLUR); m = HYPERSPACE_STARS_BLUR-player->ptimer;
x = m*cos(VANGLE(player->solid->vel)+M_PI); m /= HYPERSPACE_STARS_BLUR;
y = m*sin(VANGLE(player->solid->vel)+M_PI); m *= HYPERSPACE_STARS_LENGTH;
x = m*cos(VANGLE(player->solid->vel)+M_PI);
y = m*sin(VANGLE(player->solid->vel)+M_PI);
for(i = 0; i < nstars; i++) { for(i = 0; i < nstars; i++) {
glColor4d(1., 1., 1., stars[i].brightness); glColor4d(1., 1., 1., stars[i].brightness);