Multiplayer/Singleplayer AI

Modding, patches, etc., for anyone who speaks neither Polish nor Czech.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

yeah it's amazing how much you can actually do with it :D because of the long compiling times?
Oh that was a little error, I fixed it now though :)
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

Compile time is nothing. 2 or 10 secs, doesn't matter (in my opinion at least). But when running it there can be some laggs if many bases are controlled at the same time (especially when some bases are attacking/under attack). That's actually an issue with Ar15a on some computers (mine almost doesn't lagg).
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Ah yes I have noticed that. It is very annoying when attacking, vehicles and people would move a hex or two and then freeze and then move again but defending turrets still fire normally.. :P gives a great advantage to them
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

That's a different kind of lagg (the weird world of OW...). The lagg I'm talking about is good old lagg where the framerate decreases and everything jerks around. The kind of lagg you describe is caused by relatively many units being given a move-like command to a hex far away. You can try it in the editor. Place some 80 people in the lower right corner and tell them to walk to the upper left corner. The longer they have to go the worse. That's actually the main reason I make extensively use of waypoints - to minimize the distance.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Ah yes..good old lag :P much better so it is
Experience is the teacher of all things. - Julius Caesar
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

I'm getting runtime errors when the enemy is going to attack but it doesn't specify where the error is? Is it an error in the strategy? Oh and for now i'm just using a copy of the ar15a attack so it should be working fine shouldn't it?
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

What errors?
When you say "copy" do you mean you copy-pasted from Ar15a or did you just uncomment the commented code? To make it compile I removed some outcommented code in the outcommented code so in that case I can't guarantee things will work out completely right.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

I just uncommented it. I noticed that this section,

Code: Select all

//All are ready to attack.
         //Set attack strategy.
         ai_attack_strategy = Replace(ai_attack_strategy,base,Rand(1,4));
was significantly longer in Ar15a so could it just be that I need to redefine each side's strategy?

Thanks again.
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

The preparation code for attacking I did some rewriting on so it would make a template. And as I said I did some quick things to get the attack control code compiling. You could take those two everys and completely copy-paste from Ar15a (you also may have to declare and intialize some global variables ("base_in_area_map" at least). Also just copy-paste the definitions from Ar15a). But the strategies are tailored for that mission. For example it only defines attack paths for behemoths attacking from the Russian base. So as you say you probably want to redefine some but not necessarily all of the strategies. As I write "ai_attack_strategy" is just an abstraction. You have to define what path strategy 2 for base 4 corresponds to.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Ah ok I understand. For future maps would it be easier to have 2 attack paths using attack_hexs or to make a list of the dangerous vehicles and use ComAggressiveMove? Oh and where exactly do I define each strategy, is it just each set of Attack_hexs?
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

For future maps would it be easier to have 2 attack paths using attack_hexs or to make a list of the dangerous vehicles and use ComAggressiveMove?
Not sure what you mean.
Oh and where exactly do I define each strategy, is it just each set of Attack_hexs?
In the preparation part you set "ai_attack_strategy" for the base to something appropriate given the current situation. In the attack control code you build up "attack_hexes" and "init_attack_hexes" according to the value of "ai_attack_strategy". I admit it's a little silly. Why not just build the attack hexes in the preparation? That would also improve performance a bit. But under some circumstances it's convenient, e.g. when dealing with behemoths.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Not sure what you mean.
I just meant which is easier for planning attacks but nevermind :P
In the preparation part you set "ai_attack_strategy" for the base to something appropriate given the current situation. In the attack control code you build up "attack_hexes" and "init_attack_hexes" according to the value of "ai_attack_strategy". I admit it's a little silly. Why not just build the attack hexes in the preparation? That would also improve performance a bit. But under some circumstances it's convenient, e.g. when dealing with behemoths.
I understand now, very good generic command for setting attacks :D
Just 1 little problem I am having, I simplified the russians attack so that is it just this,

Code: Select all

//All are ready to attack.
          //Set attack strategy.
          case base of
               1: begin
                    ai_attack_strategy = Replace(ai_attack_strategy,base,1);
               end;
for the Strategy and the the actual attack,

Code: Select all

1: begin  //Russians
                              //Strategy 1 - Attack Alliance and later Americans.
                              init_attack_hexes = [[44,17],[72,29],[72,29]];  //Double indended to make vehicles gather at that hex
                              attack_hexes = init_attack_hexes;

                              if ai_attack_strategy[base] = 1 then
                                   begin
                                        attack_hexes = attack_hexes ^ [[69,37],[67,46],[59,55],[56,66],[56,66],[64,84],[67,99]];  //Attack Alliance. Double indended to make vehicles gather at that hex
                                        end;
But still, when the vehicles are produced I get a runtime error at various numbers at around 60000 for "sets of 19: []" and "[0]" so the results are set to 0 and the vehicles gather in the top right corner. What do you think is causing this? thanks
Attachments
Runtime Error.JPG
(188.33 KiB) Not downloaded yet
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

The code snippets you posted look fine. It's caused by something else. Again, it's easier if you just post the whole code so I can find what's wrong.
The "line numbers" you get in the error message is where the exception happened in the compiled code - not your code. Rather annoying as it makes debugging a lot harder. A way to pinpoint the error is to force a reading beyond end of list error a known place in you code and note the number. E.g.

Code: Select all

Every 0$1 do
var a;
begin a = [1,2]; a = a[10]; end;

[some code]

Every 0$2 do
var a;
begin a = [1,2]; a = a[10]; end;

[some more code]

Every 0$3 do
var a;
begin a = [1,2]; a = a[10]; end;
Let's say you have an error at line 2000. The first forced error (happening after 1 second) happens at line 1300. The next (after 2 seconds) at line 1800. The third at line 2300. Now you know the error is somewhere in "[some more code]". To further track it down you can use the results to calculate how many lines of compiled code goes per un-compiled line.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

I don't know exactly how to do what you are saying but I'll attach both my MAIN and AI modules so you can see better for yourself :)
Attachments
MAIN.src
(54.29 KiB) Downloaded 180 times
AI.src
(314.55 KiB) Downloaded 168 times
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

All right. First a couple of minors I found:

In function "PrepareComputerSides" 6 mechanics for producing siberite bombs are created but no siberite factory is specified (via "ai_sib_bomb_fact"). Although it won't cause and error I think you'll have 6 non-placed mechanics in memory.

In the mechanic control code I can see you have specified areas for vehicle defence.

Code: Select all

//Order the vehicles to attack an enemy unit near the base.
                              case base of
                                   1: temp_list = DangerousUnits(FilterAllUnits([[f_enemy,side],[f_inarea,ru_vehicle_defend_area]]));
                                   2: temp_list = DangerousUnits(FilterAllUnits([[f_enemy,side],[f_inarea,am_vehicle_defend_area]]));
                                   3: temp_list = DangerousUnits(FilterAllUnits([[f_enemy,side],[f_inarea,ar_vehicle_defend_area]]));
                              end; DangerousUnits( ListFilterNearBaseArea( FilterAllUnits([f_enemy,side]), area) );  //***1
but forgot to delete the last part "DangerousUnits( ListFilterNearBaseArea( FilterAllUnits([f_enemy,side]), area) );" which doesn't really do anything atm.

In the attack preparation code I made a mistake in the template. In the beginning it says

Code: Select all

wait(0$1 mod (ai_bases diff 2));

          for base in (ai_bases diff 2) do
          begin
          wait(0$1 div (ai_bases diff 2));
but it should be

Code: Select all

wait(0$1 mod (ai_bases+0));

          for base in ai_bases do
          begin
          wait(0$1 div (ai_bases+0));
Else base 2 would never attack.

Regarding your runtime error there are three problems: First you use the global variable "base_in_area_map" in both attack preparation and control but that variable is never initialized. In Ar15a it's used for determining in what areas there are enemy bases. You can almost copy-paste the code from Ar15a if you want.
Second you use behemoths for attacking for any base if the strategy is 1, 2 or 4 (but since only base 1 produces behemoths it's only applicable for them), but you never specify attack paths for them. If you don't want to use behemoths for attacks remember to put "behemoths_in_position = Replace(behemoths_in_position,base,in_position_target[base]);" in the attack hexes building section.
Third, you haven't deleted the line "init_attack_hexes = []; attack_hexes = []; behemoths_in_position = Replace(behemoths_in_position,base,in_position_target[base]); //***1" which effectivly resets everything you have done before that point.
Post Reply