[Fix] Fixed some escort ai issues, also allowed for fighters to return to ship.
This commit is contained in:
		
							parent
							
								
									843067a0f3
								
							
						
					
					
						commit
						3a87ce36ff
					
				@ -4,6 +4,7 @@ include("../scripts/ai/tpl/escort.lua")
 | 
				
			|||||||
armour_run    = 40
 | 
					armour_run    = 40
 | 
				
			||||||
armour_return = 70
 | 
					armour_return = 70
 | 
				
			||||||
aggressive    = true
 | 
					aggressive    = true
 | 
				
			||||||
 | 
					command       = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function create()
 | 
					function create()
 | 
				
			||||||
  mem.escort = ai.getPlayer()
 | 
					  mem.escort = ai.getPlayer()
 | 
				
			||||||
 | 
				
			|||||||
@ -2,10 +2,11 @@ include("../scripts/ai/tpl/generic.lua") -- Simple create function.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
-- Shouldn't think, should only obey orders.
 | 
					-- Shouldn't think, should only obey orders.
 | 
				
			||||||
atk_think = false
 | 
					atk_think = false
 | 
				
			||||||
 | 
					command = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function create(master)
 | 
					function create(master)
 | 
				
			||||||
  mem.escort = master
 | 
					  mem.escort = master
 | 
				
			||||||
  mem.command = true -- On by default.
 | 
					  mem.carrier = true
 | 
				
			||||||
  attack_choose()
 | 
					  attack_choose()
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -32,7 +33,7 @@ function escort()
 | 
				
			|||||||
    return
 | 
					    return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- Brake.
 | 
					  -- Brake.
 | 
				
			||||||
  elseif dist < bdist then
 | 
					  elseif dist+100 < bdist then
 | 
				
			||||||
    ai.pushtask(0, "brake")
 | 
					    ai.pushtask(0, "brake")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- Must approach.
 | 
					  -- Must approach.
 | 
				
			||||||
@ -83,28 +84,28 @@ end
 | 
				
			|||||||
--]]
 | 
					--]]
 | 
				
			||||||
--Attack target.
 | 
					--Attack target.
 | 
				
			||||||
function e_attack(target)
 | 
					function e_attack(target)
 | 
				
			||||||
  if mem.command then
 | 
					  if command then
 | 
				
			||||||
    ai.pushtask(0, "attack", target)
 | 
					    ai.pushtask(0, "attack", target)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Hold position.
 | 
					-- Hold position.
 | 
				
			||||||
function e_hold()
 | 
					function e_hold()
 | 
				
			||||||
  if mem.command then
 | 
					  if command then
 | 
				
			||||||
    ai.pushtask(0, "hold")
 | 
					    ai.pushtask(0, "hold")
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Return to carrier.
 | 
					-- Return to carrier.
 | 
				
			||||||
function e_return()
 | 
					function e_return()
 | 
				
			||||||
  if mem.command and mem.carrier then
 | 
					  if command and mem.carrier then
 | 
				
			||||||
    ai.pushtask(0, "flyback")
 | 
					    ai.pushtask(0, "flyback")
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Clear orders.
 | 
					-- Clear orders.
 | 
				
			||||||
function e_clear()
 | 
					function e_clear()
 | 
				
			||||||
  if mem.command then
 | 
					  if command then
 | 
				
			||||||
    while ai.taskname() ~= "none" do
 | 
					    while ai.taskname() ~= "none" do
 | 
				
			||||||
      ai.poptask()
 | 
					      ai.poptask()
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								src/ai.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								src/ai.c
									
									
									
									
									
								
							@ -150,6 +150,7 @@ static int ai_getrndplanet(lua_State* L);       /* Vec2 getrndplanet() */
 | 
				
			|||||||
static int ai_getlandplanet(lua_State* L);      /* Vec2 getlandplanet() */
 | 
					static int ai_getlandplanet(lua_State* L);      /* Vec2 getlandplanet() */
 | 
				
			||||||
static int ai_hyperspace(lua_State* L);         /* [number] hyperspace() */
 | 
					static int ai_hyperspace(lua_State* L);         /* [number] hyperspace() */
 | 
				
			||||||
static int ai_stop(lua_State* L);               /* stop() */
 | 
					static int ai_stop(lua_State* L);               /* stop() */
 | 
				
			||||||
 | 
					static int ai_dock(lua_State* L);               /* dock(number) */
 | 
				
			||||||
/* Combat. */
 | 
					/* Combat. */
 | 
				
			||||||
static int ai_combat(lua_State* L);             /* combat(number) */
 | 
					static int ai_combat(lua_State* L);             /* combat(number) */
 | 
				
			||||||
static int ai_settarget(lua_State* L);          /* settarget(number) */
 | 
					static int ai_settarget(lua_State* L);          /* settarget(number) */
 | 
				
			||||||
@ -207,6 +208,7 @@ static const luaL_Reg ai_methods[] = {
 | 
				
			|||||||
  { "brake",                ai_brake            },
 | 
					  { "brake",                ai_brake            },
 | 
				
			||||||
  { "stop",                 ai_stop             },
 | 
					  { "stop",                 ai_stop             },
 | 
				
			||||||
  { "hyperspace",           ai_hyperspace       },
 | 
					  { "hyperspace",           ai_hyperspace       },
 | 
				
			||||||
 | 
					  { "dock",                 ai_dock             },
 | 
				
			||||||
  /* Combat. */
 | 
					  /* Combat. */
 | 
				
			||||||
  { "aim",                  ai_aim              },
 | 
					  { "aim",                  ai_aim              },
 | 
				
			||||||
  { "combat",               ai_combat           },
 | 
					  { "combat",               ai_combat           },
 | 
				
			||||||
@ -529,8 +531,8 @@ void ai_think(Pilot* pilot) {
 | 
				
			|||||||
            cur_pilot->solid->dir);
 | 
					            cur_pilot->solid->dir);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Fire weapons if needs be. */
 | 
					  /* Fire weapons if needs be. */
 | 
				
			||||||
  if(ai_isFlag(AI_PRIMARY)) pilot_shoot(pilot, 0); /* Primary. */
 | 
					  if(ai_isFlag(AI_PRIMARY)) pilot_shoot(cur_pilot, 0); /* Primary. */
 | 
				
			||||||
  if(ai_isFlag(AI_SECONDARY)) pilot_shoot(pilot, 1); /* Secondary. */
 | 
					  if(ai_isFlag(AI_SECONDARY)) pilot_shoot(cur_pilot, 1); /* Secondary. */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -1116,6 +1118,21 @@ static int ai_stop(lua_State* L) {
 | 
				
			|||||||
  return 0;
 | 
					  return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Docks the ship. */
 | 
				
			||||||
 | 
					static int ai_dock(lua_State* L) {
 | 
				
			||||||
 | 
					  Pilot* p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Target is another ship. */
 | 
				
			||||||
 | 
					  if(lua_isnumber(L, 1)) {
 | 
				
			||||||
 | 
					    p = pilot_get(lua_tonumber(L, 1));
 | 
				
			||||||
 | 
					    if(p == NULL) return 0;
 | 
				
			||||||
 | 
					    pilot_dock(cur_pilot, p);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  else LLUA_INVALID_PARAMETER();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Aim at the pilot, trying to hit it. */
 | 
					/* Aim at the pilot, trying to hit it. */
 | 
				
			||||||
static int ai_aim(lua_State* L) {
 | 
					static int ai_aim(lua_State* L) {
 | 
				
			||||||
  int id;
 | 
					  int id;
 | 
				
			||||||
 | 
				
			|||||||
@ -98,7 +98,7 @@ static int escort_command(Pilot* parent, int cmd, int param) {
 | 
				
			|||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Check if command makes sense. */
 | 
					    /* Check if command makes sense. */
 | 
				
			||||||
    if((cmd == ESCORT_RETURN) && !pilot_isFlag(parent, PILOT_CARRIED))
 | 
					    if((cmd == ESCORT_RETURN) && !pilot_isFlag(e, PILOT_CARRIED))
 | 
				
			||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    n++; /* Amount of escorts left. */
 | 
					    n++; /* Amount of escorts left. */
 | 
				
			||||||
 | 
				
			|||||||
@ -15,9 +15,9 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
typedef enum OutfitType_ {
 | 
					typedef enum OutfitType_ {
 | 
				
			||||||
  OUTFIT_TYPE_NULL,                       /**< NULL type. */
 | 
					  OUTFIT_TYPE_NULL,                       /**< NULL type. */
 | 
				
			||||||
  OUTFIT_TYPE_BOLT,                       /**< @todo Fixed bolt cannon. */
 | 
					  OUTFIT_TYPE_BOLT,                       /**< Fixed bolt cannon. */
 | 
				
			||||||
  OUTFIT_TYPE_BEAM,                       /**< Fixed beam cannon. */
 | 
					  OUTFIT_TYPE_BEAM,                       /**< Fixed beam cannon. */
 | 
				
			||||||
  OUTFIT_TYPE_TURRET_BOLT,                /**< @todo Rotaty bolt turret. */
 | 
					  OUTFIT_TYPE_TURRET_BOLT,                /**< Rotaty bolt turret. */
 | 
				
			||||||
  OUTFIT_TYPE_TURRET_BEAM,                /**< Rotary bolt turret. */
 | 
					  OUTFIT_TYPE_TURRET_BEAM,                /**< Rotary bolt turret. */
 | 
				
			||||||
  OUTFIT_TYPE_MISSILE_DUMB,               /**< Dumb missile launcher. */
 | 
					  OUTFIT_TYPE_MISSILE_DUMB,               /**< Dumb missile launcher. */
 | 
				
			||||||
  OUTFIT_TYPE_MISSILE_DUMB_AMMO,          /**< Dumb missile ammo. */
 | 
					  OUTFIT_TYPE_MISSILE_DUMB_AMMO,          /**< Dumb missile ammo. */
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										38
									
								
								src/pilot.c
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								src/pilot.c
									
									
									
									
									
								
							@ -580,6 +580,40 @@ void pilot_setAfterburner(Pilot* p) {
 | 
				
			|||||||
  p->afterburner = NULL;
 | 
					  p->afterburner = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @fn int pilot_dock(Pilot* p, Pilot* target)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @brief Dock the pilot on its target pilot.
 | 
				
			||||||
 | 
					 *    @param p Pilot that wants to dock.
 | 
				
			||||||
 | 
					 *    @param target Pilot to dock on.
 | 
				
			||||||
 | 
					 *    @return 0 on successful docking.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int pilot_dock(Pilot* p, Pilot* target) {
 | 
				
			||||||
 | 
					  int i;
 | 
				
			||||||
 | 
					  Outfit* o;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Check to see if target has an available bay. */
 | 
				
			||||||
 | 
					  for(i = 0; i < target->noutfits; i++) {
 | 
				
			||||||
 | 
					    if(outfit_isFighterBay(target->outfits[i].outfit)) {
 | 
				
			||||||
 | 
					      o = outfit_get(outfit_ammo(target->outfits[i].outfit));
 | 
				
			||||||
 | 
					      if(outfit_isFighter(o) &&
 | 
				
			||||||
 | 
					          (strcmp(p->ship->name, o->u.fig.ship)==0))
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if(i >= target->noutfits)
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Add the pilots outfit. */
 | 
				
			||||||
 | 
					  if(pilot_addOutfit(target, o, 1) != 1)
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Destroy the pilot. */
 | 
				
			||||||
 | 
					  pilot_setFlag(p, PILOT_DELETE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void pilot_explode(double x, double y, double radius,
 | 
					void pilot_explode(double x, double y, double radius,
 | 
				
			||||||
@ -1283,9 +1317,9 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  /* Escort stuff. */
 | 
					  /* Escort stuff. */
 | 
				
			||||||
  if(flags & PILOT_ESCORT) {
 | 
					  if(flags & PILOT_ESCORT) {
 | 
				
			||||||
    pilot->flags |= PILOT_ESCORT;
 | 
					    pilot_setFlag(pilot, PILOT_ESCORT);
 | 
				
			||||||
    if(flags & PILOT_CARRIED)
 | 
					    if(flags & PILOT_CARRIED)
 | 
				
			||||||
      pilot->flags |= PILOT_CARRIED;
 | 
					      pilot_setFlag(pilot, PILOT_CARRIED);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* AI. */
 | 
					  /* AI. */
 | 
				
			||||||
 | 
				
			|||||||
@ -235,6 +235,8 @@ void pilot_setSecondary(Pilot* p, const char* secondary);
 | 
				
			|||||||
void pilot_setAmmo(Pilot* p);
 | 
					void pilot_setAmmo(Pilot* p);
 | 
				
			||||||
int pilot_getAmmo(Pilot* p, Outfit* o);
 | 
					int pilot_getAmmo(Pilot* p, Outfit* o);
 | 
				
			||||||
void pilot_setAfterburner(Pilot* p);
 | 
					void pilot_setAfterburner(Pilot* p);
 | 
				
			||||||
 | 
					/* Escort stuff. */
 | 
				
			||||||
 | 
					int pilot_dock(Pilot* p, Pilot* target);
 | 
				
			||||||
/* Explosion. */
 | 
					/* Explosion. */
 | 
				
			||||||
void pilot_explode(double x, double y, double radius,
 | 
					void pilot_explode(double x, double y, double radius,
 | 
				
			||||||
    DamageType dtype, double damage, unsigned int parent);
 | 
					    DamageType dtype, double damage, unsigned int parent);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user