00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
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         
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         
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()); 
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 )
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 )
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 }