Advertisement
Guest User

telengard

a guest
Nov 21st, 2009
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include "chameleon.h"
  2.  
  3. #include "pieces/piece.h"
  4. #include "utils/misc.h"
  5. #include "zones/zone.h"
  6.  
  7. ///////////////////////////////////
  8.  
  9. chameleon::chameleon( piece* _piece )
  10.     : static_ability( ABILITY_TYPE_CHAMELEON, _piece )
  11. {
  12.     desc         = "Chameleon";
  13.     desc_long    = desc + " - This creature is considered to belong to all aspects of local allies.";
  14.     is_executing = false;
  15. }
  16.  
  17. ///////////////////////////////////
  18.  
  19. void
  20. chameleon::init( game_state* _game_state, vector<piece*> _all_pieces )
  21. {
  22.     f = boost::bind( &chameleon::get_aspects_hook, this, _1, _2, _3 );
  23.  
  24.     enable( _game_state );
  25. }
  26.  
  27. ///////////////////////////////////
  28.  
  29. void
  30. chameleon::enable( game_state* _game_state )
  31. {
  32.     _game_state->get_aspects.add_modifier( _game_state, &f );
  33. }
  34.  
  35. ///////////////////////////////////
  36.  
  37. void
  38. chameleon::disable( game_state* _game_state )
  39. {
  40.     _game_state->get_aspects.remove_modifier( _game_state, &f );
  41. }
  42.  
  43. ///////////////////////////////////
  44.  
  45. bool
  46. chameleon::get_aspects_hook( vector<int>& _aspects, game_state* _game_state, piece* _piece )
  47. {
  48.     if ( !is_executing )
  49.     {
  50.         if (    _piece == owning_piece
  51.              && has_this_ability( _game_state )
  52.              && can_use( _game_state )
  53.              && _game_state->is_in_play( owning_piece )
  54.            )
  55.         {
  56.             bool modified_aspects = false;
  57.  
  58.             /* Kicking off more queries, set to avoid infinite recursion, does not
  59.              * need to go through undo engine since it will be set back in this
  60.              * same function.
  61.              */
  62.  
  63.             is_executing = true;
  64.  
  65.             foreach( piece* p, owning_piece->current_zone->pieces )
  66.             {
  67.                 if ( _game_state->is_ally( owning_piece->controller, owning_piece, p ) )
  68.                 {
  69.                     vector<int> aspects = _game_state->get_aspects( _game_state, p );
  70.  
  71.                     foreach( int aspect, aspects )
  72.                     {
  73.                         vector<int>::iterator iter = find( _aspects.begin(), _aspects.end(), aspect );
  74.  
  75.                         if ( iter == _aspects.end() )
  76.                         {
  77.                             modified_aspects |= true;
  78.                             _aspects.push_back( aspect );
  79.                         }
  80.                     }
  81.                 }
  82.             }
  83.  
  84.             is_executing = false;
  85.  
  86.             return modified_aspects;
  87.         }
  88.     }
  89.  
  90.     return false;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement