MonsterEgg.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2005 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 
00021 #include "MonsterEgg.h"
00022 #include "UCMachine.h"
00023 #include "Actor.h"
00024 #include "ItemFactory.h"
00025 #include "CurrentMap.h"
00026 #include "ShapeInfo.h"
00027 #include "MonsterInfo.h"
00028 #include "getObject.h"
00029 
00030 #include "IDataSource.h"
00031 #include "ODataSource.h"
00032 
00033 DEFINE_RUNTIME_CLASSTYPE_CODE(MonsterEgg,Item);
00034 
00035 MonsterEgg::MonsterEgg()
00036 {
00037 
00038 }
00039 
00040 
00041 MonsterEgg::~MonsterEgg()
00042 {
00043 
00044 }
00045 
00046 uint16 MonsterEgg::hatch()
00047 {
00050 
00051         int shape = getMonsterShape();
00052 
00053         // CHECKME: why does this happen? (in the plane of Earth near the end)
00054         if (shape == 0)
00055                 return 0;
00056 
00057         Actor* newactor = ItemFactory::createActor(shape, 0, 0,
00058                                                                 FLG_FAST_ONLY|FLG_DISPOSABLE|FLG_IN_NPC_LIST, 
00059                                                                 0, 0, 0, true);
00060         if (!newactor) {
00061                 perr << "MonsterEgg::hatch failed to create actor (" << shape
00062                          <<     ")." << std::endl;
00063                 return 0;
00064         }
00065         uint16 objID = newactor->getObjId();
00066 
00067         // set stats
00068         if (!newactor->loadMonsterStats()) {
00069                 perr << "MonsterEgg::hatch failed to set stats for actor (" << shape
00070                          << ")." << std::endl;
00071         }
00072 
00073         if (!newactor->canExistAt(x,y,z)) {
00074                 newactor->destroy();
00075                 return 0;
00076         }
00077 
00078         newactor->setMapNum(getMapNum()); // CHECKME!
00079         newactor->setNpcNum(objID);
00080         newactor->move(x,y,z);
00081 
00082         newactor->cSetActivity(getActivity());
00083 
00084         return objID;
00085 }
00086 
00087 void MonsterEgg::saveData(ODataSource* ods)
00088 {
00089         Item::saveData(ods);
00090 }
00091 
00092 bool MonsterEgg::loadData(IDataSource* ids, uint32 version)
00093 {
00094         if (!Item::loadData(ids, version)) return false;
00095 
00096         return true;
00097 }
00098 
00099 uint32 MonsterEgg::I_monsterEggHatch(const uint8*args,unsigned int /*argsize*/)
00100 {
00101         ARG_ITEM_FROM_PTR(item);
00102         MonsterEgg* megg = p_dynamic_cast<MonsterEgg*>(item);
00103         if (!megg) return 0;
00104 
00105         return megg->hatch();
00106 }
00107 
00108 uint32 MonsterEgg::I_getMonId(const uint8*args,unsigned int /*argsize*/)
00109 {
00110         ARG_ITEM_FROM_PTR(item);
00111         MonsterEgg* megg = p_dynamic_cast<MonsterEgg*>(item);
00112         if (!megg) return 0;
00113 
00114         return megg->getMapNum() >> 3;
00115 }

Generated on Fri Jul 27 22:27:26 2007 for pentagram by  doxygen 1.4.7