[Fix] Fixed god damn ai!
This commit is contained in:
parent
8047f198e9
commit
b26a1ca968
@ -160,8 +160,8 @@ function land()
|
|||||||
tk.msg(msg_title[2], string.format(msg_msg[2], carg_type))
|
tk.msg(msg_title[2], string.format(msg_msg[2], carg_type))
|
||||||
|
|
||||||
-- Modify the faction standing.
|
-- Modify the faction standing.
|
||||||
if player.getFaction("Merchant") < 70 then
|
if player.getFaction("Trader") < 70 then
|
||||||
player.modFactionRaw("Merchant", misn_faction)
|
player.modFactionRaw("Trader", misn_faction)
|
||||||
end
|
end
|
||||||
if player.getFaction("Independent") < 30 then
|
if player.getFaction("Independent") < 30 then
|
||||||
player.modFactionRaw("Independent", misn_faction/2)
|
player.modFactionRaw("Independent", misn_faction/2)
|
||||||
|
@ -14,6 +14,7 @@ function attack_think()
|
|||||||
else
|
else
|
||||||
atk_g_think()
|
atk_g_think()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
-- Wrapper for the attack functions.
|
-- Wrapper for the attack functions.
|
||||||
|
@ -6,31 +6,78 @@
|
|||||||
-- Mainly manages targetting nearest enemy.
|
-- Mainly manages targetting nearest enemy.
|
||||||
--]]
|
--]]
|
||||||
function atk_g_think()
|
function atk_g_think()
|
||||||
if mem.atk_think ~= nil then
|
enemy = ai.getenemy()
|
||||||
mem.atk_think()
|
target = ai.targetid()
|
||||||
else
|
|
||||||
atk_g_think()
|
-- Get new target if it's closer.
|
||||||
|
if enemy ~= target then
|
||||||
|
dist = ai.dist(ai.pos(target))
|
||||||
|
range = ai.getweaprange()
|
||||||
|
|
||||||
|
-- Shouldn't switch targets if close.
|
||||||
|
if dist > range * 1.3 then
|
||||||
|
ai.poptask()
|
||||||
|
ai.pushtask(0, "attack", enemy)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
-- Generic "brute force" attack. Doesn't really do anything interesting.
|
-- Generic "brute force" attack. Doesn't really do anything interesting.
|
||||||
--]]
|
--]]
|
||||||
function atk_g()
|
function atk_g()
|
||||||
if mem.atk ~= nil then
|
target = ai.targetid()
|
||||||
mem.atk()
|
ai.hostile(target) -- Mark as hostile.
|
||||||
|
|
||||||
|
-- Make sure pilot exists.
|
||||||
|
if not ai.exists(target) then
|
||||||
|
ai.poptask()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
ai.settarget(target)
|
||||||
|
|
||||||
|
-- Get stats about enemy.
|
||||||
|
dist = ai.dist(ai.pos(target)) -- Get distance.
|
||||||
|
range = ai.getweaprange()
|
||||||
|
|
||||||
|
-- We first bias towards range.
|
||||||
|
if dist > range then
|
||||||
|
dir = ai.face(target) -- Normal face the target.
|
||||||
|
|
||||||
|
secondary, special, ammo = ai.secondary("Launcher")
|
||||||
|
|
||||||
|
-- Shoot missiles if in range.
|
||||||
|
if secondary == "Launcher" and
|
||||||
|
dist < ai.getweaprange(1) then
|
||||||
|
-- More lenient with aiming.
|
||||||
|
if special == "Smart" and dir < 30 then
|
||||||
|
ai.shoot(2)
|
||||||
|
-- Non-smart miss more.
|
||||||
|
elseif dir < 10 then
|
||||||
|
ai.shoot(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Approach for melee.
|
||||||
|
if dir < 10 then
|
||||||
|
ai.accel()
|
||||||
|
end
|
||||||
|
-- Close enough to melee.
|
||||||
else
|
else
|
||||||
atk_g()
|
secondary, special = ai.secondary("Beam Weapon")
|
||||||
|
dir = ai.aim(target) -- We aim instead of face.
|
||||||
|
|
||||||
|
-- Fire non-smart secondary weapons.
|
||||||
|
if(secondary == "Launcher" and special ~= "Smart") or
|
||||||
|
secondary == "Beam Weapon" then
|
||||||
|
if dir < 10 or special == "Turret" then -- Need good accuracy.
|
||||||
|
ai.shoot(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
if dir < 10 or ai.hasturrets() then
|
||||||
-- Generic function to choose what attack functions match the ship best.
|
ai.shoot()
|
||||||
--]]
|
end
|
||||||
function attack_choose()
|
end
|
||||||
class = ai.shipclass()
|
|
||||||
|
|
||||||
if class == "Bomber" then
|
|
||||||
mem.atk_think = atk_b_think
|
|
||||||
mem.atk = atk_b
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ function runaway()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
dir = ai.face(target, 1)
|
dir = ai.face(target, true)
|
||||||
ai.accel()
|
ai.accel()
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
include("../scripts/ai/include/basic.lua")
|
|
||||||
|
|
||||||
-- Required control rate.
|
|
||||||
control_rate = 2
|
|
||||||
|
|
||||||
-- Required "control" function.
|
|
||||||
function control()
|
|
||||||
task = ai.taskname()
|
|
||||||
enemy = ai.getenemy()
|
|
||||||
|
|
||||||
-- Runaway if enemy is near.
|
|
||||||
if task ~= "runaway" and enemy ~= nil and ai.dist(enemy) < 500 then
|
|
||||||
if task ~= "none" then
|
|
||||||
ai.poptask()
|
|
||||||
end
|
|
||||||
ai.pushtask(0, "runaway", enemy)
|
|
||||||
|
|
||||||
-- Enter hyperspace if possible.
|
|
||||||
elseif task == "hyperspace" then
|
|
||||||
ai.hyperspace() -- Try to go to hyperspace.
|
|
||||||
|
|
||||||
-- Try to jump when far enough away.
|
|
||||||
elseif task == "runaway" then
|
|
||||||
if ai.dist(ai.pos(ai.targetid())) > 400 then
|
|
||||||
ai.hyperspace()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Find something to do.
|
|
||||||
elseif task == "none" then
|
|
||||||
planet = ai.landplanet()
|
|
||||||
-- Planet must exist.
|
|
||||||
if planet == nil then
|
|
||||||
ai.pushtask(0, "hyperspace")
|
|
||||||
else
|
|
||||||
ai.pushtask(0, "hyperspace")
|
|
||||||
ai.pushtask(0, "land", planet)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Required "attacked" function.
|
|
||||||
function attacked(attacker)
|
|
||||||
if ai.taskname() ~= "runaway" then
|
|
||||||
sos = {
|
|
||||||
"Mayday! We are under attack!",
|
|
||||||
"Requesting assistance. We are under attack!",
|
|
||||||
"Merchant vessle here under attack! HALP!"
|
|
||||||
}
|
|
||||||
ai.broadcast(sos[rnd.int(1, #sos)])
|
|
||||||
|
|
||||||
-- So bravely run away!
|
|
||||||
ai.pushtask(0, "runaway", attacker)
|
|
||||||
else -- Runaway from the new bad guys.
|
|
||||||
ai.poptask()
|
|
||||||
ai.pushtask(0, "runaway", attacker)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function create()
|
|
||||||
ai.setcredits(rnd.int(100, ai.shipprice()/50))
|
|
||||||
|
|
||||||
-- Some stuff has more chance than other.
|
|
||||||
num = rnd.int(12)
|
|
||||||
if num < 5 then
|
|
||||||
cargo = "Food"
|
|
||||||
elseif num < 8 then
|
|
||||||
cargo = "Ore"
|
|
||||||
elseif num < 10 then
|
|
||||||
cargo = "Industrial Goods"
|
|
||||||
elseif num < 12 then
|
|
||||||
cargo = "Luxury Goods"
|
|
||||||
else
|
|
||||||
cargo = "Medicine"
|
|
||||||
end
|
|
||||||
ai.setcargo(cargo, rnd.int(0, ai.cargofree()))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Fly to the target.
|
|
||||||
function go()
|
|
||||||
target = ai.target()
|
|
||||||
dir = ai.face(target)
|
|
||||||
dist = ai.dist(target)
|
|
||||||
bdist = ai.minbrakedist()
|
|
||||||
if dir < 10 and dist > bdist then
|
|
||||||
ai.accel()
|
|
||||||
elseif dir < 10 and dist < bdist then
|
|
||||||
ai.poptask()
|
|
||||||
ai.pushtask(0, "stop")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Backthrust.
|
|
||||||
function stop()
|
|
||||||
ai.brake()
|
|
||||||
if ai.isstopped() then
|
|
||||||
ai.stop()
|
|
||||||
ai.poptask()
|
|
||||||
ai.settimer(0, rnd.int(8000, 15000)) -- We wait during a while.
|
|
||||||
ai.pushtask(0, "land")
|
|
||||||
else
|
|
||||||
ai.brake()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Waits.
|
|
||||||
function land()
|
|
||||||
if ai.timeup(0) then
|
|
||||||
ai.pushtask(0, "hyperspace")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
include("../scripts/ai/merchant.lua")
|
include("../scripts/ai/tpl/merchant.lua")
|
||||||
|
|
||||||
function sos()
|
function sos()
|
||||||
msg = {
|
msg = {
|
||||||
|
2
src/ai.c
2
src/ai.c
@ -502,7 +502,7 @@ void ai_think(Pilot* pilot) {
|
|||||||
L = cur_pilot->ai->L; /* Set the AI profile to the current pilot's. */
|
L = cur_pilot->ai->L; /* Set the AI profile to the current pilot's. */
|
||||||
|
|
||||||
/* Clean up some variables. */
|
/* Clean up some variables. */
|
||||||
pilot_acc = 0.;
|
pilot_acc = 0;
|
||||||
pilot_turn = 0.;
|
pilot_turn = 0.;
|
||||||
pilot_flags = 0;
|
pilot_flags = 0;
|
||||||
cur_pilot->target = cur_pilot->id;
|
cur_pilot->target = cur_pilot->id;
|
||||||
|
@ -80,7 +80,7 @@ void input_setDefault(void) {
|
|||||||
input_setKeybind("e_attack", KEYBIND_KEYBOARD, SDLK_f, KMOD_NONE, 0);
|
input_setKeybind("e_attack", KEYBIND_KEYBOARD, SDLK_f, KMOD_NONE, 0);
|
||||||
input_setKeybind("e_hold", KEYBIND_KEYBOARD, SDLK_g, KMOD_NONE, 0);
|
input_setKeybind("e_hold", KEYBIND_KEYBOARD, SDLK_g, KMOD_NONE, 0);
|
||||||
input_setKeybind("e_return", KEYBIND_KEYBOARD, SDLK_r, KMOD_NONE, 0);
|
input_setKeybind("e_return", KEYBIND_KEYBOARD, SDLK_r, KMOD_NONE, 0);
|
||||||
input_setKeybind("e_cleark", KEYBIND_KEYBOARD, SDLK_c, KMOD_NONE, 0);
|
input_setKeybind("e_clear", KEYBIND_KEYBOARD, SDLK_c, KMOD_NONE, 0);
|
||||||
|
|
||||||
|
|
||||||
/* Secondary weapon. */
|
/* Secondary weapon. */
|
||||||
|
Loading…
Reference in New Issue
Block a user