#include "ObjectWrapper.h" void InitWObject(VObjectWrapper * o) { o->Type = NONEOBJECTTYPE; o->next = NULL; o->previous = NULL; o->taggedForRemoval = false; o->exploded = 0; o->picked = false; o->target = false; } void RunWObject(VObjectWrapper * o, float interval, void * w) { if(o->taggedForRemoval) { CleanUpWObject(o); } else { switch(o->Type) { case VOBJECT: if(o->o->taggedForRemoval) { CleanUpWObject(o); break; } RunObject(o->o, w); break; case VENEMY: if(o->e->taggedForRemoval) { CleanUpWObject(o); break; } RunEnemy(o->e, interval); break; case VWEAPON: if(o->w->taggedForRemoval) { CleanUpWObject(o); break; } RunWeapon(o->w, interval, w); if(o->w->taggedForRemoval == 2) { o->exploded = true; o->taggedForRemoval = true; if(o->w->Type == WEAPONTYPEBULLET) o->explosionLevel = 2; if(o->w->Type == WEAPONTYPEROCKET) o->explosionLevel = 7; } break; case VEXPLOSION: if(o->ex->markedForRemoval) { CleanUpWObject(o); break; } RunExplosion(o->ex, interval); break; case VPOWERUP: if (o->p->taggedForRemoval) { CleanUpWObject(o); break; } RunPowerup(o->p, interval, w); break; } } } void DrawWObject(VObjectWrapper * o) { switch(o->Type) { case VOBJECT: DrawObject(o->o); break; case VENEMY: DrawEnemy(o->e); break; case VWEAPON: DrawWeapon(o->w); break; case VEXPLOSION: DrawExplosion(o->ex); break; case VPOWERUP: DrawPowerup(o->p); break; } } void CleanUpWObject(VObjectWrapper * o) { if(o->exploded != 1) { switch(o->Type) { case VOBJECT: CleanUpObject(o->o); DisposePtr((Ptr)o->o); break; case VENEMY: CleanUpEnemy(o->e); DisposePtr((Ptr)o->e); break; case VWEAPON: CleanUpWeapon(o->w); DisposePtr((Ptr)o->w); break; case VEXPLOSION: CleanUpExplosion(o->ex); DisposePtr((Ptr)o->ex); break; case VPOWERUP: CleanUpPowerup(o->p); DisposePtr((Ptr)o->p); break; } } o->taggedForRemoval = true; } void AllocateWObject(VObjectWrapper ** o) { *o = (VObjectWrapper *) NewPtrClear(sizeof(VObjectWrapper)); InitWObject(*o); } void AllocateObject(VObjectWrapper * o) { o->o = (VObject *) NewPtrClear(sizeof(VObject)); o->Type = VOBJECT; } void AllocateWeapon(VObjectWrapper * o) { o->w = (VWeapon *) NewPtrClear(sizeof(VWeapon)); o->Type = VWEAPON; } void AllocateEnemy(VObjectWrapper * o) { o->e = (VEnemy *) NewPtrClear(sizeof(VEnemy)); o->Type = VENEMY; } void AllocateExplosion(VObjectWrapper * o) { o->ex = (VExplosion *) NewPtrClear(sizeof(VExplosion)); o->Type = VEXPLOSION; } void AllocatePowerup(VObjectWrapper * o) { o->p = (VPowerup *) NewPtr(sizeof(VPowerup)); o->Type = VPOWERUP; } void WObjectObject(VObjectWrapper * o, VObject ** obj) { switch(o->Type) { case VOBJECT: *obj = o->o; break; case VENEMY: *obj = &o->e->Object; break; case VWEAPON: *obj = &o->w->Object; break; case VEXPLOSION: *obj = NULL; break; case VPOWERUP: *obj = &o->p->Object; break; default: *obj = NULL; break; } } void CopyWObject(VObjectWrapper * src, VObjectWrapper ** dest) { AllocateWObject(dest); (**dest).Type = src->Type; switch (src->Type) { case VOBJECT: AllocateObject(*dest); CopyObject(src->o, (**dest).o); break; case VENEMY: AllocateEnemy(*dest); CopyEnemy(src->e, (**dest).e); break; case VWEAPON: AllocateWeapon(*dest); CopyWeapon(src->w, (**dest).w); break; case VEXPLOSION: AllocateExplosion(*dest); CopyExplosion(src->ex, (**dest).ex); break; case VPOWERUP: AllocatePowerup(*dest); CopyPowerup(src->p, (**dest).p); break; } (**dest).next = NULL; (**dest).previous = NULL; (**dest).taggedForRemoval = src->taggedForRemoval; (**dest).exploded = src->exploded; (**dest).explosionLevel = src->explosionLevel; } VObjectWrapper * GetWrapperByEnemy(VObjectWrapper * objectList, VEnemy * e) { while (objectList != NULL) { if (objectList->Type == VENEMY && objectList->e == e) return objectList; objectList = objectList->next; } return NULL; } VObjectWrapper * GetWrapperByObject(VObjectWrapper * objectList, VObject * o) { while (objectList != NULL) { if (objectList->Type == VOBJECT && objectList->o == o) return objectList; objectList = objectList->next; } return NULL; }