Example #1
0
 public static bool ai_get_dist(Unit unit, int x, int y, AI_FIND type, out int dx, out int dy, out int dist)
 {
     bool found = false;
     int length;
     int i, j;
     dist = 999;
     dx = dy = 0;
     for (i = 0; i < Engine.map.map_w; i++)
         for (j = 0; j < Engine.map.map_h; j++)
             if (ai_check_hex_type(unit, type, i, j))
             {
                 length = Misc.get_dist(i, j, x, y);
                 if (dist > length)
                 {
                     dist = length;
                     dx = i;
                     dy = j;
                     found = true;
                 }
             }
     return found;
 }
Example #2
0
 /*
 ====================================================================
 Locals
 ====================================================================
 */
 /*
 ====================================================================
 Get the distance of 'unit' and position of object of a special
 type.
 ====================================================================
 */
 static bool ai_check_hex_type(Unit unit, AI_FIND type, int x, int y)
 {
     switch (type)
     {
         case AI_FIND.AI_FIND_DEPOT:
             if (Engine.map.map_is_allied_depot(Engine.map.map[x, y], unit))
                 return true;
             break;
         case AI_FIND.AI_FIND_ENEMY_OBJ:
             if (!Engine.map.map[x, y].obj) return false;
             break;
         case AI_FIND.AI_FIND_ENEMY_TOWN:
             if (Engine.map.map[x, y].player != null && !Player.player_is_ally(unit.player, Engine.map.map[x, y].player))
                 return true;
             break;
         case AI_FIND.AI_FIND_OWN_OBJ:
             if (!Engine.map.map[x, y].obj) return false;
             break;
         case AI_FIND.AI_FIND_OWN_TOWN:
             if (Engine.map.map[x, y].player != null && Player.player_is_ally(unit.player, Engine.map.map[x, y].player))
                 return true;
             break;
     }
     return false;
 }