EggHatcherProcess.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2004 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 "EggHatcherProcess.h"
00022 #include "Egg.h"
00023 #include "MainActor.h"
00024 #include "TeleportEgg.h"
00025 #include "getObject.h"
00026 
00027 #include "IDataSource.h"
00028 #include "ODataSource.h"
00029 
00030 DEFINE_RUNTIME_CLASSTYPE_CODE(EggHatcherProcess,Process);
00031 
00032 EggHatcherProcess::EggHatcherProcess()
00033 {
00034 
00035 }
00036 
00037 
00038 EggHatcherProcess::~EggHatcherProcess()
00039 {
00040 
00041 }
00042 
00043 void EggHatcherProcess::addEgg(uint16 egg)
00044 {
00045         eggs.push_back(egg);
00046 }
00047 
00048 void EggHatcherProcess::addEgg(Egg* egg)
00049 {
00050         assert(egg);
00051         eggs.push_back(egg->getObjId());
00052 }
00053 
00054 bool EggHatcherProcess::run(const uint32 /*framenum*/)
00055 {
00056         bool nearteleporter = false;
00057         MainActor* av = getMainActor();
00058         assert(av);
00059 
00060         for (unsigned int i = 0; i < eggs.size(); i++) {
00061                 uint16 eggid = eggs[i];
00062                 Egg* egg = p_dynamic_cast<Egg*>(getObject(eggid));
00063                 if (!egg) continue; // egg gone
00064 
00065                 sint32 x,y,z;
00066                 egg->getLocation(x,y,z);
00067 
00069                 sint32 x1 = x - 32 * egg->getXRange();
00070                 sint32 x2 = x + 32 * egg->getXRange();
00071                 sint32 y1 = y - 32 * egg->getYRange();
00072                 sint32 y2 = y + 32 * egg->getYRange();
00073 
00074                 // get avatar location
00075                 sint32 ax,ay,az;
00076                 sint32 axs,ays,azs;
00077                 av->getLocation(ax,ay,az);
00078                 av->getFootpadWorld(axs,ays,azs);
00079 
00080                 // 'justTeleported':
00081                 // if the avatar teleports, set the 'justTeleported' flag.
00082                 // if this is set, don't hatch any teleport eggs
00083                 // unset it when you're out of range of any teleport eggs
00084                 TeleportEgg* tegg = p_dynamic_cast<TeleportEgg*>(egg);
00085 
00086                 if (x1 <= ax && ax-axs < x2 && y1 <= ay && ay-ays < y2 &&
00087                         z - 48 < az && az <= z + 48) { // CONSTANTS!
00088                         if (tegg && tegg->isTeleporter()) nearteleporter = true;
00089 
00090                         if (tegg && av->hasJustTeleported()) continue;
00091 
00092                         egg->hatch();
00093                 }
00094         }
00095 
00096         if (!nearteleporter) av->setJustTeleported(false); // clear flag
00097 
00098         return false;
00099 }
00100 
00101 void EggHatcherProcess::saveData(ODataSource* ods)
00102 {
00103         Process::saveData(ods);
00104 }
00105 
00106 
00107 bool EggHatcherProcess::loadData(IDataSource* ids, uint32 version)
00108 {
00109         if (!Process::loadData(ids, version)) return false;
00110 
00111         // the eggs will be re-added to the EggHatcherProcess when they're
00112         // re-added to the CurrentMap
00113 
00114         return true;
00115 }

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