[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 */
|
||||
extern const char* keybindNames[]; /* Keybindings. */
|
||||
/* input.c. */
|
||||
extern unsigned int input_afterburnSensibility;
|
||||
extern unsigned int input_afterburnSensitivity;
|
||||
|
||||
static void print_usage(char** argv);
|
||||
|
||||
@ -170,8 +170,8 @@ int conf_loadConfig(const char* file) {
|
||||
|
||||
/* Input. */
|
||||
i = 250;
|
||||
conf_loadInt("afterburn", i);
|
||||
input_afterburnSensibility = (i < 0) ? 0 : (unsigned int)i;
|
||||
conf_loadInt("afterburn_sensitivity", i);
|
||||
input_afterburnSensitivity = (i < 0) ? 0 : (unsigned int)i;
|
||||
i = 0;
|
||||
|
||||
/* Sound. */
|
||||
|
@ -110,7 +110,7 @@ const char* keybindDescription[] = {
|
||||
|
||||
/* Accel hacks. */
|
||||
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_right; /**< player.c */
|
||||
@ -390,7 +390,7 @@ static void input_key(int keynum, double value, double kabs) {
|
||||
/* Double tap accel = afterburn! */
|
||||
t = SDL_GetTicks();
|
||||
if((value == KEY_PRESS) && INGAME() && NOHYP() &&
|
||||
(t-input_accelLast <= input_afterburnSensibility))
|
||||
(t-input_accelLast <= input_afterburnSensitivity))
|
||||
player_afterburn();
|
||||
else if((value == KEY_RELEASE) && player_isFlag(PLAYER_AFTERBURNER))
|
||||
player_afterburnOver();
|
||||
|
@ -955,6 +955,10 @@ static void pilot_update(Pilot* pilot, const double dt) {
|
||||
pilot_rmFlag(pilot, PILOT_AFTERBURNER); /* Break afterburner. */
|
||||
pilot->energy += pilot->energy_regen * dt;
|
||||
|
||||
/* Player damage decay. */
|
||||
if(pilot->player_damage > 0.)
|
||||
pilot->player_damage -= dt * PILOT_HOSTILE_DECAY;
|
||||
|
||||
/* Check limits. */
|
||||
if(pilot->armour > pilot->armour_max) pilot->armour = pilot->armour_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_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. */
|
||||
#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. */
|
||||
@ -171,6 +175,8 @@ typedef struct Pilot_ {
|
||||
double ptimer; /**< Generic timer for internal pilot use. */
|
||||
int lockons; /**< Stores how many seeking weapons are targetting pilot. */
|
||||
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. */
|
||||
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) {
|
||||
Pilot* parent;
|
||||
int spfx;
|
||||
double damage;
|
||||
DamageType dtype;
|
||||
|
||||
/* Choose spfx. */
|
||||
if(p->shield > 0.)
|
||||
@ -629,18 +631,20 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
|
||||
else
|
||||
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. */
|
||||
if(!pilot_isPlayer(p)) {
|
||||
if((player != NULL) && (w->parent == player->id) &&
|
||||
((player->target == p->id) || (RNGF() > 0.33))) { /* 33% chance. */
|
||||
parent = pilot_get(w->parent);
|
||||
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);
|
||||
}
|
||||
if(!pilot_isPlayer(p) && (pilot_isPlayer(parent)) &&
|
||||
((player->target == p->id) || (p->player_damage > PILOT_HOSTILE_THRESHOLD))) {
|
||||
pilot_setHostile(p);
|
||||
pilot_rmFlag(p, PILOT_BRIBED);
|
||||
ai_attacked(p, w->parent);
|
||||
spfx_add(spfx, pos->x, pos->y,
|
||||
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);
|
||||
|
||||
/* Let the ship know that is should take some kind of damage. */
|
||||
pilot_hit(p, w->solid, w->parent,
|
||||
outfit_damageType(w->outfit), outfit_damage(w->outfit));
|
||||
pilot_hit(p, w->solid, w->parent, dtype, damage);
|
||||
/* We don't need the weapon particle any longer. */
|
||||
weapon_destroy(w, layer);
|
||||
}
|
||||
@ -669,6 +672,8 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
|
||||
(void)layer;
|
||||
Pilot* parent;
|
||||
int spfx;
|
||||
double damage;
|
||||
DamageType dtype;
|
||||
|
||||
/* Choose spfx. */
|
||||
if(p->shield > 0.)
|
||||
@ -676,19 +681,23 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
|
||||
else
|
||||
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. */
|
||||
if(!pilot_isPlayer(p)) {
|
||||
if((player != NULL) && (w->parent == player->id) &&
|
||||
((player->target == p->id) || (RNGF() < 0.30*dt))) { /* 30% chance per second. */
|
||||
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. */
|
||||
}
|
||||
if(pilot_isPlayer(parent) &&
|
||||
((player->target == p->id) || (p->player_damage > PILOT_HOSTILE_THRESHOLD))) {
|
||||
pilot_setHostile(p);
|
||||
pilot_rmFlag(p, PILOT_BRIBED);
|
||||
ai_attacked(p, w->parent);
|
||||
}
|
||||
ai_attacked(p, w->parent);
|
||||
|
||||
if(w->lockon == -1.) { /* Code to signal create explosions. */
|
||||
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. */
|
||||
pilot_hit(p, w->solid, w->parent,
|
||||
outfit_damageType(w->outfit), outfit_damage(w->outfit)*dt);
|
||||
pilot_hit(p, w->solid, w->parent, dtype, damage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user