From bf44366a5ec116674b4c44fb6dfe630a7ea53f7a Mon Sep 17 00:00:00 2001 From: darkrose Date: Thu, 25 Sep 2014 03:00:56 +1000 Subject: [PATCH] initial mob setup --- src/CMakeLists.txt | 1 + src/content_mob.cpp | 63 +++++++++++++++ src/content_mob.h | 184 ++++++++++++++++++++++++++++++++++++++++++++ src/content_sao.cpp | 58 +------------- src/environment.cpp | 1 + src/main.cpp | 4 + src/servermain.cpp | 2 + src/serverobject.h | 18 ----- 8 files changed, 256 insertions(+), 75 deletions(-) create mode 100644 src/content_mob.cpp create mode 100644 src/content_mob.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11acefa..d3a6f1c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/content_mob.cpp b/src/content_mob.cpp new file mode 100644 index 0000000..2ff244b --- /dev/null +++ b/src/content_mob.cpp @@ -0,0 +1,63 @@ +/************************************************************************ +* Minetest-c55 +* Copyright (C) 2010 celeron55, Perttu Ahola +* +* content_mob.cpp +* Copyright (C) Lisa 'darkrose' Milne 2014 +* +* 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 +************************************************************************/ + +#include "content_mob.h" +#include "main.h" + +std::map 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::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; + +} diff --git a/src/content_mob.h b/src/content_mob.h new file mode 100644 index 0000000..87bcceb --- /dev/null +++ b/src/content_mob.h @@ -0,0 +1,184 @@ +/************************************************************************ +* Minetest-c55 +* Copyright (C) 2010 celeron55, Perttu Ahola +* +* mob.h +* Copyright (C) Lisa 'darkrose' Milne 2014 +* +* 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 +************************************************************************/ + +#ifndef MOB_HEADER +#define MOB_HEADER + +#include "mapnode.h" +#include "serverobject.h" +#ifndef SERVER +#include "common_irrlicht.h" +#endif +#include +#include + +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 animations; + std::vector 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 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 diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 07cd6b3..8a3f7bf 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -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 diff --git a/src/environment.cpp b/src/environment.cpp index 3556fca..df20ead 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -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" diff --git a/src/main.cpp b/src/main.cpp index d921324..83b25bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 diff --git a/src/servermain.cpp b/src/servermain.cpp index fa81ea1..595bfce 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -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(); diff --git a/src/serverobject.h b/src/serverobject.h index 6269337..bff0705 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -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