March 28, 2024, 09:00:17

Author Topic: The AI and You  (Read 80095 times)

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #25 on: September 25, 2011, 05:16:36 »
Okie dokie, thanks for the suggestion!
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #26 on: September 25, 2011, 22:19:29 »
Well... the problem is STILL persisting, blasted little...  >:(

Before you ask for the default_ai.mach, i have no clue what file exactly your talking about. do you mean from OTHER missions i have? or the 11_default_ai.mach?  ???

Sorry i seem to be as stumped as... well... a stump... but i get easily mixed up over things... you can thank the four letter noun 'ADHD' for that...  :P
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: The AI and You
« Reply #27 on: September 26, 2011, 00:03:08 »
you wrote this:

MACHINE "INNER_AI"
   STATE Start
      RULE event in
         :action
            SetAreaAbs(0, <-4000> , <-1000> , <-500> , <2250>);
            //We declare here the areas in the scene.
         :end
      END

   //For example, we want to boot the ai when one of the players ships reach the 0 area
   RULE event AreaEntered
      condition e.ship:race=#race_player&e.area=0
         :action
            M:GetMachine("INNER_AI"):ChangeState(Battle,
                                       e.ownMachine := M:GetMachine("INNER_AI");
                                       e.oRace := #race_raptor;
                                       e.oRaceList := -1;
                                       e.oShipList := -1;
                                       e.eRace := #race_player;
                                       e.eRaceList := -1;
                                       e.eShipList := -1;
                                       e.parentMachine := M:GetMachine("AI");
                                    );
            //Simple declaration of the AI, this will make the raptor ships launch towards the player ships.
         :end
      END
   END
END


MACHINE "INNER_AI"
#include "default_ai.mach"
END

I meant that "default_ai.mach" file, the one you've included there.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #28 on: September 26, 2011, 00:26:10 »
OH that one!

I re-labeled it...  :-X

heres what i put:

MACHINE "INNER_AI"
#include "11_default_ai.mach"
END

Should i have done that?  ???
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: The AI and You
« Reply #29 on: September 26, 2011, 00:27:53 »
wait.... in the file named 11_default_ai.mach there is a line including the file 11_default_ai.mach???

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #30 on: September 26, 2011, 02:33:48 »
Quote
wait.... in the file named 11_default_ai.mach there is a line including the file 11_default_ai.mach???

Do you mean the MAIN_AI for the second file? or the INNER_AI? that sounds so weird that you have to script to include the 11_default_ai.mach in the 11_default_ai.mach...  ???
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: The AI and You
« Reply #31 on: September 26, 2011, 03:08:06 »
No, you don't. That will certainly crash the game.

Please post here the contents of the file 11_default_ai.mach, the one you included in the Machine "INNER_AI"

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #32 on: September 26, 2011, 21:37:06 »
Ok, so to sum it up, you basically include the AI that the skirmisher generated in the INNER_AI. Right?

anyway, i can't cram it in all at once, so ill give it to you in chunks, heres the first chunk.

Code: [Select]
MACHINE "AI"
STATE battle
RULE event In
:action
AIFleetL1:=GetFreeSel();
SelectShips(AIFleetL1, s.race=#race_raptor);
if(AllNumOf(AIFleetL1)>0, m.AITeam_leader:=PickMax(AIFleetL1, 1 / s.this:tGetMaxVelocity()), ChangeState(noTeam1,0)); //slowest ship is AI leader
//for cloaking ships, we will have to change code below
ExecList(AIFleetL1,
MakeFullyKnown(s.this);
FreezeReconState(s.this, #race_player, 1);
);
PlayerFleetL1:=GetFreeSel();
SelectShips(PlayerFleetL1, s.race=#race_player);
ExecList(PlayerFleetL1,
MakeFullyKnown(s.this);
FreezeReconState(s.this, #race_raptor, 1);
);
m.PShipsCount:= AllNumOf(PlayerFleetL1);
//time to turn on defence systems in order of importance
ExecList(AIFleetL1,
EnergyLeft:=s.this:availSuppForDevices;
TempEcmL := GetFreeSel();
TempEccmL := GetFreeSel();
TempCloakL := GetFreeSel();
TempSensorL := GetFreeSel();
If(SelectDevices(TempEcmL, s.this, s.working & InSet(s.this, 16)), //ecm
Ecm:=PickFirst(TempEcmL);
If(EnergyLeft>=Ecm:energyIn,
ActivateDevice(Ecm, 1);
EnergyLeft:=EnergyLeft-Ecm:energyIn;
);
);
If(SelectDevices(TempEccmL, s.this, s.working & InSet(s.this, 17)), //eccm
Eccm:=PickFirst(TempEccmL);
If(EnergyLeft>=Eccm:energyIn,
ActivateDevice(Eccm, 1);
EnergyLeft:=EnergyLeft-Eccm:energyIn;
);
);
If(SelectDevices(TempCloakL, s.this, s.working & InSet(s.this, 9)), //cloaking also give some protection
Cloak:=PickFirst(TempCloakL);
If(EnergyLeft>=Cloak:energyIn,
ActivateDevice(Cloak, 1);
EnergyLeft:=EnergyLeft-Cloak:energyIn;
);
);
//If(SelectDevices(TempSensorL, s.this, s.working & InSet(s.this, 18)), //sensor, need for cloakers
// Sensor:=PickFirst(TempSensorL);
// If(EnergyLeft>=Sensor:energyIn,
// ActivateDevice(Sensor, 1);
// EnergyLeft:=EnergyLeft-Sensor:energyIn;
// );
//);
DeleteSelect(TempEcmL);
DeleteSelect(TempEccmL);
DeleteSelect(TempCloakL);
DeleteSelect(TempSensorL);
);
m.AITeam_leader:tRequestShipInRangeEvent(3,3);  //to know when we are close enough to call realBattle state
DeleteSelect(AIFleetL1);
DeleteSelect(PlayerFleetL1);
Delay(0,2,LocalEvent(GetClosestTarget),0);
:end
END
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #33 on: September 26, 2011, 21:38:45 »
And heres the second chunk....

Code: [Select]
RULE event GetClosestTarget
condition isValid(m.AITeam_leader)&not(m.AITeam_leader:wreck)
:action
Debug("GetClosestTarget");
PlayerFleetL2:=GetFreeSel();
SelectShips(PlayerFleetL2, s.race=#race_player);
if(AllNumOf(PlayerFleetL2)>0, TempMainTarget:=PickMax(PlayerFleetL2, 1 / distance(s.this, m.AITeam_leader)), ChangeState(noTeam0,0));
if(m.mainTarget!=TempMainTarget, // to avoid cpu overhead becouse of tick
Debug("New target");
m.mainTarget:=TempMainTarget;
LocalEvent(EvaluateAIFleet);
LocalEvent(FireMissile);
LocalEvent(MoveInFormation);
);
DeleteSelect(PlayerFleetL2);
:end
END

RULE event EvaluateAIFleet //evaluate AI fleet missile capabilities
name "evaluateAI"
:action
Debug("EvaluateAIFleet");
Disable("evaluateAI"); //We call it only once
AIFleetL3:=GetFreeSel();
SelectShips(AIFleetL3, s.race=#race_raptor);
MissCap:=0;
ExecList(AIFleetL3,
AIMissileDL:=GetFreeSel();
SelectDevices(AIMissileDL, s.this, s.weapon & s.working & InSet(s.this, 5) & s.count>1);
MissCap := MissCap + AllNumOf(AIMissileDL);
DeleteSelect(AIMissileDL);
);
if((MissCap/(m.PShipsCount+1))>0.4,
LocalEvent(SendAIBombers,e.cover:=1); //with enough missiles, we send in fighters early to saturate enemy flak, leaving only 1 squad for anti-missile defence
,
LocalEvent(SendAIBombers,e.cover:=10); //else we leave all fighters on defence
);
DeleteSelect(AIFleetL3);
:end
END

RULE event MoveInFormation
:action
if(IsValid(m.AITeam_leader)&Not(m.AITeam_leader:wreck)&IsValid(m.mainTarget)&Not(m.mainTarget:wreck),
AIFleetL4 := GetFreeSel();
SelectShips(AIFleetL4, s.race=#race_raptor);
//RemoveItem(AIFleetL4, m.AITeam_leader); //formation works worse then simple move
//if(NumOf(AIFleetL4)>0,
// m.AITeam_leader:tSetFormation(2, 1);
// ExecList(AIFleetL4,
// S.this:tSetForbid(#FORBID_MOTION_MOTIVATION_AWAY);
// S.this:tFollow(m.AITeam_leader, 2000, 10);
// );
//);
ExecList(AIFleetL4,
s.this:tSetForbid(#FORBID_MOTION_MOTIVATION_AWAY);
SetAbsSpeed(s.this, m.AITeam_leader:tGetMaxVelocity());
s.this:tMoveTo(m.mainTarget, 2, 0);
);
DeleteSelect(AIFleetL4);
,
LocalEvent(FatalDamaged);
);
:end
END

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

Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #34 on: September 26, 2011, 21:42:04 »
The third chunk....

Code: [Select]
RULE event SendAIBombers
:action
Debug("Send Bombers");
PlayerFleetL6:=GetFreeSel();
SelectShips(PlayerFleetL6, s.race=#race_player);
ExecList(PlayerFleetL6,
WGDevL:=GetFreeSel();
SelectDevices(WGDevL, s.this, s.this:damage<100&InSet(S.this, 70));  //focusing on weapon generators
if(isValid(PickFirst(WGDevL)), FocusDevice(PickFirst(WGDevL), #race_raptor, 1));
DeleteSelect(WGDevL);
);
DeleteSelect(PlayerFleetL6);
AIFleetL6:=GetFreeSel();
SelectShips(AIFleetL6, s.race=#race_raptor);
ExecList(AIFleetL6,
s.this:tSetForbid(#FORBID_FIRE_BOMBER);   //we don't want AI to mess with it as well
AIBombersL:=GetFreeSel();
HostShip:=s.this;
NumofCover:=0;
SelectDevices(AIBombersL, s.this, s.weapon&s.working&s.count!=0&InSet(s.this,22));  //fighters by SET
ExecList(AIBombersL,
ActivateDevice(s.this, 1);
if(NumofCover<e.cover,
NumofCover:=NumofCover+1;
WeaponMode(s.this,3,HostShip);
,
WeaponMode(S.this,5,m.mainTarget);
);
);
SelectDevices(AIBombersL, s.this, s.weapon&s.working&s.count!=0&InSet(s.this,20));  //then gunboats by SET
ExecList(AIBombersL,
ActivateDevice(s.this, 1);
if(NumofCover<e.cover,
NumofCover:=NumofCover+1;
WeaponMode(s.this,3,HostShip);
,
WeaponMode(S.this,5,m.mainTarget);
);
);
SelectDevices(AIBombersL, s.this, s.weapon&s.working&s.count!=0&InSet(s.this,21));  //then bombers by SET
ExecList(AIBombersL,
ActivateDevice(s.this, 1);
if(NumofCover<e.cover,
NumofCover:=NumofCover+1;
WeaponMode(s.this,3,HostShip);
,
WeaponMode(S.this,5,m.mainTarget);
);
);
);
DeleteSelect(AIFleetL6);
:end
END

RULE event Tick
:action
// basic energy management
Debug("tick battle");
AIFleetL7:=GetFreeSel();
SelectShips(AIFleetL7, s.race=#race_raptor);
ExecList(AIFleetL7,
if(s.this:reserveLevel>25,  //full power to weapons, however we leave reserve for shield augmenting
s.this:tEnergyMode(1, 2);
,
s.this:tEnergyMode(1, 0);
);
);
DeleteSelect(AIFleetL7);
LocalEvent(GetClosestTarget); //during battle we constantly update closest target
:end
END
Tick 6

RULE event CO_ShipInRange
:action
Debug("In range");
ChangeState(realBattle,0) //time to close in action
:end
END

RULE event FatalDamaged
:action
Debug("battleFatalDamaged");
if(e.ship:Race=#race_player,
m.PShipsCount:=m.PShipsCount-1;
if(e.ship=m.mainTarget,
LocalEvent(GetClosestTarget);
);
,
if(e.ship=m.AITeam_leader,
AIFleetL8:=GetFreeSel();
SelectShips(AIFleetL8, s.race=#race_raptor);
if(AllNumOf(AIFleetL8)>0, m.AITeam_leader:=PickMax(AIFleetL8, 1 / s.this:tGetMaxVelocity()), ChangeState(noTeam1,0));
DeleteSelect(AIFleetL8);
//LocalEvent(MoveInFormation);
LocalEvent(GetClosestTarget);
);
);
:end
END

RULE event out //disband formation
:action
if(isValid(m.AITeam_leader)&Not(m.AITeam_leader:wreck)&IsValid(m.mainTarget)&Not(m.mainTarget:wreck),
AIFleetL9 := GetFreeSel();
SelectShips(AIFleetL9, s.race=#race_raptor);
ExecList(AIFleetL9,
SetAbsSpeed(s.this, s.this:tGetMaxVelocity());
s.this:tMoveTo(m.mainTarget, 2, 0);
);
DeleteSelect(AIFleetL9);
);
:end
END

END //STATE battle

STATE realBattle

RULE event In
:action
Disable("latertick");
//just precaution if something changed during switching states
if(Not(isValid(m.AITeam_leader))|m.AITeam_leader:wreck,
AIFleetL1:=GetFreeSel();
SelectShips(AIFleetL1, s.race=#race_raptor);
if(AllNumOf(AIFleetL1)>0, m.AITeam_leader:=PickMax(AIFleetL1, 1 / s.this:tGetMaxVelocity()), ChangeState(noTeam1,0)); //slowest ship is AI leader
DeleteSelect(AIFleetL1);
);
if(not(IsValid(m.mainTarget))|m.mainTarget:wreck,
PlayerFleetL1:=GetFreeSel();
SelectShips(PlayerFleetL1, s.race=#race_player);
if(AllNumOf(PlayerFleetL1)>0, m.mainTarget:=PickMax(PlayerFleetL1, 1 / distance(s.this, m.AITeam_leader)), ChangeState(noTeam0,0));
DeleteSelect(PlayerFleetL1);
);

m.AITeam_leader:tRequestShipInRangeEvent(2,3);  //to know when we are close enough to enable deflection and combat engines
Delay(0,1,LocalEvent(EvaluateAIFleet),0);
Delay(0,2,LocalEvent(GetMainTarget),0);
Delay(0,4,LocalEvent(GetSecondaryTarget),0);
Delay(0,6,LocalEvent(GetMissileTarget),0);
Delay(0,8,Enable("latertick"),0);
:end
END

RULE event EvaluateAIFleet
:action
AIFleetL2:=GetFreeSel();
SelectShips(AIFleetL2, s.race=#race_raptor);
AIShipSHBusterL:=GetFreeSel(); //shield and hull buster ships
AIShipDeviceBusterL:=GetFreeSel(); //device buster ships
ExecList(AIFleetL2,
AIDevBustDL:=GetFreeSel();
AISHBustDL:=GetFreeSel();
SelectDevices(AIDevBustDL, s.this, s.weapon & s.working & s.deviceValue=1 & s.count!=0);
SelectDevices(AISHBustDL, s.this, s.weapon & s.working & (s.hullValue=1 | s.shieldValue=1) & s.count!=0);
SubList(AIDevBustDL, AISHBustDL); // remove multipurpose weapons
if(NumOf(AIDevBustDL)>NumOf(AISHBustDL),
AddItem(AIShipDeviceBusterL, s.this); // ships with primary device busting capablities
,
AddItem(AIShipSHBusterL, s.this); // ships with primary hull and shield busting capablities
);
//DeleteSelect(AIMissileDL);
DeleteSelect(AIDevBustDL);
DeleteSelect(AISHBustDL);
);
DeleteSelect(AIFleetL2);
LocalEvent(FocusOnDevices);
:end
END
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #35 on: September 26, 2011, 21:43:15 »
The fourth chunk (hope im not overwhelming you)

Code: [Select]
RULE event Tick
Name "latertick"
:action
// basic energy management
Debug("realBattle tick");
AIFleetL3:=GetFreeSel();
SelectShips(AIFleetL3, s.race=#race_raptor);
ExecList(AIFleetL3,
if(s.this:reserveLevel>25,  //full power to weapons, hovever we leave reserve for shield augmenting
s.this:tEnergyMode(1, 2);
,
s.this:tEnergyMode(1, 0);
);
if(s.this:shieldLevel<50, //boost shield when low
s.this:tEnergyMode(2, 2);
,
s.this:tEnergyMode(2, 0);
);
);
if(isValid(m.AITeam_leader)&isValid(m.mainTarget)&not(m.mainTarget:wreck)&not(m.AITeam_leader:wreck),
if(range(m.AITeam_leader,m.mainTarget)>3, //main target running away
LocalEvent(GetMainTarget);
);
);
if(isValid(m.secondaryTarget)&isValid(m.mainTarget)&not(m.mainTarget:wreck)&not(m.secondaryTarget:wreck),
if(range(m.secondaryTarget,m.mainTarget)>3, //secondary target running away
LocalEvent(GetSecondaryTarget);
);
);
if(isValid(m.missileTarget)&not(m.missileTarget:wreck),
InBlastRange:=0;
AIFleetL4:=GetFreeSel();
SelectShips(AIFleetL4, s.race=#race_raptor);
ExecList(AIFleetL4,
if(range(m.missileTarget,s.this)=2,
InBlastRange:=1;
);
);
DeleteSelect(AIFleetL4);
if(InBlastRange,LocalEvent(GetSecondaryTarget));  //some of our ships are in blast range - retargeting missiles
);
DeleteSelect(AIFleetL3);
:end
END
Tick 6

RULE event CO_ShipInRange
:action
Debug("In range");
AIFleetL5:=GetFreeSel();
SelectShips(AIFleetL5, s.race=#race_raptor);
ExecList(AIFleetL5,
EnableDodge(s.this, 1);
s.this:tEngineMode(2);
);
DeleteSelect(AIFleetL5);
:end
END

RULE event CO_DeviceDestroyed
condition e.device:owner:race=#race_player&DeviceFocused(e.device,#race_raptor)
:action
LocalEvent(FocusOnDevices);
LocalEvent(GetSecondaryTarget);
:end
END

RULE event ShieldDown
condition e.ship:race=#race_player
:action
LocalEvent(FireMainShield);
:end
END

RULE event ShieldUp
condition E.ship:race=#race_player
:action
LocalEvent(FireMainShield);
:end
END

RULE event FocusOnDevices
:action
PlayerFleetL6:=GetFreeSel();
SelectShips(PlayerFleetL6, s.race=#race_player);
ExecList(PlayerFleetL6,
WGDevL:=GetFreeSel();
SelectDevices(WGDevL, s.this, s.this:damage<100&InSet(S.this, 70));  //focusing on weapon generators
if(isValid(PickFirst(WGDevL)), FocusDevice(PickFirst(WGDevL), #race_raptor, 1));
DeleteSelect(WGDevL);
);
DeleteSelect(PlayerFleetL6);
:end
END

RULE event GetMainTarget
:action
Debug("GetMainTarget");
if(isValid(m.AITeam_leader)&not(m.AITeam_leader:wreck),
PlayerFleetL7:=GetFreeSel();
SelectShips(PlayerFleetL7, s.race=#race_player&range(s.this,m.AITeam_leader)=2&s.this:damage>35); //if there is heavy damaged ship nearby, first finish it off
if(AllNumOf(PlayerFleetL7)>0,
m.mainTarget:=PickMax(PlayerFleetL7,s.this:damage);
,
SelectShips(PlayerFleetL7, s.race=#race_player&range(s.this,m.AITeam_leader)=2); //else we pick most dangerous nearby ship
if(AllNumOf(PlayerFleetL7)>0,
m.mainTarget:=PickMax(PlayerFleetL7, (s.this:tDamage(m.AITeam_leader,2,1)+s.this:tDamage(m.AITeam_leader,2,2)+s.this:tDamage(m.AITeam_leader,2,3)+s.this:tDamage(m.AITeam_leader,3,1)+s.this:tDamage(m.AITeam_leader,3,2)+s.this:tDamage(m.AITeam_leader,3,3)));
,
SelectShips(PlayerFleetL7, s.race=#race_player); //else we pick closest target
if(AllNumOf(PlayerFleetL7)>0, m.mainTarget:=PickMax(PlayerFleetL7, 1 / distance(s.this, m.AITeam_leader)), ChangeState(noTeam0,0));
);
);
ExecList(AIShipSHBusterL,
s.this:tMoveTo(m.mainTarget, 2, 0);
);
LocalEvent(FireMainHull);
LocalEvent(FireMainShield);
DeleteSelect(PlayerFleetL7);
,
LocalEvent(FatalDamaged, E.ship=m.AITeam_leader);
);
:end
END

RULE event GetSecondaryTarget
:action
Debug("GetSecondaryTarget");
if(NumOf(AIShipDeviceBusterL)>0,
if(isValid(m.mainTarget)&not(m.mainTarget:wreck),
PlayerFleetL8:=GetFreeSel();
SelectShips(PlayerFleetL8, s.race=#race_player&(range(s.this,m.mainTarget)=2|range(s.this,m.mainTarget)=3));  // we want to have main target in device buster ships artilery range
if(AllNumOf(PlayerFleetL8)>0, m.secondaryTarget:=PickMax(PlayerFleetL8, (s.this:tDamage(m.AITeam_leader,2,1)+s.this:tDamage(m.AITeam_leader,2,2)+s.this:tDamage(m.AITeam_leader,2,3)+s.this:tDamage(m.AITeam_leader,3,1)+s.this:tDamage(m.AITeam_leader,3,2)+s.this:tDamage(m.AITeam_leader,3,3))), m.secondaryTarget:=m.mainTarget);  //most dangerous opponent
DeleteSelect(PlayerFleetL8);
,
LocalEvent(GetMainTarget);
);
ExecList(AIShipDeviceBusterL,
s.this:tMoveTo(m.secondaryTarget, 2, 0);
);
,
m.secondaryTarget:=m.mainTarget;
);
LocalEvent(FireToSecondary);
:end
END

RULE event GetMissileTarget
:action
Debug("GetMissileTarget");
if(isValid(m.AITeam_leader)&not(m.AITeam_leader:wreck),
PlayerFleetL9:=GetFreeSel();
SelectShips(PlayerFleetL9, s.race=#race_player&range(s.this,m.AITeam_leader)>2);
if(AllNumOf(PlayerFleetL9)>0,
AIFleetL9:=GetFreeSel();
SelectShips(AIFleetL9, s.race=#race_raptor&s.this!=m.AITeam_leader);  // we don't want to have any AI ships in blast range
if(AllNumOf(AIFleetL9)>0,
ExecList(PlayerFleetL9,
PotentialTarget:=s.this;
ExecList(AIFleetL9,
if(range(PotentialTarget,s.this)=2,
RemoveItem(PlayerFleetL9, PotentialTarget);
);
);
);
);
DeleteSelect(AIFleetL9);
if(NumOf(PlayerFleetL9)>0,
m.missileTarget:=PickMax(PlayerFleetL9, 1 / distance(s.this, m.AITeam_leader));
LocalEvent(FireMissile);
);
);
DeleteSelect(PlayerFleetL9);
,
LocalEvent(FatalDamaged, E.ship=m.AITeam_leader);
);
:end
END

RULE event FireMainHull
:action
Debug("FireMainHull");
if(isValid(m.AITeam_leader)&isValid(m.mainTarget)&not(m.mainTarget:wreck)&not(m.AITeam_leader:wreck),
AIFleetL10:=GetFreeSel();
SelectShips(AIFleetL10, s.race=#race_raptor);
ExecList(AIFleetL10,
s.this:tSetForbid(#FORBID_FIRE);
s.this:tSetForbid(#FORBID_FIRE_BOMBER);
AIFleetWeaponL10:=GetFreeSel();
SelectDevices(AIFleetWeaponL10, s.this, S.working&S.weapon&s.count!=0&s.hullValue=1);
ExecList(AIFleetWeaponL10,
s.this:contFire:=1;
ActivateDevice(S.this, 1);
TargetWeapon(s.this, m.mainTarget);
);
DeleteSelect(AIFleetWeaponL10);
AIFleetBomberL10:=GetFreeSel();
SelectDevices(AIFleetBomberL10, s.this, s.hullValue=1&s.working&(Inset(s.this,20)|Inset(s.this,21)|Inset(s.this,22)));
ExecList(AIFleetBomberL10,WeaponMode(S.this,5,m.mainTarget));
DeleteSelect(AIFleetBomberL10);
);
DeleteSelect(AIFleetL10);
);
:end
END

RULE event FireMainShield
:action
Debug("FireMainShield");
if(isValid(m.AITeam_leader)&not(m.AITeam_leader:wreck),
if(isValid(m.mainTarget)&not(m.mainTarget:wreck),
AIFleetL11:=GetFreeSel();
SelectShips(AIFleetL11, s.race=#race_raptor);
ExecList(AIFleetL11,
AIFleetWeaponL11:=GetFreeSel();
SelectDevices(AIFleetWeaponL11, s.this, S.working&S.weapon&s.count!=0&s.hullValue=0&s.shieldValue=1);
ExecList(AIFleetWeaponL11,
s.this:contFire:=1;
ActivateDevice(S.this, 1);
if(m.mainTarget:isShielded,
TargetWeapon(s.this, m.mainTarget);
,
if(isValid(m.secondaryTarget)&not(m.secondaryTarget:wreck)
if(m.secondaryTarget:isShielded,
TargetWeapon(s.this, m.secondaryTarget);
,
PlayerFleetL11:=GetFreeSel();
SelectShips(PlayerFleetL11, s.race=#race_player&s.this:isShielded);
if(AllNumOf(PlayerFleetL11)>0,
TargetWeapon(s.this,PickMax(PlayerFleetL11, 1 / distance(s.this, m.AITeam_leader)));
);
);
,
LocalEvent(GetSecondaryTarget);
);
);
);
);
DeleteSelect(AIFleetL11);
,
LocalEvent(GetMainTarget);
);
);
:end
END

Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #36 on: September 26, 2011, 21:44:25 »
AND FINALLY the fifth chunk... (DANG thats a crap load of coding)

Code: [Select]
RULE event FireToSecondary
:action
Debug("FireToSecondary");
if(isValid(m.secondaryTarget)&not(m.secondaryTarget:wreck),
AIFleetL12:=GetFreeSel();
SelectShips(AIFleetL12, s.race=#race_raptor);
ExecList(AIFleetL12,
AIFleetWeaponL12:=GetFreeSel();
SelectDevices(AIFleetWeaponL12, s.this, S.working&S.weapon&s.count!=0&s.hullValue=0&s.shieldValue=0&s.DeviceValue=1);
ExecList(AIFleetWeaponL12,
s.this:contFire:=1;
ActivateDevice(S.this, 1);
TargetWeapon(s.this, m.secondaryTarget);
);
DeleteSelect(AIFleetWeaponL12);
AIFleetBomberL12:=GetFreeSel();
SelectDevices(AIFleetBomberL12, s.this, s.hullValue=0&s.shieldValue=0&s.DeviceValue=1&s.working&(Inset(s.this,20)|Inset(s.this,21)|Inset(s.this,22)));
ExecList(AIFleetBomberL12,WeaponMode(S.this,5,m.secondaryTarget));
DeleteSelect(AIFleetBomberL12);
);
DeleteSelect(AIFleetL12);
);
:end
END

RULE event FireMissile
:action
Debug("FireMissile");
if(IsValid(m.missileTarget)&Not(m.missileTarget:wreck),
AIFleetL13:=GetFreeSel();
SelectShips(AIFleetL13, s.race=#race_raptor);
ExecList(AIFleetL13,
s.this:tSetForbid(#FORBID_FIRE_MISSILE);
AIMissileL13:=GetFreeSel();
SelectDevices(AIMissileL13, s.this, s.weapon & s.working & InSet(s.this, 5) & s.count!=0); //missiles & e-bombs
ExecList(AIMissileL13,
s.this:contFire:=1;
ActivateDevice(S.this, 1);
TargetWeapon(S.this, m.missileTarget);
);
DeleteSelect(AIMissileL13);
);
DeleteSelect(AIFleetL13);
,
LocalEvent(FatalDamaged,E.ship=m.missileTarget);
);
:end
END

RULE event FatalDamaged
:action
Debug("realBattleFatalDamaged");
if(e.ship:Race=#race_player,
PlayerFleetL14:=GetFreeSel();
SelectShips(PlayerFleetL14, s.race=#race_player);
if(NumOf(PlayerFleetL14)>0,
if(e.ship=m.mainTarget,
LocalEvent(GetMainTarget);
);
if(e.ship=m.secondaryTarget,
LocalEvent(GetSecondaryTarget);
);
if(e.ship=m.misileTarget,
LocalEvent(GetMissileTarget);
);
,
ChangeState(noTeam0,0);
);
DeleteSelect(PlayerFleetL14);
,
RemoveItem(AIShipDeviceBusterL,e.ship);
RemoveItem(AIShipSHBusterL,e.ship);
if(e.ship=m.AITeam_leader,
AIFleetL14:=GetFreeSel();
SelectShips(AIFleetL14, s.race=#race_raptor);
if(AllNumOf(AIFleetL14)>0, m.AITeam_leader:=PickMax(AIFleetL14, 1 / s.this:tGetMaxVelocity()), ChangeState(noTeam1,0));
DeleteSelect(AIFleetL14);
Delay(0,1,LocalEvent(GetMainTarget),0);
Delay(0,3,LocalEvent(GetSecondaryTarget),0);
Delay(0,5,LocalEvent(GetMissileTarget),0);
);
);
:end
END

END //STATE realBattle

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"
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: The AI and You
« Reply #37 on: September 27, 2011, 00:36:27 »
Yeah... I found what the error was. The file you put here:

MACHINE "INNER_AI"
#include "11_default_ai.mach"
END

is not the one I meant by when I gave you the first example, but this file: http://arparso.de/nexus/forum/index.php/topic,222.msg1569.html#msg1569

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #38 on: September 27, 2011, 00:57:26 »
Aaaah... ok, glad you were able to figure it out!

I should applaud you for that, in fact i will!  :D

i might post a few more questions / problems i run into in the future here, im sure everyone will benefit from it.

Edit: THANK GOD! it works now! :D

Btw, going clear back to the first page of this topic...

About setting up an area that the AI will kick in if you have a ship go into it... can you make it visible in the editor? i want to make sure i have it in the right place... :-\

OH yeah, and another thing, can you code for a ship appear to be damaged when the mission starts? and where would you put that piece of coding?
« Last Edit: September 27, 2011, 01:06:16 by The_Small_Time_Modder »
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: The AI and You
« Reply #39 on: September 27, 2011, 05:52:24 »
area that appears on the editor: nope. You can, however, put a ship in those coordinates and if the radius of the ship is of a similar length to the ARTILLERY and COMBAT ones, then you can use the display options in the mission editor.

Ship appearing damaged: easy as pie. just meddle with this atribute: m.ship:damage := 0 to 100; where 0 means full health and 100 = death. I recommend applying this change just before making that ship appear, to keep the code clear.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #40 on: September 27, 2011, 23:11:25 »
1- can you set a nav-point in the editor to be the center of said area, then?

2- What if the ship is present in the first place? the ship im planning on applying this to i put in using the mission editor...
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: The AI and You
« Reply #41 on: September 27, 2011, 23:18:03 »
This is a bit of a hack, but yeah, you can put a navpoint in the center of an area. In fact, you can actually put an area in relation to a navpoint (way more efficient). Use this command:
Code: [Select]
SetArea(index, centeritem, radius);
Where centeritem can be a navpoint.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #42 on: September 27, 2011, 23:38:26 »
two questions about that coding...

1- what would the index be? the area in question?

2- you would apply that 'centeritem' thing to an EXISTING navpoint, correct? also how do you make it so that such a navpoint is VISIBLE when you test\play the mission?
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #43 on: September 28, 2011, 03:05:03 »
Going slightly off topic here for a moment...

3- For objectives, what would be the proper code to have it so you need to have a commando squad enter a ship and scan it?
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: The AI and You
« Reply #44 on: September 28, 2011, 09:45:36 »
1)   Yes, this is the area in question. It'll be a number from 0 to 9 (You can only set up ten of these areas I think).

2)   For making it visible during the test play, put this in the SceneInit rule...

    MakeFullyKnown(M.AreaNav);
    FreezeReconState(M.AreaNav,1);

    Where M.AreaNav will be the name you assigned to the navpoint you want to display.

3)   Just to clarify, you'd like some coding to update an objective once your commandos have got onboard an enemy ship and survived long enough to "scan" it? I'll have to a bit of digging for something like that...
Better to look the fool by asking, then prove them right with ignorance.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #45 on: September 29, 2011, 00:12:07 »
Hi dragon, good to see you chipping in!  :)

3a) Im simply looking for code that will make that an OBJECTIVE

3b) i didnt even think of the updating objective part, that i would also gladly appreciate, i dont want to just destroy the raptor ships i have hiding about on the mission im focusing on currently.

EDIT: Problem...

The MakeFullyKnown command wants a ship, not a nav point... you sure thats right?

heres what i have...
Code: [Select]
MakeFullyKnown(SOS);
FreezeReconState(SOS,1);

SOS is the name i have for the navigation point, did i mess up on something?  ???
« Last Edit: September 29, 2011, 00:51:42 by The_Small_Time_Modder »
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: The AI and You
« Reply #46 on: September 29, 2011, 02:31:23 »
Let us see the declaration of the navpoint, too.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: The AI and You
« Reply #47 on: September 29, 2011, 09:46:54 »
Ok, for the sake of argument, you've added a navpoint via the mission editor called "SOS". In order for the game to be able to see and interact with it, then it'll need a variable name. To assign one, add the following to the SceneInit rule...

  M.SOS:=GetSceneObj("SOS");

So our previous commands to make it visible would now read...

    MakeFullyKnown(M.SOS);
    FreezeReconState(M.SOS,1);


Quick question or two, have you visited the NexusWiki (http://nexusthegame.net/wiki/Beginner%27s_Guide#Nexus:TJI_Basic_mission-making_walkthrough) and read through the beginners tutorials? You'll find what you need on adding and updating Objectives in there. The only bit you won't find there is a trigger for the update...

Code: [Select]
       RULE event Breached
condition E.location=[size=15pt][color=red]1[/color][/size]&E.ship:launcherWeapon:owner=[size=15pt][color=red]2[/color][/size]
:action

:end
END

1= The variable name that you declared for the raptor ship.
2= The variable name that you declared for the player ship.

Not overly sure about this, but if you have several ships that carry marines, then try changing the "2" to "race_Player ". This rule should hopefully cover all your ships then.
Better to look the fool by asking, then prove them right with ignorance.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #48 on: September 29, 2011, 22:16:29 »
Excellent, i got the navpoint working now...

EDIT: i got even better news! the AI for the raptors is now working exactly as i wanted it to in the first place! I had to remove the inclusion of the default AI from the .mission file.

now that i know it works i intend to add more raptor ships into the area. and add large asteroids to hide them.
« Last Edit: September 29, 2011, 22:35:27 by The_Small_Time_Modder »
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
Re: The AI and You
« Reply #49 on: September 29, 2011, 23:06:04 »
OK, the AI part as far as i know is done.

Now i want to have the music change from contact ghost (the one i have playing in the mission) to contact raptor when the AI turns on. Anyone know exactly how?
Epic win = when bullets dodge YOU.

Nothing can contend with that. Unless if you can travel through time and space.