Goto https://www.stucuk.netGoto https://www.atlanticaonlinewiki.comGoto https://www.game-requirements.com


Menu


It is currently Sat Sep 22, 2018 2:54 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Engineer, Scientist, Soldier AI
PostPosted: Sat May 23, 2009 12:43 am 
Offline
Soldier level 1
Soldier level 1
User avatar

Joined: Mon Nov 26, 2007 8:07 pm
Posts: 86
Location: Germany
Basicly this is an AI for us when you have this:

4 Bunkers indicated as b1-b4
4 soldiers which sit in the bunkers indicated as sol1-sol4
1 Barracks indicated as bar1
1 lab indicated as lab2
1 Warehouse(Or depot) indicated as d1
3 Engineers indicated as eng1-eng3
2 scientists indicated as sc1-sc2
What does it do?
Well here is a small text about the function:
When a tower or the barracks have less than 550 health, engineers go there and repair it. After 10 seconds of repair they return to the depot.
If a bunker has less then 300 Health (it starts burning) the soldier that controlled the bunker moves back to the barracks.
If the health goes over 350 again, they move back inside.
If one of the Engineers has less then 550 HP, He isn't allowed to repair anymore. He will be send near the lab, where the scientists heal him. After 15 seconds the scientist go back into the lab, and the engineer to the depot, or whereever he is sent to.
This is it, basicly
Here is my work:
Code:
export forbidden1,forbidden2,forbidden3;
every 0$0.5 trigger Getlives(b1)<550 do
begin
if forbidden1=0 then
Comrepairbuilding(eng4,b1);
if forbidden2=0 then
Comrepairbuilding(eng5,b1);
if forbidden3=0 then
ComRepairBuilding(eng6,b1);


wait(0$10);
AddComEnterUnit([eng4,eng5,eng6],d1);
enable;
end;
every 0$0.5 trigger Getlives(b2)<550 do
begin
if forbidden1=0 then
Comrepairbuilding(eng4,b2);
if forbidden2=0 then
Comrepairbuilding(eng5,b2);
if forbidden3=0 then
ComRepairBuilding(eng6,b2);
wait(0$10);
AddComEnterUnit([eng4,eng5,eng6],d1);
enable;
end;
every 0$0.5 trigger Getlives(b3)<550 do
begin
if forbidden1=0 then
Comrepairbuilding(eng4,b3);
if forbidden2=0 then
Comrepairbuilding(eng5,b3);
if forbidden3=0 then
ComRepairBuilding(eng6,b3);


wait(0$10);
AddComEnterUnit([eng4,eng5,eng6],d1);
enable;
end;
every 0$0.5 trigger Getlives(b4)<550 do
begin
if forbidden1=0 then
Comrepairbuilding(eng4,b4);
if forbidden2=0 then
Comrepairbuilding(eng5,b4);
if forbidden3=0 then
ComRepairBuilding(eng6,b4);


wait(0$10);
AddComEnterUnit([eng4,eng5,eng6],d1);
enable;
end;
every 0$0.5 trigger Getlives(bar1)<550 do
begin
if forbidden1=0 then

Comrepairbuilding(eng4,bar1);

if forbidden2=0 then

Comrepairbuilding(eng5,bar1);

if forbidden3=0 then

ComRepairBuilding(eng6,bar1);


wait(0$10);
AddComEnterUnit([eng4,eng5,eng6],d1);
enable;
end;
every 0$0.5 trigger Getlives(eng4)<550 do
begin
forbidden1=1;
ComStop(eng4);
ComStop([sc1,sc2]);
CommoveXY(eng4,151,13);
CommoveXY([sc1,sc2],151,13);
wait(0$2);
ComHeal([sc1,sc2],eng4);
wait(0$15);
forbidden1=0;
AddComEnterUnit(eng4,d1);
AddComEnterUnit([sc1,sc2],lab2);
enable;
end;
every 0$0.5 trigger Getlives(eng5)<550 do
begin
forbidden2=1;
ComStop(eng5);
CommoveXY(eng5,151,13);
CommoveXY([sc1,sc2],151,13);
wait(0$2);
ComHeal([sc1,sc2],eng5);
wait(0$15);
forbidden2=0;
AddComEnterUnit(eng5,d1);
AddComEnterUnit([sc1,sc2],lab2);
enable;
end;
every 0$0.5 trigger Getlives(eng6)<550 do
begin
forbidden3=1;
ComStop(eng6);
CommoveXY(eng6,151,13);
CommoveXY([sc1,sc2],151,13);
wait(0$2);
ComHeal([sc1,sc2],eng6);
wait(0$15);
forbidden3=0;
AddComEnterUnit(eng6,d1);
AddComEnterUnit([sc1,sc2],lab2);
enable;
end;
every 0$1 trigger Getlives(b1)<300 do
begin
if forbidden1=0 then
Comrepairbuilding(eng4,b1);
if forbidden2=0 then
Comrepairbuilding(eng5,b1);
if forbidden3=0 then
ComRepairBuilding(eng6,b1);

Comenterunit(sol1,bar1);
enable;
end;

every 0$1 trigger Getlives(b2)<300 do
begin
if forbidden1=0 then
Comrepairbuilding(eng4,b2);
if forbidden2=0 then
Comrepairbuilding(eng5,b2);
if forbidden3=0 then
ComRepairBuilding(eng6,b2);


Comenterunit(sol2,bar1);
end;
every 0$1 trigger Getlives(b3)<300 do
begin
if forbidden1=0 then
Comrepairbuilding(eng4,b3);
if forbidden2=0 then
Comrepairbuilding(eng5,b3);
if forbidden3=0 then
ComRepairBuilding(eng6,b3);

Comenterunit(sol3,bar1);
enable;
end;
every 0$0.5 trigger Getlives(b4)<300 do
begin
if forbidden1=0 then
Comrepairbuilding(eng4,b4);
if forbidden2=0 then
Comrepairbuilding(eng5,b4);
if forbidden3=0 then
ComRepairBuilding(eng6,b4);
Comenterunit(sol4,bar1);
enable;
end;
every 0$0.5 trigger Getlives(b1)>350 do
begin
AddComEnterUnit(sol1,b1);
enable;
end;
every 0$0.5 trigger Getlives(b2)>350 do
begin
AddComEnterUnit(sol2,b2);
enable;
end;
every 0$0.5 trigger Getlives(b3)>350 do
begin
AddComEnterUnit(sol3,b3);
enable;
end;
every 0$0.5 trigger Getlives(b4)>350 do
begin
AddComEnterUnit(sol4,b4);
enable;
end;

_________________
MEMORIES, A OWAR MOD, PLEASE TRY OUT


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 22, 2009 3:25 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
xXx::.TRUCKER.::xXx wrote:
3 Engineers indicated as eng1-eng3


Fine fine, in the code they are just indicated as eng4-eng6 :P

xXx::.TRUCKER.::xXx wrote:
If a bunker has less then 300 Health (it starts burning)


If you mean burning like in "going to red life" it first happens at 250 hp 8for any unit).

In the part where the injured engineer goes to the scientists to get healed, I propose you make it more general (you refer to specific coordinates). Furthermore I think it's best if the engineer keeps standing by the scientists until he is fully healed :wink: You could do it like this:

Code:
every 0$0.5 trigger GetLives(engi1) < 550 do
     var dir_lab, x_lab, y_lab;
     begin
          forbidden1 = 1;
          ComStop(engi1);
          ComStop([sc1,sc2]);
          dir_lab = GetDir(lab2);
          x_lab = GetX(lab2);
          y_lab = GetY(lab2);
          //this part ensures that the engineer goes to the entrance of the lab
          if dir_lab = 0 then ComMoveXY(engi1,x_lab,y_lab-4);
          if dir_lab = 1 then ComMoveXY(engi1,x_lab+4,y_lab);
          if dir_lab = 2 then ComMoveXY(engi1,x_lab+4,y_lab+4);
          if dir_lab = 3 then ComMoveXY(engi1,x_lab,y_lab+4);
          if dir_lab = 4 then ComMoveXY(engi1,x_lab-4,y_lab);
          if dir_lab = 5 then ComMoveXY(engi1,x_lab-4,y_lab-4);
          AddComHold(engi1);

          repeat
          Wait(0$1);
          until IsIdle(engi1) or not IsOk(engi1);

          if IsIdle(engi1) then
               begin
                    ComExitBuilding([sc1,sc2]);
                    AddComHeal([sc1,sc2],engi1);

                    repeat
                    Wait(0$1);
                    until GetLives(engi1) = 1000 or not IsOk(engi1);

                    if GetLives(engi1) = 1000 then forbidden1 = 0;
                    AddComEnterUnit(eng4,d1);
                    AddComEnterUnit([sc1,sc2],lab2);
               end;
          enable;
     end;


And why not do the same with the soldiers :P

Concerning the code where the engineers are ordered to repair damaged buildings; why not make similar codes for the lab and the depot?
And maybe some extra code should be added to ensure that the engineers repair the buildings completely if the base isn't attacked. Try this out:

Code:
Export Function AnyoneFromListAttacks(list);
     var a;
     begin
          result = false;
          for a in list do
               if Attacks(a) then
                    begin
                         result = true;
                         exit;
                    end;
     end;

every 0$1 trigger 550 <= GetLives(b1) < 1000 and not AnyoneFromListAttacks(FilterAllUnits([f_side,1])) do
     begin
          if forbidden1=0 then
          ComRepairBuilding(eng1,b1);
          if forbidden2=0 then
          ComRepairBuilding(eng2,b1);
          if forbidden3=0 then
          ComRepairBuilding(eng3,b1);

          Wait(0$1);
          if GetLives(b1) = 1000 or AnyoneFromListAttacks(FilterAllUnits([f_side,1])) then AddComEnterUnit([engi1,engi2,engi3],d1);
          enable;
     end;


EDIT: Repaired function AnyoneFromListAttacks (thanks Gothuk and Radzio)


Last edited by McBenn on Thu Jul 23, 2009 9:19 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 22, 2009 3:30 pm 
Offline
Original-War.Net Owner
Original-War.Net Owner
User avatar

Joined: Wed Jan 25, 2006 10:21 am
Posts: 2786
Location: Poland, Białystok
Should be ok.
But in AnyoneFromListAttacks u should put exit along with result in begin/end block for "if" not a loop. Loop doesn't really need a begin/end block.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 22, 2009 4:14 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
Like this?

Code:
Export Function AnyoneFromListAttacks(list);
     var a;
     begin
          result = false;
          for a in list do
               if Attacks(a) then result = true; exit;
     end;


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 22, 2009 5:28 pm 
Offline
Original-War.Net Owner
Original-War.Net Owner
User avatar

Joined: Wed Jan 25, 2006 10:21 am
Posts: 2786
Location: Poland, Białystok
Code:
then begin result = true; exit; end;

Otherwise it will simply exit after checking the first value in the list (no matter what "if" states).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 22, 2009 11:42 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
Isn't that the same as

Code:
for a in list do
     begin
          if Attacks(a) then result = true;
          exit;
     end;


:?:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 23, 2009 12:20 am 
Offline
Moderator
Moderator
User avatar

Joined: Mon Sep 17, 2007 7:34 pm
Posts: 259
Location: Poland, Warsaw
No, because even if condition is false, exit will made.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 23, 2009 1:19 am 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
Jees you are right :!: :!: How could I miss that. Corrected :wink:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Original War is an RTS / RPG game by Altar Games
Original War Support is not part of Altar Games but is maintaining Original War for Altar Games

Privacy Policy