September 16, 2019, 10:05:53

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

Offline The_Small_Time_Modder

  • Petty Officer
  • **
  • Posts: 126
  • Karma: 0
  • Watch out batman! here comes CHUCK NORRIS!
    • View Profile
The AI and You
« on: September 22, 2011, 02:29:37 »
I had a few questions on scripting the AI.

1. Can you set it so the AI activates when any ship you have enters a certain area in the scene?

2. How do you code for a fleet to enter the scene via jump?

And a question out of curiosity....

3. Could it be possible to create a program sort of like the trigger/condition/event programs found in editors of games, such as AOE 3, that can be used to easily create code for an AI? if so that could be a really neat tool. If not it was just an idea.  :-\
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 #1 on: September 22, 2011, 09:28:22 »
1- That can easily be done. Just create the areas and then use the AreaEntered event.
For example, let's have a look at this piece of code, using my default_AI as basis:

Code: [Select]
MACHINE "AI"
STATE Start
RULE event in
:action
SetAreaAbs(0, <x>, <y>, <z>, <radius>);
SetAreaAbs(1, <x>, <y>, <z>, <radius>);
SetAreaAbs(2, <x>, <y>, <z>, <radius>);
SetAreaAbs(3, <x>, <y>, <z>, <radius>);
//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 2 area
RULE event AreaEntered
condition e.ship:race=#race_player&e.area=2
:action
M:GetMachine("InnerAI"):ChangeState(Battle,
e.ownMachine := M:GetMachine("InnerAI");
e.oRace := #race_gorg;
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 gorg ships launch towards the player ships.
:end
END
END
END


MACHINE "InnerAI"
#include "defaultAI.mach"
END

2- You mean ip jump or gate jump?

3- I don't think I follow.... you mean like a more user-friendly IDE?

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 #2 on: September 22, 2011, 21:39:10 »
 2- More like an IP jump, sorry i didnt clarify that!  :(

 3- i think so, im talking about how some editors allow you to create triggers, then create conditions (what sets off the trigger) and events (the result of the trigger) to make an in-depth mission, i have quite a bit of experience with that such system thanks to the editor from starcraft II (excellent editor in my opinion, i figured it all out in less than two days!)

Edit: on a side note, would you put that coding IN the default_ai.mach? or make it a seperate .mach? i just dont want to wind up doing the wrong thing and end up stumped again. I hate it when i wind up like that. >:(

Edit #2: If you can make the program i was talking about earlier, that would be a true honor! i think you're an absolute genius with coding this stuff! :D

That includes Aparso, if you're reading this Aparso... YOU'RE AWESOME! :D
« Last Edit: September 22, 2011, 22:03:41 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 #3 on: September 23, 2011, 00:29:32 »
well... it COULD be done. But it'd mean a shitload of work... probably too much. Not a priority right now, actually...
Working with a single text file is simple enough, once you get used to it and find a proper environment to ease up on the things (I recommend notepad++)

About the other thing: yeah, this code is meant to go someplace else, a .mach file or inside the .mission one. Just take care that the path to the default_ai.mach file in the #include line is the correct one (that file is located on this forum. somewhere)

and the ip drive arrival:

first, select the ships to jump (for example, all the player ships), then go through the list applying the longRangeArrive(ship) command to each item of the list:
Code: [Select]
e.shipsToJump := getFreeSel();
SelectShips(e.shipsToJump, s.race = #race_player);
Execlist(e.shipsToJump,
longrangearrive(s.this);
);

Or you could issue that command to a ship in particular, for example, m.ship:
Code: [Select]
LongRangeArrive(m.ship);

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 #4 on: September 23, 2011, 00:35:16 »
Okie dokie, Thanks!

just a few more questions...

1. How would you code capturing a idle ship? (i.e. a battleship thats just floating around doing nothing, i tried this myself and fouled up...)

2. would you create a list for a specific group of ships to have the code you just stated affect it?

Edit: for #2, i have a group of raptor ships i specifically wanted to have jump in once the raptor ships that are present in the first place are destroyed, if that narrows your answer down...
« Last Edit: September 23, 2011, 00:51:57 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 #5 on: September 23, 2011, 03:20:47 »
1- if the ship has been wrecked, then no, it can't be done.

2- Creating a list is only one way. You can issue the command to an individual ship, from wherever you got that ship's identifier, but I found myself using lists and selections 90% of the time.

Edit for 2:
Yeah, that's very easy to do.
first, you need to store the ships that are to jump on a list, because I'm guessing that until they are called they'll remain dissaperead, right? (disappeared ships can't be selected)

So add this line in your sceneInit rule:

Code: [Select]
raptors := GetFreeSel();
selectShips(raptors, s.race = #race_raptor (or whatever race they are));

Then disappear the ships that you know will appear as reinforcements later on.

Then, keep an eye out for the event that all raptor ships have been taken out:

Code: [Select]
Rule Event FatalDamaged
condition e.ship:race=#race_raptor
:action
e.count := selectShips(0, s.race=#race_raptor);
if(e.count = 0,
m:Execlist(m.raptors, longRangeArrive(s.this)); //The M:execlist goes because the list raptors is stored in the mission block, and as such can only be accesed that way.
);
:end
END

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 #6 on: September 23, 2011, 03:37:34 »
Is it the same for a dynamic group? i put the ships in a dynamic group instead of having them dissappear in the coding. Or is it even possible with a dynamic group?  ???
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 #7 on: September 23, 2011, 04:18:29 »
What do you mean a dynamic group?

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 #8 on: September 23, 2011, 04:30:14 »
In the editor you can have a group of ships/objects become a dynamic group, it says so right in the modding manual...
i can even give you the page # and section.

Pg. 56  section 7.2.8

the result is that the objects dissappear from the game unless (i assume) called for by an event from the scripts.
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 #9 on: September 23, 2011, 06:03:11 »
oh yeah... the mystic dynamic block. I've been modding this game for about... 4 years now? and I still don't how the heck to work with that :P

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 #10 on: September 23, 2011, 06:30:29 »
Laugh out loud... XD

Hey, i just tested the 'Area activates AI' coding you provided for me earlier.

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

For some reason my finiky copy thinks what i put in red for you doesn't exist, what i put in lime green is what i predict it also thinks doesnt exist, any ideas?

Edit: The battleship i tried to code to be capturable wasnt a wreck, it was simply sitting there, like a sleeping duck, if you want to call it that ;)
« Last Edit: September 23, 2011, 06:33:50 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 #11 on: September 23, 2011, 17:33:55 »
Couple of things: you have two machines that are named the same, check that.
Also, you wrote this:

SetAreaAbs(0, <-4000> , <-1000> , <-500> , <2250>);

I put the "<,>" in my example to say what you were supposed to put in them, they don't have to be there!
It should be like this:
SetAreaAbs(0, -4000 , -1000, -500 , 2250);

The "<,>" are comparators, for example, putting 2>3 will return 0, and 4<8 will return 1. They are used in conditions and ifs

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 #12 on: September 23, 2011, 19:29:17 »
OH....

whoops!  ::)

my bad, i guess i shouldnt have put them there in the first place.

Ill take 'em off and try again, thanks for clearing that up man.  ;)

Edit: ok, thats been fixed, i also fixed the #include code (i didnt specify for which mission's AI i wanted to include, easy fix). But now its saying that the 11_default_ai.mach has an invalid keyword, and of all of the things it picked, it picked the very first word MACHINE. I hate how it somehow comes up with random errors like that. >:(

« Last Edit: September 23, 2011, 19:34: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 #13 on: September 23, 2011, 19:55:32 »
Can you give us some context?
where in the .mission file did you include the 11_default_ai.mach file? can you give us a short description of where each file is located and the contents of each?

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 #14 on: September 23, 2011, 22:01:01 »
Sure Mularac...

heres the top section of the .mission file....

MISSION 11
Name "The Atlantis"
DefLocation "ASTFLD_ARCTURUS IID" ((this is part of a custom system i made, one of three, the other two are Ouroboros and Nexor, after the games name, Nexus  ;) ))

OBJECTIVES
   1
   2
END

RULES

   RULE    event sceneInit
         :action
            SetSceneRadius(100000);      
      
            SetRelation(#race_player, #race_raptor, 2);
            SetRelation(#race_raptor, #race_player, 2);
            
            PShip.0 := GetSceneObj("Darkstar");
            PShip.1 := GetSceneObj("Vanguard");
            PShip.2 := GetSceneObj("Eringuard");
            PShip.3 := GetSceneObj("Kings Arch");

            EShip.0 := GetSceneObj("Highlander");
            EShip.1 := GetSceneObj("Skirmisher");
            EShip.2 := GetSceneObj("Stingray");
            EShip.3 := GetSceneObj("Hellstorm");
            
            Playmusic(21);
            
            GetMachine("Director"):ChangeState(IntroMovie, 0);
            GetMachine("Objectives"):ChangeState(monitor,0);
            GetMachine("AI"):ChangeState(battle,0);
            GetMachine("ATLANTIS_AI"):ChangeState(idle,0);
         :end
   END

   MACHINE "Director"

      STATE IntroMovie

         RULE   event In
               :action
               :end
         END
      END
   END
   
   #include "11_default_obj.mach"
   #include "11_default_ai.mach"      
   #include "11_atlantis_ai.mach"
   #include "11_inner_ai.mach"
                        
END

I let the explorer (the program used to look into files on your computer) order them all alphebetically in the missions file of the Skirmisher SP settings, here it is in a list... (exactly as it is in the folder)

11_atlantis_ai.mach (this AI controls the single vardrag explorer in the scene)
11_default_obj.mach (this is what the Skirmisher put in)
11_inner_ai.mach (The area activated AI that you suggested)
11_The Atlantis.mission (the file partly shown above)

Does that help you?  ???
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 #15 on: September 23, 2011, 23:24:01 »
What is the content of these files: "11_default_ai.mach" and "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 #16 on: September 24, 2011, 03:45:23 »
1-The contents of the 11_Default_AI.mach is exactly as the Nexus Skirmisher program made it, i havent even TOUCHED it.

2-Do you mean the Inner AI you talked about?  ???

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 #17 on: September 24, 2011, 03:50:42 »
I'm trying to figure out your error... If you could post more information about it it would be great. But my money is in the fact that you've named two machines the same. Check you don't have an other Machine named "AI" other than in the 11_default_AI.mach file

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 #18 on: September 24, 2011, 03:52:55 »
oddly enough i dont...   ???

Do you think i could simply debug it?  :-\

Edit: maybe this can help, this is the Error, word for word...

----------------------------------------------------------------

MISSION_EDITOR_DX9 INPUT ERROR

File: universe\mod_missions\11_default_ai.mach
Line: 1

>>>MACHINE<<< "AI"

(Press OK to quit)

Description: Invalid Keyword

-----------------------------------------------------------------

Again, i havent even TOUCHED the default_ai.mach for the mission, and i gave a seperate name to the inner_ai.mach ("INNER_AI")
« Last Edit: September 24, 2011, 03:59:03 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 #19 on: September 24, 2011, 05:01:32 »
You probably put an end where you weren't supposed to, or forgot to put one where it was supposed to be :P
What's the content of the "11_default_obj.mach" file? I think the error is in that file.

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 #20 on: September 24, 2011, 19:02:37 »
heres the file your asking for.

Code: [Select]
//Basic objective structure:
//mission terminates, if either one of the two sides has no ships left

MACHINE "Objectives"

//main STATE
//majority of code is executed here
STATE monitor
RULE event In
:action
//OBJECTIVE INITIALISATION

//make sure, that both objectives are counted as "primary objectives"
SetObjectivePrimary(1, 1);
SetObjectivePrimary(2, 1);

//make sure, that both objectives are counted as "uncompleted"
MissionObjective(1,#OBJECTIVE_UNCOMPLETED);
MissionObjective(2,#OBJECTIVE_UNCOMPLETED);
:end
END

//the even FatalDamaged gets executed every time, a ship is being evacuated or even destroyed
RULE event FatalDamaged
//it is only executed, if the FatalDamaged ship is a player ship
condition E.ship:race=#race_player
:action
//Selects all player ships
SelectShips(1, s.race=#race_player);

//IF there are no player ships left
//THEN change STATE to Mission_failed
If(AllNumOf(1)=0, ChangeState(Mission_failed,0));
:end
END

//the even FatalDamaged gets executed every time, a ship is being evacuated or even destroyed
RULE event FatalDamaged
//it is only executed, if the FatalDamaged ship is an enemy ship
condition E.ship:race=#race_raptor
:action
//Selects all enemy ships
SelectShips(2, s.race=#race_raptor);

//IF there are no enemy ships left
//THEN change STATE to Mission_won
If(AllNumOf(2)=0, ChangeState(Mission_won,0));
:end
END

END //STATE monitor

STATE Mission_failed

RULE event In
:action
//Show a "Mission_lost" title
Title(0,0,0,"Mission_lost");

//Set both objectives to "failed"
MissionObjective(1, #OBJECTIVE_FAILED);
MissionObjective(2, #OBJECTIVE_FAILED);

//wait 10 seconds before quitting the mission
Delay(0,10,uQuitMission(0),0);
:end
END

END //STATE Mission_failed

STATE Mission_won

RULE event In
:action
//Show a "Mission_won" title
Title(0,0,0,"Mission_won");

//Set both objectives to "completed"
MissionObjective(1, #OBJECTIVE_COMPLETED);
MissionObjective(2, #OBJECTIVE_COMPLETED);

//wait 10 seconds before quitting the mission
Delay(0,10,uQuitMission(1),0);
:end
END

END //STATE Mission_won

END //MACHINE "Objectives"

I hope im giving you the information thats helping you out man. I also appreciate you taking time to reply to my posts on here, for which i applaud you.  :D

EDIT: i also want to say i havent touched this file either, though i plan to soon, again with your assistance, if able... ;)
« Last Edit: September 24, 2011, 19:05:25 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 #21 on: September 24, 2011, 19:09:45 »
OH WAIT A SECOND....  :o

When you were talking about this...

Quote
Couple of things: you have two machines that are named the same, check that.

did you mean this part? if so i didnt change that!  :o

Code: [Select]
MACHINE "INNER_AI"
#include "default_ai.mach"
END

That may be the problem right there!  :D
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 #22 on: September 24, 2011, 19:23:25 »
Try changing the name of that machine to something else.
And if that doesn't work, I'm gonna have to see the content of the default_ai.mach file.

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 #23 on: September 25, 2011, 04:57:39 »
Do you have any suggestions/reccomendations as to what i should name it? Im thinking SECONDARY_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 #24 on: September 25, 2011, 05:12:43 »
I would leave that as Inner_AI (as it is, in fact, an inner ai) and name the upper one to MAIN_AI or RAPTOR_AI