Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Natural Wasp
#1
I made a little program for a wasp to it move more natural
What it does:
-wasp looks like flying totally pointless (but it's not)
-wasp is harder to shoot down
-wasp drops OrgaMatter on buildings and robots (not every one - you can check)
-when no buildings or robots on map, wasp steals your resources Smile)

I know it's so much imperfect and the code has a lot of bugs - I'm just a begginer.
I just want to show that wasps can move more naturally and be more annoying (like in real!) - maybe it's something what you can do batter in Colobot Gold? Wasp is not a robot and I think it shouldn't move like robot.

The code is made for Tropica freemission map.
I placed there "CreateObject pos=65.58;232.20 dir=0.0 type=AlienNest"
and "CreateObject pos= -55; 243 cmdline= -55; 243; -62; 234 dir=0.0 type=AlienQueen script1="alienqueen.txt" run=1"
where script alienqueen.txt produces an AlienWasp when there are < 30 of them Smile



Here it is:
Code:
void object::grabber()
{
while (this.load == null)
{
motor(0,0);
while (this.altitude > 1)
{
jet(-1);
wait(0.1);
continue;
}
jet(-1);
wait(1.5);
grab();
break;
}

}

void object::fly()
{
float rand1 = rand(), rand2 = rand();

  jet(1);
  wait(0.8);
           motor(1, 0.5+rand1);
  jet(0.8);
  wait(0.8);
           motor(0.5+rand2, 1);
  jet(1);
  wait(1.6);
      motor(1, 0.5+rand2);
  jet(0.7);
      wait(0.8); 
       motor(1,1);         
}

void object::Fight()
{
point dest;
int alien[], j = 0; // aliens for wasp ;)
//alien[j++] = WingedGrabber;
//alien[j++] = TrackedGrabber;
//alien[j++] = WheeledGrabber;
//alien[j++] = LeggedGrabber;
alien[j++] = WingedShooter;
alien[j++] = TrackedShooter;
alien[j++] = WheeledShooter;
alien[j++] = LeggedShooter;
alien[j++] = WingedOrgaShooter;
alien[j++] = TrackedOrgaShooter;
alien[j++] = WheeledOrgaShooter;
alien[j++] = LeggedOrgaShooter;
alien[j++] = WingedSniffer;
alien[j++] = TrackedSniffer;
alien[j++] = WheeledSniffer;
alien[j++] = LeggedSniffer;
alien[j++] = Thumper;
alien[j++] = PhazerShooter;
alien[j++] = Recycler;
alien[j++] = Shielder;
alien[j++] = Subber;
//alien[j++] = Me;

alien[j++] = Houston; 
alien[j++] = ExchangePost; 
alien[j++] = RadarStation; 
//alien[j++] = Derrick; 
//alien[j++] = Converter; 
alien[j++] = PowerPlant; 
alien[j++] = NuclearPlant; 
alien[j++] = BotFactory; 
alien[j++] = RepairCenter; 
alien[j++] = PowerStation; 
alien[j++] = DefenseTower; 
alien[j++] = PowerCaptor; 
alien[j++] = AutoLab; 
alien[j++] = ResearchCenter; 

object item;
point dustbin;
dustbin.x = 34;
dustbin.y = 240;

item = radar(OrgaMatter, 0, 360, 0, 1000);
if (item == null)
{
jet(1);  
dest = position;
dest.x += (rand()-0.5)*10;
dest.y += (rand()-0.5)*10;
goto(dest);  
produce(position, 0, OrgaMatter, "");
wait(2);
}
else
{
jet(1);
produce(position, 0, OrgaMatter, "");
goto(item.position);
grabber();
   if (this.load == null)
   {
   Fight(); // sometimes has problem with grab so tries again
}
item = radar(alien, 0, 360, 0, 10000, FilterOnlyLanding);
if (item == null)
{
Steal();
GoBack();
}
else
{
while (distance(position, item.position) > 30)
{
item = radar(alien, 0, 360, 0, 10000, FilterOnlyLanding);
if (item == null)
{
SuperWasp(); //enemy may become destroyed while wasp was flying there
}
else
{
turn (direction(item.position));
fly();
}
}
   
while (distance(position, item.position) < 30)
{
item = radar(alien, 0, 360, 0, 10000, FilterOnlyLanding);
   if (item == null)
   {
   SuperWasp();
}

while (distance(position, item.position) > 10)
{
item = radar(alien, 0, 360, 0, 10000, FilterOnlyLanding);
if (item == null)
{
Steal();
}
else
{
jet(1);
turn(direction(item.position));
motor(1,1);
}
}
                      
while (distance(position, item.position) <= 10)
{
item = radar(alien, 0, 360, 0, 10000, FilterOnlyLanding);
if (item == null)
{
Steal();
}
else
{
jet(1);
if (this.load != null)
{
motor(0, 1);
jet(1);
wait(0.1);
drop(); // drop Orga Matter not so accurately
fly();
}
else
{
Steal();
GoBack();
}
}
break;
}
break;
}
   
}

}
}

void object::Steal()
{
point dest;
point dustbin;
dustbin.x = 34;
dustbin.y = 240;
object item;
object thing;
object item2;

int list[], i = 0;
list[i++] = Titanium;
list[i++] = PowerCell;
list[i++] = NuclearCell;

GoBack();

if (this.load != null)
{
drop();
}

item = radar(list, 0, 360, 0, 10000, -1);
if (item == null)
{
while (distance(position, dustbin) > 30)
{
turn (direction(dustbin));
fly();
}
while (distance(position, dustbin) < 30)
{
jet(1);  
dest = position;
dest.x += (rand()-0.5)*10;
dest.y += (rand()-0.5)*10;
goto(dest);  
break;
}
}
else
{   
while (distance(position, item.position) > 30) // go there
{
item2 = radar(list, 0, 360, 30, 10000);
if (item2 != null)
{
item2 == item;
turn (direction(item.position));
fly();
}
else
{
SuperWasp();
}

}
while (distance(position, item.position) < 30) // wasp close to target, need to be more accuretely
{
item = radar(list, 0, 360, 0, 10000);
if (item == null)
{
SuperWasp();
}
if (distance2d(position, item.position) > 10)
{
jet(1);
turn(direction(item.position));
move(distance(position, item.position));
}
if (distance2d(position, item.position) <= 10)
{
motor(0,0);
jet(1);
turn(direction(item.position));
move(distance2d(position, item.position));
grabber();
if (this.load == null)
{
item = radar(list, 0, 360, 0, 10000);
goto(item.position);
grabber();
}
jet(1);
wait(0.2);
motor(1, 0.7);
wait(1.5);
SuperWasp();
}
break;
}
}


jet(1);
turn(direction(dustbin));
while (distance(position, dustbin) > 30)
{
turn (direction(dustbin));
fly();
}
while (distance(position, dustbin) > 30)
{
turn(direction(dustbin));
move(10);
if (this.load != null)
{
drop();
}
}
}

void object::GoBack()
{
point dustbin; // position where wasps collect stolen items
dustbin.x = 34;
dustbin.y = 240;

jet(1);
turn(direction(dustbin));
while (distance(position, dustbin) > 20)
{
turn (direction(dustbin));
fly();
}
while (distance(position, dustbin) < 20)
{
if (this.load != null)
{
goto(dustbin);
drop(); // Anything
break;
}
break;
}
}


extern void object::SuperWasp()
{
int alien[], j = 0; // aliens for wasp ;)
//alien[j++] = WingedGrabber;
//alien[j++] = TrackedGrabber;
//alien[j++] = WheeledGrabber;
//alien[j++] = LeggedGrabber;
alien[j++] = WingedShooter;
alien[j++] = TrackedShooter;
alien[j++] = WheeledShooter;
alien[j++] = LeggedShooter;
alien[j++] = WingedOrgaShooter;
alien[j++] = TrackedOrgaShooter;
alien[j++] = WheeledOrgaShooter;
alien[j++] = LeggedOrgaShooter;
alien[j++] = WingedSniffer;
alien[j++] = TrackedSniffer;
alien[j++] = WheeledSniffer;
alien[j++] = LeggedSniffer;
alien[j++] = Thumper;
alien[j++] = PhazerShooter;
alien[j++] = Recycler;
alien[j++] = Shielder;
alien[j++] = Subber;
//alien[j++] = Me;

alien[j++] = Houston; 
alien[j++] = ExchangePost; 
alien[j++] = RadarStation; 
//alien[j++] = Derrick; 
//alien[j++] = Converter; 
alien[j++] = PowerPlant; 
alien[j++] = NuclearPlant; 
alien[j++] = BotFactory; 
alien[j++] = RepairCenter; 
alien[j++] = PowerStation; 
alien[j++] = DefenseTower; 
alien[j++] = PowerCaptor; 
alien[j++] = AutoLab; 
alien[j++] = ResearchCenter; 

errmode(0);
object item;
point dustbin; // position where wasps collect stolen items
dustbin.x = 34;
dustbin.y = 240;

while(true)
{
if (this.load != null) // when holding something
{
jet(1);
while (distance(position, dustbin) > 30)
{
turn (direction(dustbin));
fly();
}
drop();
}

item = radar(alien, 0, 360, 0, 10000, FilterOnlyLanding);
if (item != null) // can destroy something
{
Fight();
Steal();
}
           
else // nothing to destroy
{
Steal();
}
       
GoBack();    
continue;    
}
}


What do your thing about it?
#2
Of course better AI is also planned for GOLD. And, well, I like your script Smile . The only flaw I could see is bad aiming when AlienWasp tries to destroy a building. And I don't know what's the point of producing OrgaMatter at the beginning of the program. But that's for now a minor bugs. I simply loved how AlienWasp flies and steals resources Big Grin .
#3
I wanted to wasps aim not so accurately, otherwise it would be too hard to win with them Smile
My script has also problems when wasp comes too close to building like BotFactory - the wasp gets stuck over the building and can't release until the building is destroyed - i didn't know how to fix that so I made wasps not come too close of building.
I decided to wasps produce OrgaMatter because when there was only one AlienNest on the map and few wasps, sometimes they was getting error because of problems with grab, so it was blocking AlienNest to produce OrgaMatter.

I know my solutions don't really solve the problems, but as I said on the beginning - I'm just a begginner and I'm learning it from few days only Smile

I'm very pleased you appreciate my script. Thank you!

I'll try to rewrite it
#4
Hey, have you guys played my levels? I have some wasps stealing resources too, maybe you can find some solutions for your problems in my AI scripts.
True Level Pack
Screenshots
#5
Sorry for my little absence - had too much work.

True Destroyer, I can't test your levels - it doesn't work on my 1.6 alpha.
Anyway I conclude I wasn't first with idea of wasp who steals resources Tongue

I rewrited my program, still had few bugs - I will be ready soon.
#6
I'm back again!
Still working on my program (don't have much time) and I have a problem.
Command "turn(direction(item.position))" makes my wasp too slow. I mean it makes wasp only turning, not moving straight...
I wonder how to make "wasp turn(direction(item.position))" using "motor(1,0);" - do u guys have any idea?
#7
Probably there is required some function that will convert angle to x and y variables, that could be passed to motor function. Negative angle turned to i.e. motor(0.8, 1);, or motor(-0.1, 1);, depending how much you must turn, etc.
Spoiler :
[Image: unknown.png]
#8
I was thinking about the same:
1) get self.position (x, y only)
2) get target.position (x, y)

For example if target.position.y < self.position.y => target is on the west =>... But i don't know how to get/use self orientation - if i would know my orientation is North so then motor (0,1); and do it every Fly()
#9
OK, I made wasp turns using "motor" - not "turn", so it flies faster and more fluently, so it's harder to shoot it down.
I rewritted whole program to make it simpler. It works much better but I'm still working on few issues (and learning CBOT :D)

Maybe you can help me - i don't have any idea what to do:
When wasps have stolen all resources, they make a big crowd near "dustbin" point - they all want to grab resources which are laying there just ti drop it again. I don't know what to do with that. I tried to make object "Cleaner" (it's in code) which will destroy resources in dustbin, but it doesn't help much.
I know the solution is to throw resources to lava, but it would work only on maps with it...

For now It works best on Tropica map.
Code:
void object::goto2(point dest)
{
float rand1 = rand(), rand2 = rand();
float dir;

errmode(0);
turn(direction(dest));
while (distance(position, dest) > 30)
{
dir = direction(dest);
if ( dir < 0 )  // on the right ?
{
motor(1, 1+dir/90);
}
else  // on the left ?
{
motor(1-dir/90, 1);
}
jet(1);
 wait(0.8);
motor(1, 0.5+rand1);
jet(0.8);
 wait(0.8);
motor(0.5+rand2, 1);
 jet(1);
 wait(1.6);
motor(1, 0.5+rand2);
 jet(0.7);
 wait(0.8);
motor(1,1);    
if (rand1 > 0.9) // make a spin sometimes. looks natural and it helps when wasp is stuck :)
{
jet(1);
motor(1,0);
wait(2);
}
if (rand2 > 0.9)
{
jet(1);
motor(0,1);
wait(2);
}
}
while (distance(position, dest) < 30)
{
while (distance(position, dest) > 7)
{
jet(1);
turn(direction(dest));
motor(1,1);
wait(0.1);
break;
}
if (distance(position, dest) <= 7)
{
motor (0,1);
wait(0.1);
}
break;
}
}

void object::Fight()
{
int danger[], i = 0;
danger[i++] = Shielder;
danger[i++] = WingedShooter;
danger[i++] = TrackedShooter;
danger[i++] = WheeledShooter;
danger[i++] = LeggedShooter;
danger[i++] = WingedOrgaShooter;
danger[i++] = TrackedOrgaShooter;
danger[i++] = WheeledOrgaShooter;
danger[i++] = LeggedOrgaShooter;
danger[i++] = PhazerShooter;
danger[i++] = DefenseTower;
danger[i++] = NuclearPlant;
danger[i++] = RadarStation;

int alien[], j = 0;
//alien[j++] = Me;
alien[j++] = WingedGrabber;
alien[j++] = TrackedGrabber;
alien[j++] = WheeledGrabber;
alien[j++] = LeggedGrabber;
alien[j++] = WingedShooter;
alien[j++] = TrackedShooter;
alien[j++] = WheeledShooter;
alien[j++] = LeggedShooter;
alien[j++] = WingedOrgaShooter;
alien[j++] = TrackedOrgaShooter;
alien[j++] = WheeledOrgaShooter;
alien[j++] = LeggedOrgaShooter;
alien[j++] = WingedSniffer;
alien[j++] = TrackedSniffer;
alien[j++] = WheeledSniffer;
alien[j++] = LeggedSniffer;
alien[j++] = Thumper;
alien[j++] = PhazerShooter;
alien[j++] = Recycler;
alien[j++] = Shielder;
alien[j++] = Subber;
alien[j++] = Houston;
alien[j++] = ExchangePost;
alien[j++] = RadarStation;
alien[j++] = Derrick;
alien[j++] = Converter;
alien[j++] = PowerPlant;
alien[j++] = NuclearPlant;
alien[j++] = BotFactory;
alien[j++] = RepairCenter;
alien[j++] = PowerStation;
alien[j++] = DefenseTower;
alien[j++] = PowerCaptor;
alien[j++] = AutoLab;
alien[j++] = ResearchCenter;

object item;

errmode(0);
if (this.load != null) {drop();}
item = radar(danger);
while (item != null)
{
Produceammo();
item = radar(alien, 0, 360, 0, 10000, FilterOnlyLanding);
goto2(item.position);
if (this.load != null) {drop();}
item = radar(danger);
if (item != null) {GoBack();}
}
}

void object::Steal()
{
int list[], k = 0;
list[k++] = Titanium;
list[k++] = PowerCell;
list[k++] = NuclearCell;
object item;

errmode(0);
if (this.load != null) {drop();}

item = radar(list, 0, 360, 200, 10000, FilterOnlyLanding);
for (;this.load==null;)
{
item = radar(list, 0, 360, 0, 10000, FilterOnlyLanding);
if (item != null)
{
goto2(item.position);
motor(0,0);
jet(-1);
turn(direction(item.position));
move(distance2d(position, item.position));
while (this.altitude > 1)
{
jet(-1);
wait(0.1);
}
wait(0.1);
goto(item.position);
wait(0.1);
if (this.load == null) {grab();}
}
}
}

void object::Randomfly()
{
jet(1);
motor(1,0);
wait(0.5);
turn(rand()*360);
jet(1);
motor(0,1);
wait(0.5);
turn(rand()*360);
}

void object::GoBack()
{
point dustbin(34, 240);

errmode(0);
goto2(dustbin);
if (this.load == null) {drop();}
}

void object::Clear()
{
int list[], k = 0;
list[k++] = Titanium;
list[k++] = PowerCell;
list[k++] = NuclearCell;
object item;

errmode(0);
item = radar(list, 0, 360, 0, 200, FilterOnlyLanding);
if (item != null)
{
Produceammo();
goto(item.position);
drop();
}
}

void object::Produceammo()
{
errmode(0);
while (this.load == null)
{
goto(space(position));
while (this.altitude > 1)
{
jet(-1);
wait(0.1);
continue;
}
wait(1);
produce(OrgaMatter);
wait(0.5);
grab();
}
}

extern void object::NaturalWasp()
{
while(true)
{
Clear();
Fight();
Steal();
GoBack();
Randomfly();
continue;    
}
}
#10
(08-09-2016, 11:53 AM)krakers Wrote: Maybe you can help me - i don't have any idea what to do:
When wasps have stolen all resources, they make a big crowd near "dustbin" point - they all want to grab resources which are laying there just ti drop it again. I don't know what to do with that. I tried to make object "Cleaner" (it's in code) which will destroy resources in dustbin, but it doesn't help much.
I know the solution is to throw resources to lava, but it would work only on maps with it...
Use radarall instead of radar, then filter it to find only objects that are not in dustbin.
Code:
object objs [] = radarall(list);
object o = null;
    for (int i = 0; i < sizeof(objs); i++){
        if(distance(dustbin_position, objs[i].position) > 25){
            o = objs[i];
            break;
        }
    }
#11
I'll try that. Thanks!

@edit
It's still imperfect. Need to optimize it, fix few bugs aaaand I would also add "try... catch". I think it may take forever but it makes me learn CBOT better, so I can upgrade my code and write some more for spiders, ants and worms. Anyway, do you think something should be added to wasp's code?
I'm thinking on it as a possible code or at least an idea for AI in Gold.
#12
Actually where do the waps take your resources?
Work it harder
Make it better
Do it faster
Makes us stronger
More than ever hour
After our work is never over

#13
(10-21-2016, 08:34 AM)LRV Wrote: Actually where do the waps take your resources?

There is a function "Produceammo()".

I decided to use "produce" because I couldn't make it working with AlienNest, when there were too many Wasps.
Feel free to improve it Smile My laptop is broken, so I can't do it


Forum Jump:


Users browsing this thread: 2 Guest(s)