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

Diff of /enigma/src/actors.cc

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

revision 1.41 by dheck, Fri Sep 12 21:51:39 2003 UTC revision 1.41.2.1 by dheck, Fri Sep 19 17:44:44 2003 UTC
# Line 26  Line 26 
26  #include "world.hh"  #include "world.hh"
27    
28  #include <cassert>  #include <cassert>
29    #include <iostream>
30    
31  using px::V2;  using px::V2;
32  using namespace world;  using namespace world;
# Line 43  Actor::Actor(const char *kind, const px: Line 44  Actor::Actor(const char *kind, const px:
44  }  }
45    
46  void  void
47    Actor::think(double dtime)
48    {
49        GridPos  field(actorinfo.pos);
50        Floor *fl = GetFloor(field);
51        Item *it = GetItem(field);
52        bool item_covers_floor = (it && it->covers_floor());
53        if (!item_covers_floor && fl)
54            fl->actor_contact(this);
55    }
56    
57    void
58  Actor::respawn()  Actor::respawn()
59  {  {
60      V2 p =(use_respawnpos) ? respawnpos : startingpos;      V2 p =(use_respawnpos) ? respawnpos : startingpos;
# Line 116  Actor::move() Line 128  Actor::move()
128      if (it && it->actor_hit(this))      if (it && it->actor_hit(this))
129          player::PickupItem(this, field);          player::PickupItem(this, field);
130    
     Floor *fl = GetFloor(field);  
     it = GetItem(field);        // Item may have changed  
     bool item_covers_floor = (it && it->covers_floor());  
     if (!item_covers_floor && fl)  
         fl->actor_contact(this);  
   
131      if (Stone *st = GetStone(field))      if (Stone *st = GetStone(field))
132          st->actor_inside(this);          st->actor_inside(this);
133    
# Line 168  Rotor::Rotor(const char *name, double ra Line 174  Rotor::Rotor(const char *name, double ra
174      set_attrib ("force", 10.0);      set_attrib ("force", 10.0);
175  }  }
176    
177  void Rotor::think (double /*dtime*/)  void Rotor::think (double dtime)
178  {  {
179      double range = 0, force = 0;      double range = 0, force = 0;
180      double_attrib("range", &range);      double_attrib("range", &range);
# Line 183  void Rotor::think (double /*dtime*/) Line 189  void Rotor::think (double /*dtime*/)
189              this->add_force (normalize(a->get_pos() - get_pos()) * force);              this->add_force (normalize(a->get_pos() - get_pos()) * force);
190          }          }
191      }      }
192        Actor::think(dtime);
193  }  }
194    
195    
# Line 310  namespace Line 317  namespace
317          static const double   SHIELD_TIME = 10.0;          static const double   SHIELD_TIME = 10.0;
318          enum HaloState { NOHALO, HALOBLINK, HALONORMAL } m_halostate;          enum HaloState { NOHALO, HALOBLINK, HALONORMAL } m_halostate;
319    
320            void disable_shield();
321          void update_halo();          void update_halo();
322          bool has_halo();          bool has_halo();
323          void change_state_noshield (State newstate);          void change_state_noshield (State newstate);
# Line 345  namespace Line 353  namespace
353    
354          bool is_dead()          { return state == DEAD; }          bool is_dead()          { return state == DEAD; }
355          bool is_flying()        { return state == JUMPING; }          bool is_flying()        { return state == JUMPING; }
356          bool is_on_floor()      { return state == NORMAL || state == SINKING || state == JUMP_VORTEX; }          bool is_on_floor()      { return state == NORMAL || state == SINKING || state == JUMP_VORTEX || state==APPEARING; }
357          bool can_drop_items()   { return state == NORMAL || state == SINKING || state == JUMP_VORTEX || state==JUMPING; }          bool can_drop_items()   { return state == NORMAL || state == SINKING || state == JUMP_VORTEX || state==JUMPING; }
358          bool can_pickup_items() { return state == NORMAL || state == SINKING || state == JUMP_VORTEX; }          bool can_pickup_items() { return state == NORMAL || state == SINKING || state == JUMP_VORTEX; }
359    
# Line 404  void BasicBall::message(const string &m, Line 412  void BasicBall::message(const string &m,
412      case JUMP_VORTEX:      case JUMP_VORTEX:
413          if (m == "laserhit")        change_state(SHATTERING);          if (m == "laserhit")        change_state(SHATTERING);
414          break;          break;
415        case APPEARING:
416            if ((m == "shatter" || m == "drown" || m == "fall")
417                && !has_halo())
418            {
419                std::cout  << "appearing " << m << " in state " << state << std::endl;
420                // give an "emergency" shield to the actor if it would die
421                // after appearing
422                m_shield_rest_time = 1.5;
423                update_halo();
424            }
425            break;
426      default:      default:
427          break;          break;
428      }      }
429    
430    
431      // Shield can be activated in all states except DEAD      // Shield can be activated in all states except DEAD
432    
433      if (state != DEAD && m == "shield") {      if (state != DEAD && m == "shield") {
# Line 458  void BasicBall::think(double dtime) Line 477  void BasicBall::think(double dtime)
477          m_shield_rest_time -= dtime;          m_shield_rest_time -= dtime;
478          update_halo();          update_halo();
479      }      }
480        Actor::think(dtime);
481  }  }
482    
483  void BasicBall::set_sink_model(const string &m)  void BasicBall::set_sink_model(const string &m)
# Line 484  void BasicBall::set_shine_model (bool sh Line 504  void BasicBall::set_shine_model (bool sh
504          set_model (modelname);          set_model (modelname);
505  }  }
506    
   
   
507  void BasicBall::animcb()  void BasicBall::animcb()
508  {  {
509      string kind=get_kind();      string kind=get_kind();
# Line 608  BasicBall::change_state(State newstate) Line 626  BasicBall::change_state(State newstate)
626          break;          break;
627      case DISAPPEARING:      case DISAPPEARING:
628          world::GrabActor(this);          world::GrabActor(this);
629            disable_shield();
630          set_model_cb(kind+"-disappear");          set_model_cb(kind+"-disappear");
 //        set_model_cb(kind+"-drown");  
631          break;          break;
632        case RESURRECTED:
633            disable_shield();
634            break;
635      default:      default:
636          break;          break;
637      }      }
638  }  }
639    
640    void
641    BasicBall::disable_shield()
642    {
643        if (has_halo()) {
644            m_shield_rest_time = 0;
645            update_halo();
646        }
647    }
648    
649  bool  bool
650  BasicBall::has_halo()  BasicBall::has_halo()
651  {  {
# Line 635  BasicBall::update_halo() Line 665  BasicBall::update_halo()
665          newstate = HALONORMAL;          newstate = HALONORMAL;
666    
667      if (newstate != m_halostate) {      if (newstate != m_halostate) {
668            if (m_halostate == NOHALO)
669                m_halosprite = display::AddSprite (get_pos(), "halo");
670          switch (newstate) {          switch (newstate) {
671          case NOHALO:          case NOHALO:
672              // remove halo              // remove halo
# Line 646  BasicBall::update_halo() Line 678  BasicBall::update_halo()
678              m_halosprite.replace_model (display::MakeModel ("halo-blink"));              m_halosprite.replace_model (display::MakeModel ("halo-blink"));
679              break;              break;
680          case HALONORMAL:          case HALONORMAL:
681              if (m_halostate == NOHALO)              m_halosprite.replace_model (display::MakeModel ("halo"));
                 m_halosprite = display::AddSprite (get_pos(), "halo");  
             else  
                 m_halosprite.replace_model (display::MakeModel ("halo"));  
682              break;              break;
683          }          }
684          m_halostate = newstate;          m_halostate = newstate;

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.41.2.1

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