[Change] Useing memset for pilot initialization. Also making a start on auto navigation stuff.

This commit is contained in:
Allanis 2013-12-14 00:45:01 +00:00
parent 72781329cb
commit f26cf7e4e1
3 changed files with 30 additions and 25 deletions

View File

@ -1191,9 +1191,11 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
AI_Profile* ai, const double dir, const Vec2* pos, AI_Profile* ai, const double dir, const Vec2* pos,
const Vec2* vel, const int flags) { const Vec2* vel, const int flags) {
int i;
ShipOutfit* so; ShipOutfit* so;
/* Clear memory. */
memset(pilot, 0, sizeof(Pilot));
if(flags & PILOT_PLAYER) /* Player is ID 0 */ if(flags & PILOT_PLAYER) /* Player is ID 0 */
pilot->id = PLAYER_ID; pilot->id = PLAYER_ID;
else else
@ -1207,22 +1209,11 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
/* AI. */ /* AI. */
pilot->ai = ai; pilot->ai = ai;
pilot->tcontrol = 0;
pilot->flags = 0;
pilot->lockons = 0;
/* Solid. */ /* Solid. */
pilot->solid = solid_create(ship->mass, dir, pos, vel); pilot->solid = solid_create(ship->mass, dir, pos, vel);
/* Initially idle. */
pilot->task = NULL;
/* Outfits. */ /* Outfits. */
pilot->outfits = NULL;
pilot->secondary = NULL;
pilot->ammo = NULL;
pilot->afterburner = NULL;
pilot->noutfits = 0;
if(!(flags & PILOT_NO_OUTFITS)) { if(!(flags & PILOT_NO_OUTFITS)) {
if(ship->outfit) { if(ship->outfit) {
pilot->noutfits = 0; pilot->noutfits = 0;
@ -1238,14 +1229,7 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
} }
} }
/* Jamming - must be set before calcStats. */
pilot->jam_range = 0.;
pilot->jam_chance = 0.;
/* Cargo must be set before calcStats. */ /* Cargo must be set before calcStats. */
pilot->credits = 0;
pilot->commodities = NULL;
pilot->ncommodities = 0;
pilot->cargo_free = pilot->ship->cap_cargo; /* should get redone with calcCargo. */ pilot->cargo_free = pilot->ship->cap_cargo; /* should get redone with calcCargo. */
/* Set the pilot stats based on her ship and outfits. */ /* Set the pilot stats based on her ship and outfits. */
@ -1256,12 +1240,6 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
pilot->fuel = pilot->fuel_max = 1.; pilot->fuel = pilot->fuel_max = 1.;
pilot_calcStats(pilot); pilot_calcStats(pilot);
/* Hooks. */
for(i = 0; i < PILOT_HOOKS; i++) {
pilot->hook_type[i] = PILOT_HOOK_NONE;
pilot->hook[i] = 0;
}
/* Set flags and functions. */ /* Set flags and functions. */
if(flags & PILOT_PLAYER) { if(flags & PILOT_PLAYER) {
pilot->think = player_think; /* Players don't need to thing! :P */ pilot->think = player_think; /* Players don't need to thing! :P */

View File

@ -1466,6 +1466,23 @@ void gui_free(void) {
free(msg_stack); free(msg_stack);
} }
void player_startAutonav(void) {
player_message("Autonav continuing.");
player_setFlag(PLAYER_AUTONAV);
}
/**
* @fn void player_abortAutonav(void)
*
* @brief Aborts autonav
*/
void player_abortAutonav(void) {
if(player_isFlag(PLAYER_AUTONAV)) {
player_message("Autonav aborted!");
player_rmFlag(PLAYER_AUTONAV);
}
}
/** /**
* @fn void player_think(Pilot* pplayer) * @fn void player_think(Pilot* pplayer)
* *
@ -1481,6 +1498,15 @@ void player_think(Pilot* pplayer) {
return; return;
} }
/* Autonav takes over normal controls. */
if(player_isFlag(PLAYER_AUTONAV)) {
if(pplayer->lockons > 0)
player_abortAutonav();
if(space_canHyperspace(pplayer))
player_jump();
}
/* PLAYER_FACE will take over navigation. */ /* PLAYER_FACE will take over navigation. */
if(player_isFlag(PLAYER_FACE)) { if(player_isFlag(PLAYER_FACE)) {
if(player_target != PLAYER_ID) if(player_target != PLAYER_ID)

View File

@ -14,6 +14,7 @@
#define PLAYER_SECONDARY_L (1<<14) /**< Player shot secondary last frame. */ #define PLAYER_SECONDARY_L (1<<14) /**< Player shot secondary last frame. */
#define PLAYER_LANDACK (1<<15) /**< Player has permission to land. */ #define PLAYER_LANDACK (1<<15) /**< Player has permission to land. */
#define PLAYER_CREATING (1<<16) /**< Player is being created. */ #define PLAYER_CREATING (1<<16) /**< Player is being created. */
#define PLAYER_AUTONAV (1<<16) /**< Player has autonaviagation on. */
/* Flag functions. */ /* Flag functions. */
#define player_isFlag(f) (player_flags & f) /**< Check for a player flag. */ #define player_isFlag(f) (player_flags & f) /**< Check for a player flag. */