/[enigma]/enigma/src/stones_simple.cc
ViewVC logotype

Diff of /enigma/src/stones_simple.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.53 by dheck, Fri Sep 12 21:56:28 2003 UTC revision 1.53.2.1 by dheck, Fri Sep 19 17:40:15 2003 UTC
# Line 1655  namespace Line 1655  namespace
1655  // Thief Stone  // Thief Stone
1656  //  //
1657  // Takes one item from inventory after actor hit.  // Takes one item from inventory after actor hit.
 //  
 // TODO: It should steal afer some period of time  
1658  //----------------------------------------  //----------------------------------------
1659  namespace  namespace
1660  {  {
1661      class ThiefStone : public Stone {      class ThiefStone : public Stone {
1662          CLONEOBJ(ThiefStone);          CLONEOBJ(ThiefStone);
1663    
1664            enum State { IDLE, EMERGING, RETREATING } state;
1665            int m_affected_player;
1666      public:      public:
1667          ThiefStone() : Stone("st-thief"), state(IDLE) { }          ThiefStone() : Stone("st-thief"), state(IDLE) {
1668                m_affected_player = -1;
1669            }
1670      private:      private:
         enum State { IDLE, STEALING } state;  
1671    
1672          void actor_hit(const StoneContact &sc) {          void actor_hit(const StoneContact &sc) {
1673              if (state==IDLE) {              if (state==IDLE) {
1674                  set_anim("st-thief-anim");                  set_anim("st-thief-emerge");
1675                  if (player::Inventory *inv = player::GetInventory(sc.actor))                  state = EMERGING;
1676                  {                  m_affected_player = -1;
1677                      int i = IntegerRand (0, inv->size()-1);                  sc.actor->int_attrib("player", &m_affected_player);
                     delete inv->yield_item(i);  
   
                     play_sound("thief");  
                     state = STEALING;  
                 }  
1678              }              }
1679          }          }
1680    
1681          void animcb() {          void animcb() {
1682              if (state == STEALING) {              switch (state) {
1683                  state = IDLE;              case EMERGING:
1684                  init_model();                  steal_from_player();
1685              }                  state = RETREATING;
1686                    set_anim("st-thief-retreat");
1687                    break;
1688                case RETREATING:
1689                    state = IDLE;
1690                    init_model();
1691                    break;
1692                default:
1693                    assert(0);
1694                }
1695          }          }
1696    
1697            void steal_from_player() {
1698                if (m_affected_player != -1) {
1699                    player::Inventory *inv = player::GetInventory(m_affected_player);
1700                    if (inv && inv->size() > 0)
1701                    {
1702                        int i = IntegerRand (0, inv->size()-1);
1703                        delete inv->yield_item(i);
1704                            
1705                        play_sound("thief");
1706                    }
1707                }
1708            }
1709    
1710          const char *collision_sound() {          const char *collision_sound() {
1711              return "st-thud";              return "st-thud";
1712          }          }

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.53.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26