-
- {
- std::ostringstream os(std::ios::binary);
- // command (1 = damage)
- writeU8(os, 1);
- // amount
- writeU8(os, d);
- // create message and add to list
- ActiveObjectMessage aom(getId(), false, os.str());
- m_messages_out.push_back(aom);
- }
-}
-
-/*
- FireflySAO
-*/
-
-// Prototype
-FireflySAO proto_FireflySAO(NULL, v3f(0,0,0));
-
-FireflySAO::FireflySAO(ServerEnvironment *env, v3f pos):
- ServerActiveObject(env, pos),
- m_is_active(false),
- m_speed_f(0,0,0)
-{
- ServerActiveObject::registerType(getType(), create);
-
- m_oldpos = v3f(0,0,0);
- m_last_sent_position = v3f(0,0,0);
- m_yaw = 0;
- m_counter1 = 0;
- m_counter2 = 0;
- m_age = 0;
- m_touching_ground = false;
-}
-
-ServerActiveObject* FireflySAO::create(ServerEnvironment *env, v3f pos,
- const std::string &data)
-{
- std::istringstream is(data, std::ios::binary);
- char buf[1];
- // read version
- is.read(buf, 1);
- u8 version = buf[0];
- // check if version is supported
- if(version != 0)
- return NULL;
- return new FireflySAO(env, pos);
-}
-
-void FireflySAO::step(float dtime, bool send_recommended)
-{
- ScopeProfiler sp2(g_profiler, "FireflySAO::step avg", SPT_AVG);
-
- assert(m_env);
-
- if(m_is_active == false)
- {
- if(m_inactive_interval.step(dtime, 0.5)==false)
- return;
- }
-
- /*
- The AI
- */
-
- // Apply (less) gravity
- m_speed_f.Y -= dtime*3*BS;
-
- /*
- Move around if some player is close
- */
- bool player_is_close = false;
- // Check connected players
- core::list<Player*> players = m_env->getPlayers(true);
- core::list<Player*>::Iterator i;
- for(i = players.begin();
- i != players.end(); i++)
- {
- Player *player = *i;
- v3f playerpos = player->getPosition();
- if(m_base_position.getDistanceFrom(playerpos) < BS*10.0)
- {
- player_is_close = true;
- break;
- }
- }
-
- m_is_active = player_is_close;