Some initial scouting behavoir, still very rudimentary.
Implemented as unit formula for testing. This means unaware of other units and group behavoir.
This commit is contained in:
parent
4d6b314b60
commit
22aeafeafd
2 changed files with 59 additions and 6 deletions
|
@ -50,13 +50,14 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
|
|||
[/side]
|
||||
|
||||
[side]
|
||||
#controller=human
|
||||
controller=human
|
||||
name=FormulaAI
|
||||
type=Dark Sorcerer
|
||||
side=2
|
||||
canrecruit=1
|
||||
recruit=Skeleton,Skeleton Archer,Walking Corpse,Ghost,Vampire Bat,Dark Adept,Ghoul
|
||||
gold=100
|
||||
shroud=yes
|
||||
|
||||
[unit]
|
||||
x,y=8,5
|
||||
|
@ -75,11 +76,30 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
|
|||
generate_description=yes
|
||||
formula="move(me.loc, nearest_loc(nearest_loc(me.loc,map(filter(map.terrain,id='castle'),loc)),unit_moves(me.loc)))"
|
||||
[/unit]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[unit]
|
||||
x,y=6,20
|
||||
type="Ghost"
|
||||
generate_description=yes
|
||||
formula="if(size(filter(unit_moves(me.loc),units_can_reach(enemy_moves, self))) != 0, fallback('default'), if(size(villages) != 0, move(me.loc, nearest_loc(nearest_loc(me.loc,villages),unit_moves(me.loc))), if(size(shroud) = 0, fallback('default'), move(me.loc, nearest_loc(nearest_loc(me.loc,shroud),unit_moves(me.loc))))))
|
||||
where villages = filter(unit_moves(me.loc),is_unowned_village(map,x,y)),
|
||||
shroud = find_shroud()"
|
||||
[/unit]
|
||||
[unit]
|
||||
x,y=15,22
|
||||
type="Ghost"
|
||||
generate_description=yes
|
||||
formula="if(size(filter(unit_moves(me.loc),units_can_reach(enemy_moves, self))) != 0, fallback('default'), if(size(villages) != 0, move(me.loc, nearest_loc(nearest_loc(me.loc,villages),unit_moves(me.loc))), if(size(shroud) = 0, fallback('default'), move(me.loc, nearest_loc(nearest_loc(me.loc,shroud),unit_moves(me.loc))))))
|
||||
where villages = filter(unit_moves(me.loc),is_unowned_village(map,x,y)),
|
||||
shroud = find_shroud()"
|
||||
[/unit]
|
||||
[unit]
|
||||
x,y=12,19
|
||||
type="Ghost"
|
||||
generate_description=yes
|
||||
formula="if(size(filter(unit_moves(me.loc),units_can_reach(enemy_moves, self))) != 0, fallback('default'), if(size(villages) != 0, move(me.loc, nearest_loc(nearest_loc(me.loc,villages),unit_moves(me.loc))), if(size(shroud) = 0, fallback('default'), move(me.loc, nearest_loc(nearest_loc(me.loc,shroud),unit_moves(me.loc))))))
|
||||
where villages = filter(unit_moves(me.loc),is_unowned_village(map,x,y)),
|
||||
shroud = find_shroud()"
|
||||
[/unit]
|
||||
|
||||
ai_algorithm=formula_ai
|
||||
[ai]
|
||||
|
|
|
@ -580,6 +580,37 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
class is_unowned_village_function : public function_expression {
|
||||
public:
|
||||
explicit is_unowned_village_function(const args_list& args, const formula_ai& ai)
|
||||
: function_expression("is_unowned_village", args, 2, 3),
|
||||
ai_(ai)
|
||||
{}
|
||||
private:
|
||||
variant execute(const formula_callable& variables) const {
|
||||
|
||||
const gamemap& m = convert_variant<gamemap_callable>(args()[0]->evaluate(variables))->get_gamemap();
|
||||
const std::set<gamemap::location>& my_villages = ai_.current_team().villages();
|
||||
|
||||
gamemap::location loc;
|
||||
if(args().size() == 2) {
|
||||
loc = convert_variant<location_callable>(args()[1]->evaluate(variables))->loc();
|
||||
} else {
|
||||
loc = gamemap::location( args()[1]->evaluate(variables).as_int() - 1,
|
||||
args()[2]->evaluate(variables).as_int() - 1 );
|
||||
}
|
||||
|
||||
if(m.is_village(loc) && (my_villages.count(loc)==0) ) {
|
||||
return variant(true);
|
||||
} else {
|
||||
return variant(false);
|
||||
}
|
||||
}
|
||||
|
||||
const formula_ai& ai_;
|
||||
};
|
||||
|
||||
|
||||
class unit_at_function : public function_expression {
|
||||
public:
|
||||
unit_at_function(const args_list& args, const formula_ai& ai_object)
|
||||
|
@ -856,6 +887,8 @@ expression_ptr ai_function_symbol_table::create_function(const std::string &fn,
|
|||
return expression_ptr(new recruit_function(args));
|
||||
} else if(fn == "is_village") {
|
||||
return expression_ptr(new is_village_function(args));
|
||||
} else if(fn == "is_unowned_village") {
|
||||
return expression_ptr(new is_unowned_village_function(args, ai_));
|
||||
} else if(fn == "unit_at") {
|
||||
return expression_ptr(new unit_at_function(args, ai_));
|
||||
} else if(fn == "unit_moves") {
|
||||
|
|
Loading…
Add table
Reference in a new issue