diff --git a/scripts/ai/empire.lua b/scripts/ai/empire.lua index 8443385..e2edab0 100644 --- a/scripts/ai/empire.lua +++ b/scripts/ai/empire.lua @@ -7,6 +7,7 @@ function control() enemy = ai.getenemy() if task ~= "attack" and enemy ~= 0 then + ai.hostile(enemy) ai.pushtask(0, "attack", enemy) elseif task == "none" then planet = ai.rndplanet() diff --git a/scripts/ai/militia.lua b/scripts/ai/militia.lua index 3ac6a16..7a1d1d9 100644 --- a/scripts/ai/militia.lua +++ b/scripts/ai/militia.lua @@ -7,6 +7,7 @@ function control() enemy = ai.getenemy() if task ~= "attack" and enemy ~= 0 then + ai.hostile(enemy) ai.pushtask(0, "attack", enemy) elseif ai.taskname() == "none" then ai.pushtask(0, "scan", ai.rndpilot()) diff --git a/src/faction.c b/src/faction.c index 2ba1bcc..c7bcaba 100644 --- a/src/faction.c +++ b/src/faction.c @@ -94,6 +94,15 @@ static Alliance* alliance_get(char* name) { return NULL; } +void faction_modPlayer(int f, int mod) { + if(faction_isFaction(f)) { + faction_stack[f].player += mod; + } else { + DEBUG("%d is an invalid faction/alliance", f); + return; + } +} + // Return 1 if Faction a and b are enemies. int areEnemies(int a, int b) { Faction* fa, *fb; diff --git a/src/faction.h b/src/faction.h index 7ad75d5..dc5b695 100644 --- a/src/faction.h +++ b/src/faction.h @@ -7,6 +7,9 @@ int faction_get(const char* name); int faction_getAlliance(char* name); char* faction_name(int f); +// Player stuff. +void faction_modPlayer(int f, int mod); + // Works with only factions. int areEnemies(int a, int b); int areAllies(int a, int b); diff --git a/src/pilot.c b/src/pilot.c index f306175..e78d2a5 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -266,8 +266,11 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter, if(!pilot_isFlag(p, PILOT_DEAD)) { pilot_dead(p); - // Adjust the combat rating based on pilot mass. - if(shooter == PLAYER_ID) player_crating += MAX(1, p->ship->mass/50); + // Adjust the combat rating based on pilot mass and ditto faction. + if(shooter == PLAYER_ID) { + player_crating += MAX(1, p->ship->mass/50); + faction_modPlayer(p->faction, -(p->ship->mass/10)); + } } } diff --git a/src/weapon.c b/src/weapon.c index 35c96ce..ca2b07c 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -24,6 +24,9 @@ extern Pilot** pilot_stack; extern int pilots; +// Player stuff. +extern unsigned int player_target; + // Ai stuff. extern void ai_attacked(Pilot* attacked, const unsigned int attacker); @@ -318,7 +321,11 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) { static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer) { // Someone should let the ai know it's been attacked. if(!pilot_isPlayer(p)) { - ai_attacked(p, w->parent); + if((player_target == p->id) || (RNG(0,2) == 0)) { + if(pilot_isFlag(p, PILOT_HOSTILE) || (RNG(0, 2) == 0)) + faction_modPlayer(p->faction, -1); // Slowly lower faction. + ai_attacked(p, w->parent); + } spfx_add(outfit_spfx(w->outfit), VX(w->solid->pos), VY(w->solid->pos), VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_BACK);