[Add] You can lose faction now, fixed ai to set you as hostile.

This commit is contained in:
Allanis 2013-05-23 14:31:41 +01:00
parent e0e166ae64
commit b860e38959
6 changed files with 27 additions and 3 deletions

View File

@ -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()

View File

@ -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())

View File

@ -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;

View File

@ -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);

View File

@ -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));
}
}
}

View File

@ -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);