ItemFactory.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2006 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 "ItemFactory.h"
00022 #include "GameData.h"
00023 #include "MainShapeArchive.h"
00024 #include "ShapeInfo.h"
00025 #include "Item.h"
00026 #include "Container.h"
00027 #include "Actor.h"
00028 #include "MainActor.h"
00029 #include "GlobEgg.h"
00030 #include "Egg.h"
00031 #include "MonsterEgg.h"
00032 #include "TeleportEgg.h"
00033 #include "CoreApp.h"
00034 #include "IDataSource.h"
00035 
00036 Item* ItemFactory::createItem(uint32 shape, uint32 frame, uint16 quality,
00037                                                           uint16 flags, uint16 npcnum, uint16 mapnum,
00038                                                           uint32 extendedflags, bool objid)
00039 {
00040         // check what class to create
00041         ShapeInfo *info = GameData::get_instance()->getMainShapes()->
00042                 getShapeInfo(shape);
00043         if (info == 0) return 0;
00044 
00045         // New item, no lerping
00046         extendedflags |= Item::EXT_LERP_NOPREV;
00047 
00048         uint32 family = info->family;
00049 
00050         switch (family) {
00051         case ShapeInfo::SF_GENERIC:
00052         case ShapeInfo::SF_QUALITY:
00053         case ShapeInfo::SF_QUANTITY:
00054         case ShapeInfo::SF_BREAKABLE:
00055         case ShapeInfo::SF_REAGENT: // reagents need special handling too
00056         case ShapeInfo::SF_15: // what's this?
00057         {
00058                 // 'simple' item
00059 
00060                 Item* item = new Item();
00061                 item->setShape(shape);
00062                 item->frame = frame;
00063                 item->quality = quality;
00064                 item->flags = flags;
00065                 item->npcnum = npcnum;
00066                 item->mapnum = mapnum;
00067                 item->extendedflags = extendedflags;
00068                 if (objid) item->assignObjId();
00069                 return item;
00070         }
00071 
00072         case ShapeInfo::SF_CONTAINER:
00073         {
00074                 // container
00075 
00076                 Container* container = new Container();
00077                 container->setShape(shape);
00078                 container->frame = frame;
00079                 container->quality = quality;
00080                 container->flags = flags;
00081                 container->npcnum = npcnum;
00082                 container->mapnum = mapnum;
00083                 container->extendedflags = extendedflags;
00084                 if (objid) container->assignObjId();
00085                 return container;
00086         }
00087 
00088         case ShapeInfo::SF_GLOBEGG:
00089         {
00090                 // glob egg
00091 
00092                 GlobEgg* globegg = new GlobEgg();
00093                 globegg->setShape(shape);
00094                 globegg->frame = frame;
00095                 globegg->quality = quality;
00096                 globegg->flags = flags;
00097                 globegg->npcnum = npcnum;
00098                 globegg->mapnum = mapnum;
00099                 globegg->extendedflags = extendedflags;
00100                 if (objid) globegg->assignObjId();
00101                 return globegg;
00102         }
00103 
00104         case ShapeInfo::SF_UNKEGG:
00105         {
00106                 Egg* egg = new Egg();
00107                 egg->setShape(shape);
00108                 egg->frame = frame;
00109                 egg->quality = quality;
00110                 egg->flags = flags;
00111                 egg->npcnum = npcnum;
00112                 egg->mapnum = mapnum;
00113                 egg->extendedflags = extendedflags;
00114                 if (objid) egg->assignObjId();
00115                 return egg;
00116         }
00117 
00118         case ShapeInfo::SF_MONSTEREGG:
00119         {
00120                 MonsterEgg* egg = new MonsterEgg();
00121                 egg->setShape(shape);
00122                 egg->frame = frame;
00123                 egg->quality = quality;
00124                 egg->flags = flags;
00125                 egg->npcnum = npcnum;
00126                 egg->mapnum = mapnum;
00127                 egg->extendedflags = extendedflags;
00128                 if (objid) egg->assignObjId();
00129                 return egg;
00130         }
00131 
00132         case ShapeInfo::SF_TELEPORTEGG:
00133         {
00134                 TeleportEgg* egg = new TeleportEgg();
00135                 egg->setShape(shape);
00136                 egg->frame = frame;
00137                 egg->quality = quality;
00138                 egg->flags = flags;
00139                 egg->npcnum = npcnum;
00140                 egg->mapnum = mapnum;
00141                 egg->extendedflags = extendedflags;
00142                 if (objid) egg->assignObjId();
00143                 return egg;
00144         }
00145 
00146         default:
00147                 return 0;
00148         }
00149 }
00150 
00151 
00152 
00153 Actor* ItemFactory::createActor(uint32 shape, uint32 frame, uint16 quality,
00154                                                                 uint16 flags, uint16 npcnum, uint16 mapnum,
00155                                                                 uint32 extendedflags, bool objid)
00156 {
00157         // this function should probably differentiate between the Avatar,
00158         // NPCs, monsters?
00159 
00160 /*
00161     // This makes it rather hard to create new NPCs...
00162         if (npcnum == 0) // or do monsters have npcnum 0? we'll see...
00163                 return 0;
00164 */
00165         // New actor, no lerping
00166         extendedflags |= Item::EXT_LERP_NOPREV;
00167 
00168         if (npcnum == 1) {
00169                 // Main Actor
00170 
00171                 MainActor* actor = new MainActor();
00172                 actor->setShape(shape);
00173                 actor->frame = frame;
00174                 actor->quality = quality;
00175                 actor->flags = flags;
00176                 actor->npcnum = npcnum;
00177                 actor->mapnum = mapnum;
00178                 actor->objid = 1;
00179                 actor->extendedflags = extendedflags;
00180                 return actor;
00181         }
00182 
00183         // 'normal' Actor/NPC
00184         Actor* actor = new Actor();
00185         actor->setShape(shape);
00186         actor->frame = frame;
00187         actor->quality = quality;
00188         actor->flags = flags;
00189         actor->npcnum = npcnum;
00190         actor->mapnum = mapnum;
00191         if (npcnum != 0) {
00192                 actor->objid = static_cast<uint16>(npcnum);
00193         } else if (objid) {
00194                 actor->assignObjId();
00195         }
00196         actor->extendedflags = extendedflags;
00197 
00198         return actor;
00199 }

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