aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/clientlinkableobject.cpp123
-rw-r--r--src/clientlinkableobject.h80
-rw-r--r--src/content_cao.cpp83
-rw-r--r--src/content_sao.cpp2
-rw-r--r--src/environment.cpp15
-rw-r--r--src/environment.h3
-rw-r--r--src/mesh.cpp99
-rw-r--r--src/mesh.h19
-rw-r--r--src/scriptapi.cpp91
-rw-r--r--src/serverlinkableobject.cpp53
-rw-r--r--src/serverlinkableobject.h62
-rw-r--r--src/serverobject.cpp12
-rw-r--r--src/serverobject.h9
14 files changed, 621 insertions, 32 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ee02d66f0..a736991b4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -114,6 +114,7 @@ set(common_SRCS
collision.cpp
nodemetadata.cpp
serverobject.cpp
+ serverlinkableobject.cpp
noise.cpp
porting.cpp
materials.cpp
@@ -166,6 +167,7 @@ set(minetest_SRCS
camera.cpp
clouds.cpp
clientobject.cpp
+ clientlinkableobject.cpp
guiMainMenu.cpp
guiKeyChangeMenu.cpp
guiMessageMenu.cpp
diff --git a/src/clientlinkableobject.cpp b/src/clientlinkableobject.cpp
new file mode 100644
index 000000000..917edbd53
--- /dev/null
+++ b/src/clientlinkableobject.cpp
@@ -0,0 +1,123 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2012 sapier sapier at gmx dot net
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "clientlinkableobject.h"
+
+ClientLinkableObject::ClientLinkableObject() {
+
+ this->m_Parent = NULL;
+}
+
+ClientLinkableObject::~ClientLinkableObject() {
+ if (this->isLinked())
+ this->unlink(this);
+}
+
+
+void ClientLinkableObject::link(ClientLinkableObject* entity) {
+ //TODO check if entity is already linkt (shouldn't be the case but just to be sure)
+ this->m_LinkedObjects.push_back(entity);
+}
+
+void ClientLinkableObject::unlink(ClientLinkableObject* entity) {
+ this->m_LinkedObjects.remove(entity);
+}
+
+
+void ClientLinkableObject::stepLinkedObjects(v3f pos,float dtime) {
+ for(std::list<ClientLinkableObject*>::iterator i = this->m_LinkedObjects.begin();
+ i != this->m_LinkedObjects.end(); i++) {
+ (*i)->setPosition(pos,dtime);
+ }
+}
+
+bool ClientLinkableObject::handleLinkUnlinkMessages(u8 cmd,std::istringstream* is,ClientEnvironment *m_env) {
+ if(cmd == AO_Message_type::Link) // Link entity
+ {
+ //Object to link entity to
+ u16 object_id = readU16(*is);
+ //offset against linked object
+ v3f offset = readV3F1000(*is);
+
+ ClientActiveObject* parent_cao = m_env->getActiveObject(object_id);
+
+ ClientLinkableObject* parent = dynamic_cast<ClientLinkableObject*>(parent_cao);
+
+ if (parent != NULL) {
+ this->linkEntity(offset,parent);
+ }
+ else {
+ errorstream << "Invalid object to link to!" << std::endl;
+ }
+ return true;
+
+ }
+ else if(cmd == AO_Message_type::UnLink) // UnLink entity
+ {
+ if (this->m_Parent == NULL) {
+ errorstream << "Unlinking object not linked!" << std::endl;
+ }
+
+ this->unlinkEntity();
+ return true;
+ }
+
+ return false;
+}
+
+
+bool ClientLinkableObject::linkEntity(v3f offset, ClientLinkableObject* parent) {
+ //already linked unlink first
+ if (this->m_Parent != NULL) {
+ return false;
+ }
+
+ //TODO add linkchain support
+ if (this->m_LinkedObjects.size() > 0) {
+ return false;
+ }
+
+ parent->link(this);
+ updateLinkState(true);
+ this->m_linkOffset = offset;
+ this->m_Parent = parent;
+ return true;
+}
+
+
+bool ClientLinkableObject::unlinkEntity() {
+ if (this->m_Parent != NULL) {
+
+ updateLinkState(false);
+ this->m_Parent->unlink(this);
+ this->m_Parent = NULL;
+ return true;
+
+ }
+
+ return false;
+}
+
+bool ClientLinkableObject::isLinked() {
+ if (this->m_Parent != NULL)
+ return true;
+ else
+ return false;
+}
diff --git a/src/clientlinkableobject.h b/src/clientlinkableobject.h
new file mode 100644
index 000000000..a6192d58c
--- /dev/null
+++ b/src/clientlinkableobject.h
@@ -0,0 +1,80 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2012 sapier sapier at gmx dot net
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef CLIENTLINKABLEOBJECT_H_
+#define CLIENTLINKABLEOBJECT_H_
+
+#include <list>
+#include <sstream>
+#include <irrlichttypes.h>
+#include "clientobject.h"
+#include "environment.h"
+#include "content_object.h"
+#include "utility.h"
+#include "log.h"
+
+
+//this ain't the right place to define this but until cao/sao split
+//is decided it'll have to stay here
+struct AO_Message_type {
+ static const u8 SetPosition = 0x00;
+ static const u8 SetTextureMod = 0x01;
+ static const u8 SetSprite = 0x02;
+ static const u8 Punched = 0x03;
+ static const u8 TakeDamage = 0x04;
+ static const u8 Shoot = 0x05;
+ static const u8 Link = 0x06;
+ static const u8 UnLink = 0x07;
+};
+
+
+class ClientLinkableObject {
+ public:
+ ClientLinkableObject();
+ ~ClientLinkableObject();
+ //internal communication between entitys NOT to be used by user
+ void link(ClientLinkableObject* entity);
+ void unlink(ClientLinkableObject* entity);
+
+ virtual void setPosition(v3f toset, float dtime) = 0;
+ virtual void updateLinkState(bool value) = 0;
+
+ protected:
+ void stepLinkedObjects(v3f pos,float dtime);
+
+ bool handleLinkUnlinkMessages(u8 cmd,std::istringstream* is,ClientEnvironment *m_env);
+
+
+ //user driven functions (exported by lua)
+ bool linkEntity(v3f offset, ClientLinkableObject* parent);
+ bool unlinkEntity();
+
+ bool isLinked();
+ v3f m_linkOffset;
+
+
+ private:
+ ClientLinkableObject* m_Parent;
+
+ std::list<ClientLinkableObject*> m_LinkedObjects;
+};
+
+
+#endif /* CLIENTLINKABLEOBJECT_H_ */
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index a2708674b..37da0f67d 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -1818,6 +1818,24 @@ public:
m_meshnode->setScale(v3f(1));
// Will be shown when we know the brightness
m_meshnode->setVisible(false);
+ } else if (m_prop->visual == "plant") {
+ infostream<<"LuaEntityCAO::addToScene(): plant"<<std::endl;
+ scene::IMesh *mesh = createPlantMesh(v3f(BS,BS,BS));
+ m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
+ mesh->drop();
+
+ m_meshnode->setScale(v3f(1));
+ // Will be shown when we know the brightness
+ m_meshnode->setVisible(false);
+ } else if (m_prop->visual == "cube_disorted") {
+ infostream<<"LuaEntityCAO::addToScene(): irregular_cube"<<std::endl;
+ scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS), m_prop->collisionbox);
+ m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
+ mesh->drop();
+
+ m_meshnode->setScale(v3f(1));
+ // Will be shown when we know the brightness
+ m_meshnode->setVisible(false);
} else {
infostream<<"LuaEntityCAO::addToScene(): \""<<m_prop->visual
<<"\" not supported"<<std::endl;
@@ -1970,26 +1988,51 @@ public:
tsrc->getTextureRaw(texturestring));
}
if(m_meshnode){
- for (u32 i = 0; i < 6; ++i)
- {
- std::string texturestring = "unknown_block.png";
- if(m_prop->textures.size() > i)
- texturestring = m_prop->textures[i];
- texturestring += mod;
- AtlasPointer ap = tsrc->getTexture(texturestring);
-
- // Get the tile texture and atlas transformation
- video::ITexture* atlas = ap.atlas;
- v2f pos = ap.pos;
- v2f size = ap.size;
-
- // Set material flags and texture
- video::SMaterial& material = m_meshnode->getMaterial(i);
- material.setFlag(video::EMF_LIGHTING, false);
- material.setFlag(video::EMF_BILINEAR_FILTER, false);
- material.setTexture(0, atlas);
- material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
- material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
+ if (m_prop->visual == "plant") {
+ for (u32 i = 0; i < 4; ++i) {
+ std::string texturestring = "unknown_block.png";
+ if(m_prop->textures.size() > 0)
+ texturestring = m_prop->textures[0];
+ texturestring += mod;
+ AtlasPointer ap = tsrc->getTexture(texturestring);
+
+ // Get the tile texture and atlas transformation
+ video::ITexture* atlas = ap.atlas;
+ v2f pos = ap.pos;
+ v2f size = ap.size;
+
+ // Set material flags and texture
+ video::SMaterial& material = m_meshnode->getMaterial(i);
+ material.setFlag(video::EMF_LIGHTING, false);
+ material.setFlag(video::EMF_BILINEAR_FILTER, false);
+ material.setTexture(0, atlas);
+ material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
+ material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
+ material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+ }
+ }
+ else {
+ for (u32 i = 0; i < 6; ++i) {
+ std::string texturestring = "unknown_block.png";
+ if(m_prop->textures.size() > i)
+ texturestring = m_prop->textures[i];
+ texturestring += mod;
+ AtlasPointer ap = tsrc->getTexture(texturestring);
+
+ // Get the tile texture and atlas transformation
+ video::ITexture* atlas = ap.atlas;
+ v2f pos = ap.pos;
+ v2f size = ap.size;
+
+ // Set material flags and texture
+ video::SMaterial& material = m_meshnode->getMaterial(i);
+ material.setFlag(video::EMF_LIGHTING, false);
+ material.setFlag(video::EMF_BILINEAR_FILTER, false);
+ material.setTexture(0, atlas);
+ material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
+ material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
+ material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+ }
}
}
}
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 02be64c64..4a2bef872 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -27,8 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "materials.h" // For MaterialProperties and ToolDiggingProperties
#include "gamedef.h"
-core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
-
/* Some helper functions */
// Y is copied, X and Z change is limited
diff --git a/src/environment.cpp b/src/environment.cpp
index 7c2aef272..d332e5d53 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -765,6 +765,21 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
abmhandler.apply(block);
}
+core::list<MapNode> ServerEnvironment::getNodesInsideRadius(v3s16 pos, float radius)
+{
+ core::list<MapNode> nodes;
+ for (int i = pos.X - radius; i < pos.X + radius; i ++)
+ for (int j = pos.Y - radius; j < pos.Y + radius; j ++)
+ for (int k = pos.Z - radius; k < pos.Z + radius; k ++) {
+ v3s16 current_pos = v3s16(i,j,k);
+ if (current_pos.getDistanceFrom(pos) < radius) {
+ MapNode n = m_map->getNodeNoEx(current_pos);
+ nodes.push_back(n);
+ }
+ }
+ return nodes;
+}
+
void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm)
{
m_abms.push_back(ABMWithState(abm));
diff --git a/src/environment.h b/src/environment.h
index 89c9fd676..2391025ba 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -271,6 +271,9 @@ public:
-------------------------------------------
*/
+ // Find all nodes inside a radius around a point
+ core::list<MapNode> getNodesInsideRadius(v3s16 pos, float radius);
+
// Find all active objects inside a radius around a point
std::set<u16> getObjectsInsideRadius(v3f pos, float radius);
diff --git a/src/mesh.cpp b/src/mesh.cpp
index 5afb4af59..44b3b9bbb 100644
--- a/src/mesh.cpp
+++ b/src/mesh.cpp
@@ -92,6 +92,105 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale)
return anim_mesh;
}
+scene::IAnimatedMesh* createCubeMesh(v3f scale,core::aabbox3d<f32> box)
+{
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[24] =
+ {
+ // Up
+ video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,1,0, c, 0,1),
+ video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,1,0, c, 0,0),
+ video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,1,0, c, 1,0),
+ video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,1,0, c, 1,1),
+ // Down
+ video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,-1,0, c, 0,0),
+ video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,-1,0, c, 1,0),
+ video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,-1,0, c, 1,1),
+ video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,-1,0, c, 0,1),
+ // Right
+ video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 1,0,0, c, 0,1),
+ video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 1,0,0, c, 0,0),
+ video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 1,0,0, c, 1,0),
+ video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 1,0,0, c, 1,1),
+ // Left
+ video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, -1,0,0, c, 1,1),
+ video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, -1,0,0, c, 0,1),
+ video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, -1,0,0, c, 0,0),
+ video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, -1,0,0, c, 1,0),
+ // Back
+ video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,0,1, c, 1,1),
+ video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,0,1, c, 0,1),
+ video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,0,1, c, 0,0),
+ video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,0,1, c, 1,0),
+ // Front
+ video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,0,-1, c, 0,1),
+ video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,0,-1, c, 0,0),
+ video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,0,-1, c, 1,0),
+ video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,0,-1, c, 1,1),
+ };
+
+ u16 indices[6] = {0,1,2,2,3,0};
+
+ scene::SMesh *mesh = new scene::SMesh();
+ for (u32 i=0; i<6; ++i)
+ {
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ buf->append(vertices + 4 * i, 4, indices, 6);
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+ }
+ scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
+ mesh->drop();
+ scaleMesh(anim_mesh, scale); // also recalculates bounding box
+ return anim_mesh;
+}
+
+scene::IAnimatedMesh* createPlantMesh(v3f scale)
+{
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[16] =
+ {
+ // Plane 1 Front
+ video::S3DVertex(-0.5,-0.5,-0.5, 0.5,0,-0.5, c, 0,1),
+ video::S3DVertex(-0.5,+0.5,-0.5, 0.5,0,-0.5, c, 0,0),
+ video::S3DVertex(+0.5,+0.5,+0.5, 0.5,0,-0.5, c, 1,0),
+ video::S3DVertex(+0.5,-0.5,+0.5, 0.5,0,-0.5, c, 1,1),
+ // Plane 1 Back
+ video::S3DVertex(+0.5,-0.5,+0.5, -0.5,0,0.5, c, 1,1),
+ video::S3DVertex(+0.5,+0.5,+0.5, -0.5,0,0.5, c, 1,0),
+ video::S3DVertex(-0.5,+0.5,-0.5, -0.5,0,0.5, c, 0,0),
+ video::S3DVertex(-0.5,-0.5,-0.5, -0.5,0,0.5, c, 0,1),
+
+ // Plane 2 Front
+ video::S3DVertex(-0.5,-0.5,+0.5, -0.5,0,-0.5, c, 1,1),
+ video::S3DVertex(-0.5,+0.5,+0.5, -0.5,0,-0.5, c, 1,0),
+ video::S3DVertex(+0.5,+0.5,-0.5, -0.5,0,-0.5, c, 0,0),
+ video::S3DVertex(+0.5,-0.5,-0.5, -0.5,0,-0.5, c, 0,1),
+
+ // Plane 2 Back
+ video::S3DVertex(+0.5,-0.5,-0.5, 0.5,0,0.5, c, 0,1),
+ video::S3DVertex(+0.5,+0.5,-0.5, 0.5,0,0.5, c, 0,0),
+ video::S3DVertex(-0.5,+0.5,+0.5, 0.5,0,0.5, c, 1,0),
+ video::S3DVertex(-0.5,-0.5,+0.5, 0.5,0,0.5, c, 1,1)
+
+ };
+
+ u16 indices[6] = {0,1,2,2,3,0};
+
+ scene::SMesh *mesh = new scene::SMesh();
+ for (u32 i=0; i<4; ++i)
+ {
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ buf->append(vertices + 4 * i, 4, indices, 6);
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+ }
+ scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
+ mesh->drop();
+ scaleMesh(anim_mesh, scale); // also recalculates bounding box
+ return anim_mesh;
+}
+
static scene::IAnimatedMesh* extrudeARGB(u32 twidth, u32 theight, u8 *data)
{
const s32 argb_wstep = 4 * twidth;
diff --git a/src/mesh.h b/src/mesh.h
index 57166235e..631dc0cca 100644
--- a/src/mesh.h
+++ b/src/mesh.h
@@ -33,6 +33,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
scene::IAnimatedMesh* createCubeMesh(v3f scale);
/*
+ Create a new cube mesh not linked to mapnode size.
+ Vertices are defined by given box.
+
+ The resulting mesh has 6 materials (up, down, right, left, back, front)
+ which must be defined by the caller.
+*/
+scene::IAnimatedMesh* createCubeMesh(v3f scale,core::aabbox3d<f32> box);
+
+/*
Create a new extruded mesh from a texture.
Maximum bounding box is (+-scale.X/2, +-scale.Y/2, +-scale.Z).
Thickness is in Z direction.
@@ -42,6 +51,16 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale);
scene::IAnimatedMesh* createExtrudedMesh(video::ITexture *texture,
video::IVideoDriver *driver, v3f scale);
+
+/*
+ Create a new plant style mesh.
+ Vertices are at (+-scale.X/2, +-scale.Y/2, +-scale.Z/2).
+
+ The resulting mesh has 4 materials (right, left, back, front)
+ which must be defined by the caller.
+*/
+scene::IAnimatedMesh* createPlantMesh(v3f scale);
+
/*
Multiplies each vertex coordinate by the specified scaling factors
(componentwise vector multiplication).
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index a064cd688..23063a3c8 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -45,6 +45,7 @@ extern "C" {
#include "mapblock.h" // For getNodeBlockPos
#include "content_nodemeta.h"
#include "utility.h"
+#include "serverlinkableobject.h"
static void stackDump(lua_State *L, std::ostream &o)
{
@@ -2211,7 +2212,7 @@ private:
get_server(L)->SendMovePlayer(player);
return 0;
}
-
+
// moveto(self, pos, continuous=false)
static int l_moveto(lua_State *L)
{
@@ -2540,6 +2541,62 @@ private:
return 1;
}
+ // link(parent, offset)
+ static int l_link(lua_State *L)
+ {
+ ObjectRef *ref_child = checkobject(L, 1);
+ ObjectRef *ref_parent = checkobject(L, 2);
+ v3f offset = checkFloatPos(L, 3);
+
+ ServerActiveObject *child = getobject(ref_child);
+ ServerActiveObject *parent = getobject(ref_parent);
+
+ if ((child == NULL) || (parent == NULL)) {
+ errorstream << "LUA: link(): invalid parameters" << std::endl;
+ return 0;
+ }
+
+
+ ServerLinkableObject* child_lua = dynamic_cast<ServerLinkableObject*>(child);
+ ServerLinkableObject* parent_lua = dynamic_cast<ServerLinkableObject*>(parent);
+
+ if (child_lua == NULL) return 0;
+ if (parent_lua == NULL) return 0;
+
+ if (child_lua->linkEntity(parent,offset)) {
+ lua_pushboolean(L, true);
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
+
+ // unlink()
+ static int l_unlink(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+
+ ServerActiveObject *obj = getobject(ref);
+
+ if (obj == NULL) {
+ errorstream << "LUA: unlink(): invalid parameters" << std::endl;
+ return 0;
+ }
+
+ ServerLinkableObject* tolink = dynamic_cast<ServerLinkableObject*>(obj);
+
+ if (tolink == NULL) return 0;
+
+ if (tolink->unlinkEntity()) {
+ lua_pushboolean(L, true);
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
+
public:
ObjectRef(ServerActiveObject *object):
m_object(object)
@@ -2633,6 +2690,8 @@ const luaL_reg ObjectRef::methods[] = {
method(ObjectRef, get_look_dir),
method(ObjectRef, get_look_pitch),
method(ObjectRef, get_look_yaw),
+ method(ObjectRef, link),
+ method(ObjectRef, unlink),
{0,0}
};
@@ -2913,6 +2972,35 @@ private:
return 1;
}
+ // EnvRef:get_objects_inside_radius(pos, radius)
+ static int l_get_nodes_inside_radius(lua_State *L)
+ {
+ // Get the table insert function
+ lua_getglobal(L, "table");
+ lua_getfield(L, -1, "insert");
+ int table_insert = lua_gettop(L);
+ // Get environemnt
+ EnvRef *o = checkobject(L, 1);
+ ServerEnvironment *env = o->m_env;
+ if(env == NULL) return 0;
+ // Do it
+ v3s16 pos = read_v3s16(L, 2);
+ float radius = luaL_checknumber(L, 3);// * BS;
+ core::list<MapNode> nodes = env->getNodesInsideRadius(pos, radius);
+ lua_newtable(L);
+ int table = lua_gettop(L);
+ for(core::list<MapNode>::Iterator
+ i = nodes.begin(); i != nodes.end(); i++){
+ // Insert object reference into table
+ lua_pushvalue(L, table_insert);
+ lua_pushvalue(L, table);
+ pushnode(L, *i, env->getGameDef()->ndef());
+ if(lua_pcall(L, 2, 0, 0))
+ script_error(L, "error: %s", lua_tostring(L, -1));
+ }
+ return 1;
+ }
+
// EnvRef:set_timeofday(val)
// val = 0...1
static int l_set_timeofday(lua_State *L)
@@ -3022,6 +3110,7 @@ const luaL_reg EnvRef::methods[] = {
method(EnvRef, get_meta),
method(EnvRef, get_player_by_name),
method(EnvRef, get_objects_inside_radius),
+ method(EnvRef, get_nodes_inside_radius),
method(EnvRef, set_timeofday),
method(EnvRef, get_timeofday),
{0,0}
diff --git a/src/serverlinkableobject.cpp b/src/serverlinkableobject.cpp
new file mode 100644
index 000000000..f8e401b4a
--- /dev/null
+++ b/src/serverlinkableobject.cpp
@@ -0,0 +1,53 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2012 sapier sapier at gmx dot net
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "serverlinkableobject.h"
+
+
+ServerLinkableObject::ServerLinkableObject() {
+ this->m_Linked = false;
+}
+
+ServerLinkableObject::~ServerLinkableObject() {}
+
+bool ServerLinkableObject::linkEntity(ServerActiveObject* parent,v3f offset) {
+ //check if entity is in correct state
+ if (this->m_Linked == true) {
+ errorstream<<"ServerLinkableObject: link but object already linked!"<<std::endl;
+ return false;
+ }
+ this->m_Linked = true;
+
+ errorstream<<"ServerLinkableObject: try to send link message!"<<std::endl;
+ return sendLinkMsg(parent,offset);
+}
+
+bool ServerLinkableObject::unlinkEntity() {
+ //check if entity is in correct state
+ if (this->m_Linked == false) {
+ errorstream<<"ServerLinkableObject: unlink but object not linked!"<<std::endl;
+ return false;
+ }
+
+ this->m_Linked = false;
+
+ errorstream<<"ServerLinkableObject: try to send unlink message!"<<std::endl;
+ return sendUnlinkMsg();
+}
diff --git a/src/serverlinkableobject.h b/src/serverlinkableobject.h
new file mode 100644
index 000000000..182ebb12b
--- /dev/null
+++ b/src/serverlinkableobject.h
@@ -0,0 +1,62 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2012 sapier sapier at gmx dot net
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef SERVERLINKABLEOBJECT_H_
+#define SERVERLINKABLEOBJECT_H_
+
+#include <sstream>
+#include <irrlichttypes.h>
+#include "serverobject.h"
+#include "content_object.h"
+#include "log.h"
+
+//this ain't the right place to define this but until cao/sao split
+//is decided it'll have to stay here
+struct AO_Message_type {
+ static const u8 SetPosition = 0x00;
+ static const u8 SetTextureMod = 0x01;
+ static const u8 SetSprite = 0x02;
+ static const u8 Punched = 0x03;
+ static const u8 TakeDamage = 0x04;
+ static const u8 Shoot = 0x05;
+ static const u8 Link = 0x06;
+ static const u8 UnLink = 0x07;
+};
+
+class ServerLinkableObject {
+ public:
+ ServerLinkableObject();
+ ~ServerLinkableObject();
+
+ bool linkEntity(ServerActiveObject* parent,v3f offset);
+ bool unlinkEntity();
+
+ virtual bool sendLinkMsg(ServerActiveObject* parent,v3f offset) = 0;
+ virtual bool sendUnlinkMsg() = 0;
+
+ protected:
+ inline bool isLinked() { return m_Linked; }
+
+ private:
+ bool m_Linked;
+
+};
+
+#endif /* SERVERLINKABLEOBJECT_H_ */
diff --git a/src/serverobject.cpp b/src/serverobject.cpp
index 2609e3015..76a70ca5b 100644
--- a/src/serverobject.cpp
+++ b/src/serverobject.cpp
@@ -43,8 +43,8 @@ ServerActiveObject* ServerActiveObject::create(u8 type,
const std::string &data)
{
// Find factory function
- core::map<u16, Factory>::Node *n;
- n = m_types.find(type);
+ core::map<u8, Factory>::Node *n;
+ n = ServerActiveObject::getTypes().find(type);
if(n == NULL)
{
// If factory is not found, just return.
@@ -58,13 +58,13 @@ ServerActiveObject* ServerActiveObject::create(u8 type,
return object;
}
-void ServerActiveObject::registerType(u16 type, Factory f)
+void ServerActiveObject::registerType(u8 type, Factory f)
{
- core::map<u16, Factory>::Node *n;
- n = m_types.find(type);
+ core::map<u8, Factory>::Node *n;
+ n = ServerActiveObject::getTypes().find(type);
if(n)
return;
- m_types.insert(type, f);
+ ServerActiveObject::getTypes().insert(type, f);
}
ItemStack ServerActiveObject::getWieldedItem() const
diff --git a/src/serverobject.h b/src/serverobject.h
index 380bf7302..844bfd2ff 100644
--- a/src/serverobject.h
+++ b/src/serverobject.h
@@ -209,14 +209,17 @@ protected:
typedef ServerActiveObject* (*Factory)
(ServerEnvironment *env, v3f pos,
const std::string &data);
- static void registerType(u16 type, Factory f);
+ static void registerType(u8 type, Factory f);
ServerEnvironment *m_env;
v3f m_base_position;
private:
- // Used for creating objects based on type
- static core::map<u16, Factory> m_types;
+ static core::map<u8, Factory>& getTypes()
+ {
+ static core::map<u8, Factory> types;
+ return types;
+ }
};
#endif