forked from oerkki/voxelands
initial mob setup
This commit is contained in:
parent
4a1a81967b
commit
bf44366a5e
|
@ -139,6 +139,7 @@ set(common_SRCS
|
|||
content_craft.cpp
|
||||
content_craftitem.cpp
|
||||
content_toolitem.cpp
|
||||
content_mob.cpp
|
||||
content_mapnode.cpp
|
||||
content_mapnode_door.cpp
|
||||
content_mapnode_farm.cpp
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* content_mob.cpp
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2014 <lisa@ltmnet.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>
|
||||
************************************************************************/
|
||||
|
||||
#include "content_mob.h"
|
||||
#include "main.h"
|
||||
|
||||
std::map<content_t,struct MobFeatures> g_content_mob_features;
|
||||
|
||||
MobFeatures & content_mob_features(content_t i)
|
||||
{
|
||||
if ((i&CONTENT_MOB_MASK) != CONTENT_MOB_MASK)
|
||||
return g_content_mob_features[CONTENT_IGNORE];
|
||||
|
||||
std::map<content_t,struct MobFeatures>::iterator it = g_content_mob_features.find(i);
|
||||
if (it == g_content_mob_features.end())
|
||||
return g_content_mob_features[CONTENT_IGNORE];
|
||||
return it->second;
|
||||
}
|
||||
|
||||
#ifndef SERVER
|
||||
void MobFeatures::setTexture(std::string name)
|
||||
{
|
||||
if (g_texturesource)
|
||||
texture = g_texturesource->getTextureRaw(name);
|
||||
}
|
||||
void MobFeatures::setBoxTexture(u16 i, std::string name, u8 alpha)
|
||||
{
|
||||
if (g_texturesource)
|
||||
tiles[i].texture = g_texturesource->getTexture(name);
|
||||
|
||||
if (alpha != 255) {
|
||||
tiles[i].alpha = alpha;
|
||||
tiles[i].material_type = MATERIAL_ALPHA_VERTEX;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void content_mob_init()
|
||||
{
|
||||
g_content_mob_features.clear();
|
||||
|
||||
content_t i;
|
||||
MobFeatures *f = NULL;
|
||||
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
/************************************************************************
|
||||
* Minetest-c55
|
||||
* Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
*
|
||||
* mob.h
|
||||
* Copyright (C) Lisa 'darkrose' Milne 2014 <lisa@ltmnet.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>
|
||||
************************************************************************/
|
||||
|
||||
#ifndef MOB_HEADER
|
||||
#define MOB_HEADER
|
||||
|
||||
#include "mapnode.h"
|
||||
#include "serverobject.h"
|
||||
#ifndef SERVER
|
||||
#include "common_irrlicht.h"
|
||||
#endif
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
enum MobPunchAction
|
||||
{
|
||||
MPA_IGNORE = 0,
|
||||
MPA_DIE,
|
||||
MPA_PICKUP
|
||||
};
|
||||
|
||||
enum MobMotion
|
||||
{
|
||||
MM_STATIC = 0,
|
||||
MM_WANDER,
|
||||
MM_SEEKER,
|
||||
MM_SENTRY
|
||||
};
|
||||
|
||||
enum MobMotionType
|
||||
{
|
||||
MMT_WALK = 0,
|
||||
MMT_FLY,
|
||||
MMT_SWIM
|
||||
};
|
||||
|
||||
enum MobState
|
||||
{
|
||||
MS_WILD = 0,
|
||||
MS_TAME
|
||||
};
|
||||
|
||||
enum MobAnimation
|
||||
{
|
||||
MA_STAND = 0,
|
||||
MA_MOVE,
|
||||
MA_ATTACK
|
||||
};
|
||||
|
||||
#define CONTENT_MOB_MASK 0x2000
|
||||
|
||||
struct MobFeatures {
|
||||
content_t content;
|
||||
u8 level;
|
||||
#ifndef SERVER
|
||||
TileSpec tiles[6];
|
||||
video::ITexture *texture;
|
||||
#endif
|
||||
std::string model;
|
||||
std::map<MobAnimation,int[2]> animations;
|
||||
std::vector<aabb3f> nodeboxes;
|
||||
aabb3f collisionbox;
|
||||
|
||||
MobPunchAction punch_action;
|
||||
MobMotion motion;
|
||||
MobMotionType motion_type;
|
||||
MobState spawn_state;
|
||||
bool is_tamable;
|
||||
content_t tamed_mob;
|
||||
u16 hp;
|
||||
std::string dropped_item;
|
||||
|
||||
MobFeatures()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
/*
|
||||
Gets list of node boxes
|
||||
*/
|
||||
std::vector<aabb3f> getNodeBoxes()
|
||||
{
|
||||
return nodeboxes;
|
||||
}
|
||||
|
||||
void setNodeBox(aabb3f bb)
|
||||
{
|
||||
nodeboxes.clear();
|
||||
nodeboxes.push_back(bb);
|
||||
}
|
||||
|
||||
void addNodeBox(aabb3f bb)
|
||||
{
|
||||
nodeboxes.push_back(bb);
|
||||
}
|
||||
|
||||
void setCollisionBox(aabb3f cb)
|
||||
{
|
||||
collisionbox = cb;
|
||||
}
|
||||
|
||||
aabb3f getCollisionBox()
|
||||
{
|
||||
if (collisionbox.MinEdge != collisionbox.MaxEdge)
|
||||
return collisionbox;
|
||||
if (!nodeboxes.size())
|
||||
return aabb3f(-0.5,-0.5,-0.5,0.5,0.5,0.5);
|
||||
return nodeboxes[0];
|
||||
}
|
||||
|
||||
#ifdef SERVER
|
||||
void setTexture(std::string name)
|
||||
{}
|
||||
void setBoxTexture(u16 i, std::string name, u8 alpha=255)
|
||||
{}
|
||||
void setAllBoxTextures(std::string name, u8 alpha=255)
|
||||
{}
|
||||
#else
|
||||
void setTexture(std::string name);
|
||||
void setBoxTexture(u16 i, std::string name, u8 alpha=255);
|
||||
|
||||
void setAllBoxTextures(std::string name, u8 alpha=255)
|
||||
{
|
||||
for (u16 i=0; i<6; i++) {
|
||||
setBoxTexture(i, name, alpha);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void reset()
|
||||
{
|
||||
content = CONTENT_IGNORE;
|
||||
model = "";
|
||||
nodeboxes.clear();
|
||||
punch_action = MPA_DIE;
|
||||
motion = MM_STATIC;
|
||||
motion_type = MMT_WALK;
|
||||
spawn_state = MS_WILD;
|
||||
is_tamable = false;
|
||||
tamed_mob = CONTENT_IGNORE;
|
||||
hp = 20;
|
||||
dropped_item = "";
|
||||
}
|
||||
};
|
||||
|
||||
inline u8 mobLevelI(std::string level)
|
||||
{
|
||||
if (level == "destructive")
|
||||
return MOB_DESTRUCTIVE;
|
||||
if (level == "aggressive")
|
||||
return MOB_AGGRESSIVE;
|
||||
return MOB_PASSIVE;
|
||||
}
|
||||
|
||||
inline std::string mobLevelS(u8 level)
|
||||
{
|
||||
if (level == MOB_DESTRUCTIVE)
|
||||
return std::string("destructive");
|
||||
if (level == MOB_AGGRESSIVE)
|
||||
return std::string("aggressive");
|
||||
return std::string("passive");
|
||||
}
|
||||
|
||||
void content_mob_init();
|
||||
|
||||
#endif
|
|
@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include "content_sao.h"
|
||||
#include "content_mob.h"
|
||||
#include "collision.h"
|
||||
#include "environment.h"
|
||||
#include "settings.h"
|
||||
|
@ -44,63 +45,6 @@ void accelerate_xz(v3f &speed, v3f target_speed, f32 max_increase)
|
|||
speed.Y = target_speed.Y;
|
||||
}
|
||||
|
||||
/*
|
||||
TestSAO
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
TestSAO proto_TestSAO(NULL, 0, v3f(0,0,0));
|
||||
|
||||
TestSAO::TestSAO(ServerEnvironment *env, u16 id, v3f pos):
|
||||
ServerActiveObject(env, id, pos),
|
||||
m_timer1(0),
|
||||
m_age(0)
|
||||
{
|
||||
ServerActiveObject::registerType(getType(), create);
|
||||
}
|
||||
|
||||
ServerActiveObject* TestSAO::create(ServerEnvironment *env, u16 id, v3f pos,
|
||||
const std::string &data)
|
||||
{
|
||||
return new TestSAO(env, id, pos);
|
||||
}
|
||||
|
||||
void TestSAO::step(float dtime, bool send_recommended)
|
||||
{
|
||||
m_age += dtime;
|
||||
if(m_age > 10)
|
||||
{
|
||||
m_removed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
m_base_position.Y += dtime * BS * 2;
|
||||
if(m_base_position.Y > 8*BS)
|
||||
m_base_position.Y = 2*BS;
|
||||
|
||||
if(send_recommended == false)
|
||||
return;
|
||||
|
||||
m_timer1 -= dtime;
|
||||
if(m_timer1 < 0.0)
|
||||
{
|
||||
m_timer1 += 0.125;
|
||||
|
||||
std::string data;
|
||||
|
||||
data += itos(0); // 0 = position
|
||||
data += " ";
|
||||
data += itos(m_base_position.X);
|
||||
data += " ";
|
||||
data += itos(m_base_position.Y);
|
||||
data += " ";
|
||||
data += itos(m_base_position.Z);
|
||||
|
||||
ActiveObjectMessage aom(getId(), false, data);
|
||||
m_messages_out.push_back(aom);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
ItemSAO
|
||||
|
|
|
@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "mapblock.h"
|
||||
#include "serverobject.h"
|
||||
#include "content_sao.h"
|
||||
#include "content_mob.h"
|
||||
#include "mapgen.h"
|
||||
#include "settings.h"
|
||||
#include "log.h"
|
||||
|
|
|
@ -71,6 +71,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "content_craft.h"
|
||||
#include "content_craftitem.h"
|
||||
#include "content_toolitem.h"
|
||||
#include "content_mob.h"
|
||||
#include "path.h"
|
||||
#include "gui_colours.h"
|
||||
|
||||
|
@ -893,6 +894,7 @@ int main(int argc, char *argv[])
|
|||
crafting::initCrafting();
|
||||
content_craftitem_init();
|
||||
content_toolitem_init();
|
||||
content_mob_init();
|
||||
// Initial call with g_texturesource not set.
|
||||
init_mapnode(NULL);
|
||||
// Must be called before g_texturesource is created
|
||||
|
@ -1130,6 +1132,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
drawLoadingScreen(driver,wgettext("Loading MapNodes"));
|
||||
init_mapnode(driver); // Second call with g_texturesource set
|
||||
drawLoadingScreen(driver,wgettext("Loading Creatures"));
|
||||
content_mob_init();
|
||||
|
||||
/*
|
||||
GUI stuff
|
||||
|
|
|
@ -77,6 +77,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "content_craft.h"
|
||||
#include "content_craftitem.h"
|
||||
#include "content_toolitem.h"
|
||||
#include "content_mob.h"
|
||||
#include "http.h"
|
||||
|
||||
/*
|
||||
|
@ -310,6 +311,7 @@ int main(int argc, char *argv[])
|
|||
crafting::initCrafting();
|
||||
content_craftitem_init();
|
||||
content_toolitem_init();
|
||||
content_mob_init();
|
||||
init_mapnode();
|
||||
init_mineral();
|
||||
|
||||
|
|
|
@ -28,24 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define MOB_AGGRESSIVE 1
|
||||
#define MOB_DESTRUCTIVE 2
|
||||
|
||||
inline u8 mobLevelI(std::string level)
|
||||
{
|
||||
if (level == "destructive")
|
||||
return MOB_DESTRUCTIVE;
|
||||
if (level == "aggressive")
|
||||
return MOB_AGGRESSIVE;
|
||||
return MOB_PASSIVE;
|
||||
}
|
||||
|
||||
inline std::string mobLevelS(u8 level)
|
||||
{
|
||||
if (level == MOB_DESTRUCTIVE)
|
||||
return std::string("destructive");
|
||||
if (level == MOB_AGGRESSIVE)
|
||||
return std::string("aggressive");
|
||||
return std::string("passive");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Some planning
|
||||
|
|
Loading…
Reference in New Issue