[Add] Escorts and fighter bays are starting to work quite nicely.
This commit is contained in:
parent
1411001943
commit
843067a0f3
@ -5,10 +5,17 @@
|
||||
include("../scripts/ai/include/attack_generic.lua")
|
||||
include("../scripts/ai/include/attack_bomber.lua")
|
||||
|
||||
atk_think = true
|
||||
|
||||
--[[
|
||||
-- Wrapper for the think functions.
|
||||
--]]
|
||||
function attack_think()
|
||||
-- Not everyone wants to think..
|
||||
if atk_think == false then
|
||||
return
|
||||
end
|
||||
|
||||
if mem.atk_think ~= nil then
|
||||
mem.atk_think()
|
||||
else
|
||||
|
@ -1,6 +1,11 @@
|
||||
include("../scripts/ai/tpl/generic.lua") -- Simple create function.
|
||||
|
||||
function create()
|
||||
-- Shouldn't think, should only obey orders.
|
||||
atk_think = false
|
||||
|
||||
function create(master)
|
||||
mem.escort = master
|
||||
mem.command = true -- On by default.
|
||||
attack_choose()
|
||||
end
|
||||
|
||||
@ -22,12 +27,16 @@ function escort()
|
||||
dist = ai.dist(ai.pos(target))
|
||||
bdist = ai.mindbrakedist()
|
||||
|
||||
-- Close enough.
|
||||
if ai.isstopped() and dist < 300 then
|
||||
return
|
||||
|
||||
-- Brake.
|
||||
if not ai.isstopped() and dist < bdist then
|
||||
elseif dist < bdist then
|
||||
ai.pushtask(0, "brake")
|
||||
|
||||
-- Must approach.
|
||||
elseif dir < 10 and dist > 200 then
|
||||
elseif dir < 10 and dist > 300 then
|
||||
ai.accel()
|
||||
end
|
||||
end
|
||||
@ -96,7 +105,7 @@ end
|
||||
-- Clear orders.
|
||||
function e_clear()
|
||||
if mem.command then
|
||||
while ai.taskname ~= "none" do
|
||||
while ai.taskname() ~= "none" do
|
||||
ai.poptask()
|
||||
end
|
||||
end
|
||||
|
@ -42,6 +42,7 @@ int escort_create(unsigned int parent, char* ship,
|
||||
Pilot* p, *pe;
|
||||
char buf[16];
|
||||
unsigned int e, f;
|
||||
double dir;
|
||||
|
||||
/* Get important stuff. */
|
||||
p = pilot_get(parent);
|
||||
@ -52,8 +53,12 @@ int escort_create(unsigned int parent, char* ship,
|
||||
f = PILOT_ESCORT;
|
||||
if(carried) f |= PILOT_CARRIED;
|
||||
|
||||
/* Get the direction. */
|
||||
if(carried) dir = p->solid->dir;
|
||||
else dir = 0.;
|
||||
|
||||
/* Create the pilot. */
|
||||
e = pilot_create(s, NULL, p->faction, buf, 0., pos, vel, f);
|
||||
e = pilot_create(s, NULL, p->faction, buf, dir, pos, vel, f);
|
||||
pe = pilot_get(e);
|
||||
pe->parent = parent;
|
||||
|
||||
|
@ -91,6 +91,9 @@ char* faction_name(int f) {
|
||||
WARN("Faction id '%d' is invalid.", f);
|
||||
return NULL;
|
||||
}
|
||||
/* Don't want player to see her escorts as "Player" faction. */
|
||||
if(f == FACTION_PLAYER)
|
||||
return "Escort";
|
||||
return faction_stack[f].name;
|
||||
}
|
||||
|
||||
@ -347,6 +350,9 @@ int areAllies(int a, int b) {
|
||||
Faction* fa, *fb;
|
||||
int i;
|
||||
|
||||
/* If they are the same, they must be allies. */
|
||||
if(a == b) return 1;
|
||||
|
||||
/* We assume player becomes allies with high rating. */
|
||||
if(a == FACTION_PLAYER) {
|
||||
if(faction_isFaction(b)) {
|
||||
@ -387,8 +393,6 @@ int areAllies(int a, int b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(a == b) return 0;
|
||||
|
||||
if(fa && fb) {
|
||||
/* Both are factions. */
|
||||
for(i = 0; i < fa->nallies; i++)
|
||||
|
@ -388,6 +388,7 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
|
||||
|
||||
int mod;
|
||||
double damage_shield, damage_armour, knockback, dam_mod;
|
||||
Pilot* pshooter;
|
||||
|
||||
/* Calculate the damage. */
|
||||
outfit_calcDamage(&damage_shield, &damage_armour, &knockback, dtype, damage);
|
||||
@ -421,7 +422,8 @@ 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 and ditto faction. */
|
||||
if(shooter == PLAYER_ID) {
|
||||
pshooter = pilot_get(shooter);
|
||||
if(pshooter->faction == FACTION_PLAYER) {
|
||||
mod = (int)MAX(1, ceil(pow(p->ship->mass, 1./3.))-1.);
|
||||
player_crating += MAX(1, mod);
|
||||
faction_modPlayer(p->faction, -mod);
|
||||
|
@ -593,10 +593,13 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
|
||||
* @param pos Position of the hit.
|
||||
*/
|
||||
static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
|
||||
Pilot* parent;
|
||||
|
||||
/* Someone should let the ai know it's been attacked. */
|
||||
if(!pilot_isPlayer(p)) {
|
||||
if((player->target == p->id) || (RNGF() > 0.33)) { /* 33% chance. */
|
||||
if((w->parent == PLAYER_ID) &&
|
||||
parent = pilot_get(w->parent);
|
||||
if((parent->faction == FACTION_PLAYER) &&
|
||||
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */
|
||||
faction_modPlayer(p->faction, -1); /* Slowly lower faction. */
|
||||
pilot_setFlag(p, PILOT_HOSTILE);
|
||||
@ -631,11 +634,13 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
|
||||
Vec2 pos[2], const double dt) {
|
||||
|
||||
(void)layer;
|
||||
Pilot* parent;
|
||||
|
||||
/* Inform the ai it has been attacked, useless if player. */
|
||||
if(!pilot_isPlayer(p)) {
|
||||
if((player->target == p->id) || (RNGF() < 0.30*dt)) { /* 30% chance per second. */
|
||||
if((w->parent == PLAYER_ID) &&
|
||||
parent = pilot_get(w->parent);
|
||||
if((parent->faction == FACTION_PLAYER) &&
|
||||
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */
|
||||
faction_modPlayer(p->faction, -1); /* Slowly lower faction. */
|
||||
pilot_setFlag(p, PILOT_HOSTILE);
|
||||
|
Loading…
Reference in New Issue
Block a user