[SOLVED] Problems with AI movement / bool variable

Started by Matti, Sun 25/01/2009 15:42:02

Previous topic - Next topic

Matti

I'm working on a game with a map and 4 players on it. This is my scipt for the AI movement. There are creatures and two cities on the map (like in "Moonstone" if you know that cool Amiga game).

Each turn the AIs decide between aiming at a nearby creature or knight(player) or going to one of the cities. If they don't have enough gold and there's no nearby creature to attack they're supposed to aim at random coordinates on the map. Well and everything worked fine until I introduced the "sillywalk"-bool variable. The variable should tell the AI to look out for anything interesting while senselessly walking to those random coordinates.

But since I use that variable the AIs just stop and go and bustle around when nothing interesting is nearby instead of walking straight to their aim. I can't figure out what's wrong.

For clarification: "zielx" and "ziely" are the coordinates the AIs are supposed to walk to. "spieler" is the actual player/AI.

Code: ags

  if (movement>0){  
  
    int a=Random(100);
    // AI aims at a nearby creature with 50% possibility
    i=0;
    while (i<6){
      if ((object[i].Visible)&&(a<50)&&(sillywalk[spieler])){  
        if((object[i].X>character[spieler].x-180)&&(object[i].X<character[spieler].x+180)&&(object[i].Y>character[spieler].y-180)&&(object[i].Y<character[spieler].y+180)){
          sillywalk[spieler]=false;
          zielx[spieler]=object[i].X+3;
          ziely[spieler]=object[i].Y-3;
        }
      }
    i++;
    }
    // AI aims at a nearby knight with 30% possibility
    i=0;
    while(i<4){
      if ((a>49)&&(a<80)&&(sillywalk[spieler])){  
        if((character[i].x>character[spieler].x-100)&&(character[i].x<character[spieler].x+100)&&(character[i].y>character[spieler].y-100)&&(character[i].y<character[spieler].y+100)){
          sillywalk[spieler]=false;
          zielx[spieler]=character[i].x+2;
          ziely[spieler]=character[i].y-2;
       }
      }
    i++;
    }
    // AI aims at one of the cities with 20% possibility and some gold
    if ((a>79)&&(Gold[spieler]>=(40+Stufe[spieler]*3))&&(sillywalk[spieler])){
        if(character[spieler].y<300){
          sillywalk[spieler]=false;
          zielx[spieler]=object[6].X+15;
          ziely[spieler]=object[6].Y-15;
        }
        if(character[spieler].y>=300){
          sillywalk[spieler]=false;
          zielx[spieler]=object[7].X+15;
          ziely[spieler]=object[7].Y-15;
        }
    } 
  
    // AI aims at random coodinates on the map
    // but a new aim is possible
    
    if((zielx[spieler]==character[spieler].x)&&(ziely[spieler]==character[spieler].y)) {
      if (character[spieler].x<400){zielx[spieler]=500+Random(250);}
      if (character[spieler].x>=400){zielx[spieler]=50+Random(250);}
      if (character[spieler].y<300){ziely[spieler]=400+Random(150);}
      if (character[spieler].y>=300){ziely[spieler]=50+Random(150);}
      sillywalk[spieler]=true;
    }
   
  }


Again: What's up with the letter "r" when used with code-tags? A single "r" is written as "are" and a line saying "r"=random(bla) isn't shown at all. I again had to change it to "a".


EDIT:

Sorry for possible confusion. Although it seemed so the problem had nothing to do with the sillywalk variable. The problem was that the knights also tried to attack themselves and always moved some pixels to do so. I should have included && (spieler!=i) in the if clause. What an annoying mistake that was  :P.

Gilbert

The "r" problem is a filter in the forum itself, which attempts to convert Internet abbreviations into human consumable full spellings. Unfortunately this is not fixed at the moment.

SMF spam blocked by CleanTalk