[Change] Improved how pilots react to taking damage.
This commit is contained in:
parent
db441d5765
commit
2e76ef4019
@ -57,7 +57,7 @@ extern char* namjoystick;
|
|||||||
/* From player.c */
|
/* From player.c */
|
||||||
extern const char* keybindNames[]; /* Keybindings. */
|
extern const char* keybindNames[]; /* Keybindings. */
|
||||||
/* input.c. */
|
/* input.c. */
|
||||||
extern unsigned int input_afterburnSensibility;
|
extern unsigned int input_afterburnSensitivity;
|
||||||
|
|
||||||
static void print_usage(char** argv);
|
static void print_usage(char** argv);
|
||||||
|
|
||||||
@ -170,8 +170,8 @@ int conf_loadConfig(const char* file) {
|
|||||||
|
|
||||||
/* Input. */
|
/* Input. */
|
||||||
i = 250;
|
i = 250;
|
||||||
conf_loadInt("afterburn", i);
|
conf_loadInt("afterburn_sensitivity", i);
|
||||||
input_afterburnSensibility = (i < 0) ? 0 : (unsigned int)i;
|
input_afterburnSensitivity = (i < 0) ? 0 : (unsigned int)i;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
/* Sound. */
|
/* Sound. */
|
||||||
|
@ -110,7 +110,7 @@ const char* keybindDescription[] = {
|
|||||||
|
|
||||||
/* Accel hacks. */
|
/* Accel hacks. */
|
||||||
static unsigned int input_accelLast = 0; /**< Used to see if double tap. */
|
static unsigned int input_accelLast = 0; /**< Used to see if double tap. */
|
||||||
unsigned int input_afterburnSensibility = 200; /**< ms between taps to afterburn. */
|
unsigned int input_afterburnSensitivity = 200; /**< ms between taps to afterburn. */
|
||||||
|
|
||||||
extern double player_left; /**< player.c */
|
extern double player_left; /**< player.c */
|
||||||
extern double player_right; /**< player.c */
|
extern double player_right; /**< player.c */
|
||||||
@ -390,7 +390,7 @@ static void input_key(int keynum, double value, double kabs) {
|
|||||||
/* Double tap accel = afterburn! */
|
/* Double tap accel = afterburn! */
|
||||||
t = SDL_GetTicks();
|
t = SDL_GetTicks();
|
||||||
if((value == KEY_PRESS) && INGAME() && NOHYP() &&
|
if((value == KEY_PRESS) && INGAME() && NOHYP() &&
|
||||||
(t-input_accelLast <= input_afterburnSensibility))
|
(t-input_accelLast <= input_afterburnSensitivity))
|
||||||
player_afterburn();
|
player_afterburn();
|
||||||
else if((value == KEY_RELEASE) && player_isFlag(PLAYER_AFTERBURNER))
|
else if((value == KEY_RELEASE) && player_isFlag(PLAYER_AFTERBURNER))
|
||||||
player_afterburnOver();
|
player_afterburnOver();
|
||||||
|
@ -955,6 +955,10 @@ static void pilot_update(Pilot* pilot, const double dt) {
|
|||||||
pilot_rmFlag(pilot, PILOT_AFTERBURNER); /* Break afterburner. */
|
pilot_rmFlag(pilot, PILOT_AFTERBURNER); /* Break afterburner. */
|
||||||
pilot->energy += pilot->energy_regen * dt;
|
pilot->energy += pilot->energy_regen * dt;
|
||||||
|
|
||||||
|
/* Player damage decay. */
|
||||||
|
if(pilot->player_damage > 0.)
|
||||||
|
pilot->player_damage -= dt * PILOT_HOSTILE_DECAY;
|
||||||
|
|
||||||
/* Check limits. */
|
/* Check limits. */
|
||||||
if(pilot->armour > pilot->armour_max) pilot->armour = pilot->armour_max;
|
if(pilot->armour > pilot->armour_max) pilot->armour = pilot->armour_max;
|
||||||
if(pilot->shield > pilot->shield_max) pilot->shield = pilot->shield_max;
|
if(pilot->shield > pilot->shield_max) pilot->shield = pilot->shield_max;
|
||||||
|
@ -34,6 +34,10 @@
|
|||||||
#define PILOT_HOOK_DISABLE 3 /**< Pilot got disabled. */
|
#define PILOT_HOOK_DISABLE 3 /**< Pilot got disabled. */
|
||||||
#define PILOT_HOOK_JUMP 4 /**< Pilot jumped. */
|
#define PILOT_HOOK_JUMP 4 /**< Pilot jumped. */
|
||||||
|
|
||||||
|
/* Damage. */
|
||||||
|
#define PILOT_HOSTILE_THRESHOLD 0.09 /**< Point at which pilot becomes hostile. */
|
||||||
|
#define PILOT_HOSTILE_DECAY 0.005 /**< Rate at which hostility decays. */
|
||||||
|
|
||||||
/* Flags. */
|
/* Flags. */
|
||||||
#define pilot_isFlag(p,f) (p->flags & (f)) /**< Check if flag f is set on pilot p. */
|
#define pilot_isFlag(p,f) (p->flags & (f)) /**< Check if flag f is set on pilot p. */
|
||||||
#define pilot_setFlag(p,f) (p->flags |= (f)) /**< Set flag f on pilot p. */
|
#define pilot_setFlag(p,f) (p->flags |= (f)) /**< Set flag f on pilot p. */
|
||||||
@ -171,6 +175,8 @@ typedef struct Pilot_ {
|
|||||||
double 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. */
|
||||||
int* mounted; /**< Number of mounted outfits on the mount. */
|
int* mounted; /**< Number of mounted outfits on the mount. */
|
||||||
|
double player_damage; /**< Accumulates damage done by player for hostileness
|
||||||
|
in per one of max shield + armour. */
|
||||||
|
|
||||||
/* Hook attached to the pilot. */
|
/* Hook attached to the pilot. */
|
||||||
int hook_type[PILOT_HOOKS]; /**< Type of the hook atached to the pilot. */
|
int hook_type[PILOT_HOOKS]; /**< Type of the hook atached to the pilot. */
|
||||||
|
54
src/weapon.c
54
src/weapon.c
@ -622,6 +622,8 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
|
|||||||
static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
|
static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
|
||||||
Pilot* parent;
|
Pilot* parent;
|
||||||
int spfx;
|
int spfx;
|
||||||
|
double damage;
|
||||||
|
DamageType dtype;
|
||||||
|
|
||||||
/* Choose spfx. */
|
/* Choose spfx. */
|
||||||
if(p->shield > 0.)
|
if(p->shield > 0.)
|
||||||
@ -629,18 +631,20 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
|
|||||||
else
|
else
|
||||||
spfx = outfit_spfxArmour(w->outfit);
|
spfx = outfit_spfxArmour(w->outfit);
|
||||||
|
|
||||||
|
/* Get general details. */
|
||||||
|
parent = pilot_get(w->parent);
|
||||||
|
damage = outfit_damage(w->outfit);
|
||||||
|
dtype = outfit_damageType(w->outfit);
|
||||||
|
|
||||||
|
/* Update damage. */
|
||||||
|
if((parent != NULL) && (parent->faction == FACTION_PLAYER))
|
||||||
|
p->player_damage += damage / (p->shield_max + p->armour_max);
|
||||||
|
|
||||||
/* Someone should let the ai know it's been attacked. */
|
/* Someone should let the ai know it's been attacked. */
|
||||||
if(!pilot_isPlayer(p)) {
|
if(!pilot_isPlayer(p) && (pilot_isPlayer(parent)) &&
|
||||||
if((player != NULL) && (w->parent == player->id) &&
|
((player->target == p->id) || (p->player_damage > PILOT_HOSTILE_THRESHOLD))) {
|
||||||
((player->target == p->id) || (RNGF() > 0.33))) { /* 33% chance. */
|
pilot_setHostile(p);
|
||||||
parent = pilot_get(w->parent);
|
pilot_rmFlag(p, PILOT_BRIBED);
|
||||||
if((parent != NULL) && (parent->faction == FACTION_PLAYER) &&
|
|
||||||
(!pilot_isHostile(p) || (RNGF() < 0.5))) { /* 50% chance. */
|
|
||||||
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
|
|
||||||
}
|
|
||||||
pilot_setHostile(p);
|
|
||||||
pilot_rmFlag(p, PILOT_BRIBED);
|
|
||||||
}
|
|
||||||
ai_attacked(p, w->parent);
|
ai_attacked(p, w->parent);
|
||||||
spfx_add(spfx, pos->x, pos->y,
|
spfx_add(spfx, pos->x, pos->y,
|
||||||
VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_BACK);
|
VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_BACK);
|
||||||
@ -649,8 +653,7 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
|
|||||||
VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_FRONT);
|
VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_FRONT);
|
||||||
|
|
||||||
/* Let the ship know that is should take some kind of damage. */
|
/* Let the ship know that is should take some kind of damage. */
|
||||||
pilot_hit(p, w->solid, w->parent,
|
pilot_hit(p, w->solid, w->parent, dtype, damage);
|
||||||
outfit_damageType(w->outfit), outfit_damage(w->outfit));
|
|
||||||
/* We don't need the weapon particle any longer. */
|
/* We don't need the weapon particle any longer. */
|
||||||
weapon_destroy(w, layer);
|
weapon_destroy(w, layer);
|
||||||
}
|
}
|
||||||
@ -669,6 +672,8 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
|
|||||||
(void)layer;
|
(void)layer;
|
||||||
Pilot* parent;
|
Pilot* parent;
|
||||||
int spfx;
|
int spfx;
|
||||||
|
double damage;
|
||||||
|
DamageType dtype;
|
||||||
|
|
||||||
/* Choose spfx. */
|
/* Choose spfx. */
|
||||||
if(p->shield > 0.)
|
if(p->shield > 0.)
|
||||||
@ -676,19 +681,23 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
|
|||||||
else
|
else
|
||||||
spfx = outfit_spfxArmour(w->outfit);
|
spfx = outfit_spfxArmour(w->outfit);
|
||||||
|
|
||||||
|
/* Get general details. */
|
||||||
|
parent = pilot_get(w->parent);
|
||||||
|
damage = outfit_damage(w->outfit) * dt;
|
||||||
|
dtype = outfit_damageType(w->outfit);
|
||||||
|
|
||||||
|
/* Update damage. */
|
||||||
|
if((parent != NULL) && (parent->faction == FACTION_PLAYER))
|
||||||
|
p->player_damage += damage / (p->shield_max + p->armour_max);
|
||||||
|
|
||||||
/* Inform the ai it has been attacked, useless if player. */
|
/* Inform the ai it has been attacked, useless if player. */
|
||||||
if(!pilot_isPlayer(p)) {
|
if(!pilot_isPlayer(p)) {
|
||||||
if((player != NULL) && (w->parent == player->id) &&
|
if(pilot_isPlayer(parent) &&
|
||||||
((player->target == p->id) || (RNGF() < 0.30*dt))) { /* 30% chance per second. */
|
((player->target == p->id) || (p->player_damage > PILOT_HOSTILE_THRESHOLD))) {
|
||||||
parent = pilot_get(w->parent);
|
|
||||||
if((parent != NULL) && (parent->faction == FACTION_PLAYER) &&
|
|
||||||
(!pilot_isHostile(p) || (RNGF() < 0.50*dt))) { /* 50% chance. */
|
|
||||||
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
|
|
||||||
}
|
|
||||||
pilot_setHostile(p);
|
pilot_setHostile(p);
|
||||||
pilot_rmFlag(p, PILOT_BRIBED);
|
pilot_rmFlag(p, PILOT_BRIBED);
|
||||||
|
ai_attacked(p, w->parent);
|
||||||
}
|
}
|
||||||
ai_attacked(p, w->parent);
|
|
||||||
|
|
||||||
if(w->lockon == -1.) { /* Code to signal create explosions. */
|
if(w->lockon == -1.) { /* Code to signal create explosions. */
|
||||||
spfx_add(spfx, pos[0].x, pos[0].y,
|
spfx_add(spfx, pos[0].x, pos[0].y,
|
||||||
@ -707,8 +716,7 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Inform the ship that it should take some damage. */
|
/* Inform the ship that it should take some damage. */
|
||||||
pilot_hit(p, w->solid, w->parent,
|
pilot_hit(p, w->solid, w->parent, dtype, damage);
|
||||||
outfit_damageType(w->outfit), outfit_damage(w->outfit)*dt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user