m_id(id)
{
}
-
+
u16 getId()
{
return m_id;
}
virtual ActiveObjectType getType() const = 0;
- virtual bool getCollisionBox(aabb3f *toset) = 0;
- virtual bool collideWithObjects() = 0;
+ virtual bool getCollisionBox(aabb3f *toset) const = 0;
+ virtual bool collideWithObjects() const = 0;
protected:
u16 m_id; // 0 is invalid, "no id"
};
virtual void updateLightNoCheck(u8 light_at_pos){}
virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
virtual aabb3f *getSelectionBox() { return NULL; }
- virtual bool getCollisionBox(aabb3f *toset){return false;}
- virtual bool collideWithObjects(){return false;}
+ virtual bool getCollisionBox(aabb3f *toset) const { return false; }
+ virtual bool collideWithObjects() const { return false; }
virtual v3f getPosition(){return v3f(0,0,0);}
virtual float getYaw() const {return 0;}
virtual scene::ISceneNode *getSceneNode(){return NULL;}
void processMessage(const std::string &data);
- bool getCollisionBox(aabb3f *toset) { return false; }
+ bool getCollisionBox(aabb3f *toset) const { return false; }
private:
scene::IMeshSceneNode *m_node;
v3f m_position;
std::string infoText()
{return m_infotext;}
- bool getCollisionBox(aabb3f *toset) { return false; }
+ bool getCollisionBox(aabb3f *toset) const { return false; }
private:
aabb3f m_selection_box;
scene::IMeshSceneNode *m_node;
}
}
-bool GenericCAO::getCollisionBox(aabb3f *toset)
+bool GenericCAO::getCollisionBox(aabb3f *toset) const
{
if (m_prop.physical)
{
ClientActiveObject *getParent();
- bool getCollisionBox(aabb3f *toset);
+ bool getCollisionBox(aabb3f *toset) const;
bool collideWithObjects();
#include "content_sao.h"
#include "util/serialize.h"
-#include "util/mathconstants.h"
#include "collision.h"
#include "environment.h"
-#include "settings.h"
-#include "serialization.h" // For compressZlib
#include "tool.h" // For ToolCapabilities
#include "gamedef.h"
#include "nodedef.h"
#include "server.h"
#include "scripting_game.h"
#include "genericobject.h"
-#include "log.h"
std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
}
}
- bool getCollisionBox(aabb3f *toset) {
- return false;
- }
-
- bool collideWithObjects() {
- return false;
- }
+ bool getCollisionBox(aabb3f *toset) const { return false; }
+ bool collideWithObjects() const { return false; }
private:
float m_timer1;
// Prototype (registers item for deserialization)
TestSAO proto_TestSAO(NULL, v3f(0,0,0));
+/*
+ UnitSAO
+ */
+
+UnitSAO::UnitSAO(ServerEnvironment *env, v3f pos):
+ ServerActiveObject(env, pos),
+ m_hp(-1),
+ m_yaw(0),
+ m_properties_sent(true),
+ m_armor_groups_sent(false),
+ m_animation_range(0,0),
+ m_animation_speed(0),
+ m_animation_blend(0),
+ m_animation_loop(true),
+ m_animation_sent(false),
+ m_bone_position_sent(false),
+ m_attachment_parent_id(0),
+ m_attachment_sent(false)
+{
+ // Initialize something to armor groups
+ m_armor_groups["fleshy"] = 100;
+}
/*
LuaEntitySAO
*/
m_registered(false),
m_velocity(0,0,0),
m_acceleration(0,0,0),
- m_properties_sent(true),
m_last_sent_yaw(0),
m_last_sent_position(0,0,0),
m_last_sent_velocity(0,0,0),
m_last_sent_position_timer(0),
- m_last_sent_move_precision(0),
- m_armor_groups_sent(false),
- m_animation_speed(0),
- m_animation_blend(0),
- m_animation_loop(true),
- m_animation_sent(false),
- m_bone_position_sent(false),
- m_attachment_parent_id(0),
- m_attachment_sent(false)
+ m_last_sent_move_precision(0)
{
// Only register type if no environment supplied
if(env == NULL){
ServerActiveObject::registerType(getType(), create);
return;
}
-
- // Initialize something to armor groups
- m_armor_groups["fleshy"] = 100;
}
LuaEntitySAO::~LuaEntitySAO()
m_armor_groups_sent = false;
}
-ItemGroupList LuaEntitySAO::getArmorGroups()
+const ItemGroupList &LuaEntitySAO::getArmorGroups()
{
return m_armor_groups;
}
m_attachment_child_ids.erase(child_id);
}
-UNORDERED_SET<int> LuaEntitySAO::getAttachmentChildIds()
+const UNORDERED_SET<int> &LuaEntitySAO::getAttachmentChildIds()
{
return m_attachment_child_ids;
}
m_messages_out.push(aom);
}
-bool LuaEntitySAO::getCollisionBox(aabb3f *toset) {
+bool LuaEntitySAO::getCollisionBox(aabb3f *toset) const
+{
if (m_prop.physical)
{
//update collision box
return false;
}
-bool LuaEntitySAO::collideWithObjects(){
+bool LuaEntitySAO::collideWithObjects() const
+{
return m_prop.collideWithObjects;
}
m_nocheat_dig_time(0),
m_wield_index(0),
m_position_not_sent(false),
- m_armor_groups_sent(false),
- m_properties_sent(true),
m_is_singleplayer(is_singleplayer),
- m_animation_speed(0),
- m_animation_blend(0),
- m_animation_loop(true),
- m_animation_sent(false),
- m_bone_position_sent(false),
- m_attachment_parent_id(0),
- m_attachment_sent(false),
m_breath(PLAYER_MAX_BREATH),
m_pitch(0),
m_fov(0),
m_physics_override_sent(false)
{
assert(m_peer_id != 0); // pre-condition
- m_armor_groups["fleshy"] = 100;
m_prop.hp_max = PLAYER_MAX_HP;
m_prop.physical = false;
m_inventory = &m_player->inventory;
}
+v3f PlayerSAO::getEyeOffset() const
+{
+ return v3f(0, BS * 1.625f, 0);
+}
+
std::string PlayerSAO::getDescription()
{
return std::string("player ") + m_player->getName();
m_armor_groups_sent = false;
}
-ItemGroupList PlayerSAO::getArmorGroups()
+const ItemGroupList &PlayerSAO::getArmorGroups()
{
return m_armor_groups;
}
m_attachment_child_ids.erase(child_id);
}
-UNORDERED_SET<int> PlayerSAO::getAttachmentChildIds()
+const UNORDERED_SET<int> &PlayerSAO::getAttachmentChildIds()
{
return m_attachment_child_ids;
}
return cheated;
}
-bool PlayerSAO::getCollisionBox(aabb3f *toset)
+bool PlayerSAO::getCollisionBox(aabb3f *toset) const
{
*toset = aabb3f(-BS * 0.30, 0.0, -BS * 0.30, BS * 0.30, BS * 1.75, BS * 0.30);
toset->MinEdge += m_base_position;
toset->MaxEdge += m_base_position;
return true;
}
-
-bool PlayerSAO::collideWithObjects()
-{
- return true;
-}
#include "serverobject.h"
#include "itemgroup.h"
#include "object_properties.h"
-#include "constants.h"
class UnitSAO: public ServerActiveObject
{
public:
- UnitSAO(ServerEnvironment *env, v3f pos):
- ServerActiveObject(env, pos),
- m_hp(-1), m_yaw(0) {}
+ UnitSAO(ServerEnvironment *env, v3f pos);
virtual ~UnitSAO() {}
virtual void setYaw(const float yaw) { m_yaw = yaw; }
protected:
s16 m_hp;
float m_yaw;
+
+ bool m_properties_sent;
+ struct ObjectProperties m_prop;
+
+ ItemGroupList m_armor_groups;
+ bool m_armor_groups_sent;
+
+ v2f m_animation_range;
+ float m_animation_speed;
+ float m_animation_blend;
+ bool m_animation_loop;
+ bool m_animation_sent;
+
+ // Stores position and rotation for each bone name
+ UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
+ bool m_bone_position_sent;
+
+ int m_attachment_parent_id;
+ UNORDERED_SET<int> m_attachment_child_ids;
+ std::string m_attachment_bone;
+ v3f m_attachment_position;
+ v3f m_attachment_rotation;
+ bool m_attachment_sent;
};
/*
void setHP(s16 hp);
s16 getHP() const;
void setArmorGroups(const ItemGroupList &armor_groups);
- ItemGroupList getArmorGroups();
+ const ItemGroupList &getArmorGroups();
void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
void addAttachmentChild(int child_id);
void removeAttachmentChild(int child_id);
- UNORDERED_SET<int> getAttachmentChildIds();
+ const UNORDERED_SET<int> &getAttachmentChildIds();
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
/* LuaEntitySAO-specific */
void setSprite(v2s16 p, int num_frames, float framelength,
bool select_horiz_by_yawpitch);
std::string getName();
- bool getCollisionBox(aabb3f *toset);
- bool collideWithObjects();
+ bool getCollisionBox(aabb3f *toset) const;
+ bool collideWithObjects() const;
private:
std::string getPropertyPacket();
void sendPosition(bool do_interpolate, bool is_movement_end);
std::string m_init_name;
std::string m_init_state;
bool m_registered;
- struct ObjectProperties m_prop;
v3f m_velocity;
v3f m_acceleration;
- ItemGroupList m_armor_groups;
-
- bool m_properties_sent;
float m_last_sent_yaw;
v3f m_last_sent_position;
v3f m_last_sent_velocity;
float m_last_sent_position_timer;
float m_last_sent_move_precision;
- bool m_armor_groups_sent;
-
- v2f m_animation_range;
- float m_animation_speed;
- float m_animation_blend;
- bool m_animation_loop;
- bool m_animation_sent;
-
- UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
- bool m_bone_position_sent;
-
- int m_attachment_parent_id;
- UNORDERED_SET<int> m_attachment_child_ids;
- std::string m_attachment_bone;
- v3f m_attachment_position;
- v3f m_attachment_rotation;
- bool m_attachment_sent;
};
/*
u16 getBreath() const { return m_breath; }
void setBreath(const u16 breath, bool send = true);
void setArmorGroups(const ItemGroupList &armor_groups);
- ItemGroupList getArmorGroups();
+ const ItemGroupList &getArmorGroups();
void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
void addAttachmentChild(int child_id);
void removeAttachmentChild(int child_id);
- UNORDERED_SET<int> getAttachmentChildIds();
+ const UNORDERED_SET<int> &getAttachmentChildIds();
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
m_is_singleplayer = is_singleplayer;
}
- bool getCollisionBox(aabb3f *toset);
- bool collideWithObjects();
+ bool getCollisionBox(aabb3f *toset) const;
+ bool collideWithObjects() const { return true; }
void initialize(RemotePlayer *player, const std::set<std::string> &privs);
v3f getEyePosition() const { return m_base_position + getEyeOffset(); }
- v3f getEyeOffset() const { return v3f(0, BS * 1.625f, 0); }
+ v3f getEyeOffset() const;
private:
std::string getPropertyPacket();
int m_wield_index;
bool m_position_not_sent;
- ItemGroupList m_armor_groups;
- bool m_armor_groups_sent;
- bool m_properties_sent;
- struct ObjectProperties m_prop;
// Cached privileges for enforcement
std::set<std::string> m_privs;
bool m_is_singleplayer;
- v2f m_animation_range;
- float m_animation_speed;
- float m_animation_blend;
- bool m_animation_loop;
- bool m_animation_sent;
-
- // Stores position and rotation for each bone name
- UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
- bool m_bone_position_sent;
-
- int m_attachment_parent_id;
- UNORDERED_SET<int> m_attachment_child_ids;
- std::string m_attachment_bone;
- v3f m_attachment_position;
- v3f m_attachment_rotation;
- bool m_attachment_sent;
u16 m_breath;
f32 m_pitch;
f32 m_fov;
if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
return 0;
- UNORDERED_SET<int> child_ids = co->getAttachmentChildIds();
- UNORDERED_SET<int>::iterator it;
+ const UNORDERED_SET<int> &child_ids = co->getAttachmentChildIds();
+ UNORDERED_SET<int>::const_iterator it;
for (it = child_ids.begin(); it != child_ids.end(); ++it) {
// Child can be NULL if it was deleted earlier
if (ServerActiveObject *child = env->getActiveObject(*it))
if (co == NULL)
return 0;
// Do it
- ItemGroupList groups = co->getArmorGroups();
- push_groups(L, groups);
+ push_groups(L, co->getArmorGroups());
return 1;
}
virtual void setArmorGroups(const ItemGroupList &armor_groups)
{}
- virtual ItemGroupList getArmorGroups()
- { return ItemGroupList(); }
+ virtual const ItemGroupList &getArmorGroups()
+ { static const ItemGroupList rv; return rv; }
virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity)
{}
virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop)
{}
virtual void removeAttachmentChild(int child_id)
{}
- virtual UNORDERED_SET<int> getAttachmentChildIds()
- { return UNORDERED_SET<int>(); }
+ virtual const UNORDERED_SET<int> &getAttachmentChildIds()
+ { static const UNORDERED_SET<int> rv; return rv; }
virtual ObjectProperties* accessObjectProperties()
{ return NULL; }
virtual void notifyObjectPropertiesModified()