Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "chameleon.h"
- #include "pieces/piece.h"
- #include "utils/misc.h"
- #include "zones/zone.h"
- ///////////////////////////////////
- chameleon::chameleon( piece* _piece )
- : static_ability( ABILITY_TYPE_CHAMELEON, _piece )
- {
- desc = "Chameleon";
- desc_long = desc + " - This creature is considered to belong to all aspects of local allies.";
- is_executing = false;
- }
- ///////////////////////////////////
- void
- chameleon::init( game_state* _game_state, vector<piece*> _all_pieces )
- {
- f = boost::bind( &chameleon::get_aspects_hook, this, _1, _2, _3 );
- enable( _game_state );
- }
- ///////////////////////////////////
- void
- chameleon::enable( game_state* _game_state )
- {
- _game_state->get_aspects.add_modifier( _game_state, &f );
- }
- ///////////////////////////////////
- void
- chameleon::disable( game_state* _game_state )
- {
- _game_state->get_aspects.remove_modifier( _game_state, &f );
- }
- ///////////////////////////////////
- bool
- chameleon::get_aspects_hook( vector<int>& _aspects, game_state* _game_state, piece* _piece )
- {
- if ( !is_executing )
- {
- if ( _piece == owning_piece
- && has_this_ability( _game_state )
- && can_use( _game_state )
- && _game_state->is_in_play( owning_piece )
- )
- {
- bool modified_aspects = false;
- /* Kicking off more queries, set to avoid infinite recursion, does not
- * need to go through undo engine since it will be set back in this
- * same function.
- */
- is_executing = true;
- foreach( piece* p, owning_piece->current_zone->pieces )
- {
- if ( _game_state->is_ally( owning_piece->controller, owning_piece, p ) )
- {
- vector<int> aspects = _game_state->get_aspects( _game_state, p );
- foreach( int aspect, aspects )
- {
- vector<int>::iterator iter = find( _aspects.begin(), _aspects.end(), aspect );
- if ( iter == _aspects.end() )
- {
- modified_aspects |= true;
- _aspects.push_back( aspect );
- }
- }
- }
- }
- is_executing = false;
- return modified_aspects;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement