March 28, 2024, 10:14:07

Author Topic: Fire Missile  (Read 4152 times)

Offline Blazar

  • Crewman
  • *
  • Posts: 47
  • Karma: 0
    • View Profile
Fire Missile
« on: July 21, 2011, 13:28:27 »
In new_cinema_mode, i want to enable the ships to fire their missisles i.e . RAD EB and Pulsar Missiles.

This is the original 1_new_cinema_mode_ai. It is the standard code.

Code: [Select]
MACHINE "AI"

STATE battle

RULE event In
:action

m.mainTarget0:=0;
m.mainTarget0:=1;
localEvent(StartAutoCamera, 0);

timer(StopAutoCamera, 600, 0);

SelectShips(20, s.race=#race_spacetech);
if(AllNumOf(20)>0, m.team1_leader:=Pick(20), ChangeState(noTeam1,0));

ExecList(20,
MakeFullyKnown(s.this);
FreezeReconState(s.this, #race_player, 1);
FreezeReconState(s.this, #race_Player, 1);
);

SelectShips(10, s.race=#race_player);

if(AllNumOf(20)>0, m.team0_leader:=Pick(10), ChangeState(noTeam0,0));
ExecList(10,
MakeFullyKnown(s.this);
FreezeReconState(s.this, #race_spacetech, 1);
FreezeReconState(s.this, #race_Player, 1);
);
m.mainTarget:=Pick(10);

//GuiSelect(3);

LocalEvent(GetTarget0);
LocalEvent(GetTarget1);
Delay(0,5,LocalEvent(Tick),0);
:end
END

RULE event GetTarget1
condition isValid(m.team1_leader)
:action
SelectShips(10, s.race=#race_player);
if(AllNumOf(10)>0, m.mainTarget1:=PickMax(10, 1 / distance(s.this, m.team1_leader)), ChangeState(noTeam0,0));

LocalEvent(FireTo1);
:end
END

RULE event GetTarget0
condition isValid(m.team0_leader)
:action
SelectShips(20, s.race=#race_spacetech);
if(AllNumOf(20)>0, m.mainTarget0:=PickMax(20, 1 / distance(s.this, m.team0_leader)), ChangeState(noTeam1,0));

LocalEvent(FireTo0);
:end
END


RULE event FireTo1
:action
if(isValid(m.team1_leader)&isValid(m.mainTarget1),
SelectShips(20, s.race=#race_spacetech);
ExecList(20,
s.this:tClearFire;
s.this:tMoveTo(m.mainTarget,1,0);
s.this:tFireTo(m.maintarget,1);
),
LocalEvent(FatalDamaged, E.ship=m.team1_leader)
);
:end
END

RULE event FireTo0
:action
if(isValid(m.team0_leader)&isValid(m.mainTarget0),
SelectShips(10, s.race=#race_player);
ExecList(10,
s.this:tClearFire;
s.this:tMoveTo(m.mainTarget0,1,0);
s.this:tFireTo(m.maintarget0,1);
),
LocalEvent(FatalDamaged, E.ship=m.team0_leader)
);
:end
END

RULE event ShieldDown
condition E.Ship:race=#race_player
:action
if(isValid(m.team1_leader)&isValid(E.ship),
SelectShips(20, s.race=#race_spacetech);
ExecList(20,
//s.this:tClearFire;
//s.this:tMoveTo(E.Ship,2,0);
s.this:tFireTo(E.Ship,2);
);
);
:end
END

RULE event ShieldDown
condition E.Ship:race=#race_spacetech
:action
if(isValid(m.team0_leader)&isValid(E.ship),
SelectShips(20, s.race=#race_player);
ExecList(20,
//s.this:tClearFire;
//s.this:tMoveTo(E.Ship,2,0);
s.this:tFireTo(E.Ship,2);
);
);
:end
END

RULE event FatalDamaged
condition E.ship=m.team1_leader;
:action
SelectShips(20, s.race=#race_spacetech);
if(AllNumOf(20)>0, m.team1_leader:=Pick(20), ChangeState(noTeam1,0));

LocalEvent(GetTarget1);
:end
END

RULE event FatalDamaged
condition E.ship=m.team0_leader;
:action
SelectShips(10, s.race=#race_player);
if(AllNumOf(10)>0, m.team0_leader:=Pick(10), ChangeState(noTeam0,0));

LocalEvent(GetTarget0);
:end
END

RULE event FatalDamaged
:action
if(E.ship=m.mainTarget0,
SelectShips(10, s.race=#race_player);
if(AllNumOf(10)>0, m.mainTarget:=Pick(10), ChangeState(noTeam1,0));
LocalEvent(GetTarget0);
);

if(E.ship=m.mainTarget1,
SelectShips(20, s.race=#race_spacetech);
if(AllNumOf(20)>0, m.mainTarget:=Pick(20), ChangeState(noTeam0,0));
LocalEvent(GetTarget1);
);

:end
END

RULE event StartAutoCamera
:action
guiSelect(0);
auto_camera := 1;
camGoRound(1);
timer(auto_ChangeView, 1, 0);
:end
END

RULE event StopAutoCamera
:action
auto_camera := 0;
auto_fatalship := 0;
camGoRound(2);
guiSelect(3);
uQuitMission(1);
:end
END

RULE event auto_ChangeView
condition auto_camera
:action
clearTimer(auto_ChangeView);
clearTimer(auto_camShift);

select(0, S.ship & S.damage<90);
sh := pick(0);

if (auto_fatalship,
enem := auto_fatalship;
auto_camdur := 15
,
if (select(1, S.ship & S.damage<90 & (isShot(sh, S.this) | isShot(S.this, sh)))=0,
select(1, S.ship & S.damage<90),
0);
enem := pick(1);
Debug("enem is ", enem);
enem:selected := 1;
auto_camdur := rnd(5,12));

camMoveAndTurn(sh, rnd(1,4)*sh:radius, enem, rnd(-30,30), 3);
timer(auto_CamShift, 3, 0);

if (tripleHead()=2,
tripm := if(rnd()<0.5, 1, 0);
camTripleMode(tripm);
triprnd := if(tripm=0,0.5,0.8)
,
triprnd := 0.2);

if (auto_fatalship=0 & rnd()<triprnd,
if (camViewedBoat(),
0,
if (select(2, S.bomber),
camWeaponView(pick(2):launcherweapon),
0))
,
0);

auto_fatalship := 0;
:end
END

RULE event auto_CamShift
condition auto_camera
:action
camShift(rnd(-30,30), rnd(-30,30), 0, 1.3*auto_camdur);
timer(auto_ChangeView, auto_camdur, 0);
:end
END

RULE event Exploding
condition auto_camera
:action
auto_fatalship := E.ship;
localEvent(auto_ChangeView, 0);
:end
END

END //STATE battle

STATE noTeam1

RULE event In
:action
:end
END

END //STATE noTeam1

STATE noTeam0

RULE event In
:action
:end
END

END //STATE noTeam1

END //MACHINE "AI"

What i did was.
I made extacly the same setup of ships, but in the default mode in the Skirmisher.
And then first copy-pasted the event firemissile from the 1_default_ai:

Code: [Select]
RULE event FireMissile
:action
Debug("FireMissile");
if(isValid(m.AITeam_leader)&Not(m.AITeam_leader:wreck)&IsValid(m.mainTarget)&Not(m.mainTarget:wreck),
AIFleetL5:=GetFreeSel();
SelectShips(AIFleetL5, s.race=#race_spacetech);
ExecList(AIFleetL5,
s.this:tClearFire;
s.this:tSetForbid(#FORBID_FIRE_MISSILE);  //we don't want AI to mess with it
AIMissileL:=GetFreeSel();
SelectDevices(AIMissileL, s.this, s.weapon & s.working & InSet(s.this, 5) & s.count!=0); //missiles & e-bombs
ExecList(AIMissileL,
s.this:contFire:=1; //burst missile fire
ActivateDevice(S.this, 1);
TargetWeapon(S.this, m.mainTarget);
);
DeleteSelect(AIMissileL);
);
DeleteSelect(AIFleetL5);
,
LocalEvent(FatalDamaged);
);
:end
END

After that i then adjusted the parameters like so:

Code: [Select]
MACHINE "AI"

STATE battle

RULE event In
:action

m.mainTarget0:=0;
m.mainTarget0:=1;
localEvent(StartAutoCamera, 0);

timer(StopAutoCamera, 600, 0);

SelectShips(20, s.race=#race_spacetech);
if(AllNumOf(20)>0, m.team1_leader:=Pick(20), ChangeState(noTeam1,0));

ExecList(20,
MakeFullyKnown(s.this);
FreezeReconState(s.this, #race_player, 1);
FreezeReconState(s.this, #race_Player, 1);
);

SelectShips(10, s.race=#race_player);

if(AllNumOf(20)>0, m.team0_leader:=Pick(10), ChangeState(noTeam0,0));
ExecList(10,
MakeFullyKnown(s.this);
FreezeReconState(s.this, #race_spacetech, 1);
FreezeReconState(s.this, #race_Player, 1);
);
m.mainTarget:=Pick(10);

//GuiSelect(3);

LocalEvent(GetTarget0);
LocalEvent(GetTarget1);
Delay(0,5,LocalEvent(Tick),0);
:end
END

RULE event GetTarget1
condition isValid(m.team1_leader)
:action
SelectShips(10, s.race=#race_player);
if(AllNumOf(10)>0, m.mainTarget1:=PickMax(10, 1 / distance(s.this, m.team1_leader)), ChangeState(noTeam0,0));

LocalEvent(FireTo1);
:end
END

RULE event GetTarget0
condition isValid(m.team0_leader)
:action
SelectShips(20, s.race=#race_spacetech);
if(AllNumOf(20)>0, m.mainTarget0:=PickMax(20, 1 / distance(s.this, m.team0_leader)), ChangeState(noTeam1,0));

LocalEvent(FireTo0);
:end
END


RULE event FireTo1
:action
if(isValid(m.team1_leader)&isValid(m.mainTarget1),
SelectShips(20, s.race=#race_spacetech);
ExecList(20,
s.this:tClearFire;
s.this:tMoveTo(m.mainTarget,1,0);
s.this:tFireTo(m.maintarget,1);
),
LocalEvent(FatalDamaged, E.ship=m.team1_leader)
);
:end
END

RULE event FireTo0
:action
if(isValid(m.team0_leader)&isValid(m.mainTarget0),
SelectShips(10, s.race=#race_player);
ExecList(10,
s.this:tClearFire;
s.this:tMoveTo(m.mainTarget0,1,0);
s.this:tFireTo(m.maintarget0,1);
),
LocalEvent(FatalDamaged, E.ship=m.team0_leader)
);
:end
END

RULE event FireMissile
:action
Debug("FireMissile");
if(isValid(m.team1_leader)&isValid(m.mainTarget1),
SelectShips(20, s.race=#race_spacetech);
ExecList(20,
s.this:tClearFire;
s.this:tSetForbid(#FORBID_FIRE_MISSILE);  //we don't want AI to mess with it
AIMissileL:=GetFreeSel();
SelectDevices(AIMissileL, s.this, s.weapon & s.working & InSet(s.this, 5) & s.count!=0); //missiles & e-bombs
ExecList(AIMissileL,
s.this:contFire:=1; //burst missile fire
ActivateDevice(S.this, 1);
TargetWeapon(S.this, m.mainTarget);
);
DeleteSelect(AIMissileL);
);
DeleteSelect(ExecList(20,);
,
LocalEvent(FatalDamaged);
);
:end
END

RULE event FireMissile
:action
Debug("FireMissile");
if(isValid(m.team0_leader)&isValid(m.mainTarget0),
SelectShips(10, s.race=#race_player);
ExecList(10,
s.this:tClearFire;
s.this:tSetForbid(#FORBID_FIRE_MISSILE);  //we don't want AI to mess with it
AIMissileL:=GetFreeSel();
SelectDevices(AIMissileL, s.this, s.weapon & s.working & InSet(s.this, 5) & s.count!=0); //missiles & e-bombs
ExecList(AIMissileL,
s.this:contFire:=1; //burst missile fire
ActivateDevice(S.this, 1);
TargetWeapon(S.this, m.mainTarget);
);
DeleteSelect(AIMissileL);
);
DeleteSelect(ExecList(10);
,
LocalEvent(FatalDamaged);
);
:end
END

RULE event ShieldDown
condition E.Ship:race=#race_player
:action
if(isValid(m.team1_leader)&isValid(E.ship),
SelectShips(20, s.race=#race_spacetech);
ExecList(20,
//s.this:tClearFire;
//s.this:tMoveTo(E.Ship,2,0);
s.this:tFireTo(E.Ship,2);
);
);
:end
END

RULE event ShieldDown
condition E.Ship:race=#race_spacetech
:action
if(isValid(m.team0_leader)&isValid(E.ship),
SelectShips(20, s.race=#race_player);
ExecList(20,
//s.this:tClearFire;
//s.this:tMoveTo(E.Ship,2,0);
s.this:tFireTo(E.Ship,2);
);
);
:end
END

RULE event FatalDamaged
condition E.ship=m.team1_leader;
:action
SelectShips(20, s.race=#race_spacetech);
if(AllNumOf(20)>0, m.team1_leader:=Pick(20), ChangeState(noTeam1,0));

LocalEvent(GetTarget1);
:end
END

RULE event FatalDamaged
condition E.ship=m.team0_leader;
:action
SelectShips(10, s.race=#race_player);
if(AllNumOf(10)>0, m.team0_leader:=Pick(10), ChangeState(noTeam0,0));

LocalEvent(GetTarget0);
:end
END

RULE event FatalDamaged
:action
if(E.ship=m.mainTarget0,
SelectShips(10, s.race=#race_player);
if(AllNumOf(10)>0, m.mainTarget:=Pick(10), ChangeState(noTeam1,0));
LocalEvent(GetTarget0);
);

if(E.ship=m.mainTarget1,
SelectShips(20, s.race=#race_spacetech);
if(AllNumOf(20)>0, m.mainTarget:=Pick(20), ChangeState(noTeam0,0));
LocalEvent(GetTarget1);
);

:end
END


But there's no change. I've tried a number of other changes including, the" tClearForbid(#FORBID_FIRE) clears all of the FIRE inhibitions".
Described in page 99 of the manual;

>   obj:tClearForbid(flags);
It deletes the given inhibition(s), and leaves the rest unchanged. The delete is hierarchic, that is, e.g. tClearForbid(#FORBID_FIRE) clears all of the FIRE inhibitions, or e.g. the FORBID_MOTION_MOTIVATION clears the CLOSE and AWAY inhibitions too. If the flags is 0, it deletes all the inhibitions.

I am a complete scripting noob so it might also just be rubbish. ::)
« Last Edit: July 21, 2011, 17:23:24 by Blazar »