#include "Enemies.h" #include "WorldManager.h" #define EnemySpeed 0.001 void TestAI(void * Enemy, AIEvent Event, float interval) { #pragma unused (Event) VEnemy * e; VWorld * w; Vector Angle; VObjectWrapper * objectList; VObject * object; float shields; e = (VEnemy *) Enemy; w = (VWorld *) e->Data; SubtractVector(&w->Camera.Position, &e->Object.Position, &Angle); NormalizeVector(&Angle); Angle.x *= PYRAMIDROTSPEED / interval; Angle.y *= PYRAMIDROTSPEED / interval; Angle.z *= PYRAMIDROTSPEED / interval; AddVector(&e->Object.Front, &Angle, &e->Object.Front); NormalizeVector(&e->Object.Front); CrossProduct(&e->Object.Front, &e->Object.Right, &e->Object.Up); CrossProduct(&e->Object.Up, &e->Object.Front, &e->Object.Right); NormalizeVector(&e->Object.Right); NormalizeVector(&e->Object.Up); if(fabs( ((e->Object.Position.x - w->Camera.Position.x) * (e->Object.Position.x - w->Camera.Position.x) + (e->Object.Position.y - w->Camera.Position.y) * (e->Object.Position.y - w->Camera.Position.y) + (e->Object.Position.z - w->Camera.Position.z) * (e->Object.Position.z - w->Camera.Position.z)) > PYRAMIDRANGE)) { Angle = e->Object.Front; NormalizeVector(&Angle); Angle.x *= PYRAMIDMOVESPEED / interval; Angle.y *= PYRAMIDMOVESPEED / interval; Angle.z *= PYRAMIDMOVESPEED / interval; AddVector(&e->Object.Position, &Angle, &e->Object.Position); for (objectList = w->Objects; objectList != NULL; objectList = objectList->next) { if (objectList->Type != VENEMY && objectList->Type != VOBJECT) continue; if (objectList->Type == VENEMY && e == objectList->e) continue; WObjectObject(objectList, &object); if (object != NULL && fabs(((e->Object.Position.x - object->Position.x) * (e->Object.Position.x - object->Position.x)) + ((e->Object.Position.y - object->Position.y) * (e->Object.Position.y - object->Position.y)) + ((e->Object.Position.z - object->Position.z) * (e->Object.Position.z - object->Position.z))) <= (e->Object.Radius + object->Radius)) { if (objectList->Type == VENEMY) { shields = objectList->e->Shields; HitEnemy(objectList->e, e->Shields); e->Shields -= shields; if (objectList->e->Shields <= 0) { objectList->taggedForRemoval = true; objectList->exploded = 1; } else { objectList->exploded = 2; } } else { shields = objectList->o->Durability; objectList->o->Durability -= e->Shields; e->Shields -= shields; if (objectList->o->Durability <= 0) { objectList->taggedForRemoval = true; objectList->exploded = 1; } else { objectList->exploded = 2; } } if (e->Shields <= 0) e->taggedForRemoval = 1; break; } } if (!e->taggedForRemoval) { if (fabs(((e->Object.Position.x - w->Camera.Position.x) * (e->Object.Position.x - w->Camera.Position.x)) + ((e->Object.Position.y - w->Camera.Position.y) * (e->Object.Position.y - w->Camera.Position.y)) + ((e->Object.Position.z - w->Camera.Position.z) * (e->Object.Position.z - w->Camera.Position.z))) <= (e->Object.Radius + PLAYERSHIPRADIUS)) { shields = w->Player.Shields; w->Player.Shields -= e->Shields; e->Shields -= shields; if (e->Shields <= 0) e->taggedForRemoval = 1; } } } else { e->Idle += interval; if(e->Idle > PYRAMIDSHOOTSPEED) { VWeapon * theWeapon; VObjectWrapper * theWObject; e->Idle = 0; theWeapon = (VWeapon *) NewPtr(sizeof(VWeapon)); if (theWeapon != NULL) { InitWeapon(theWeapon, WEAPONTYPEBULLET); AllocateWObject(&theWObject); theWObject->w = theWeapon; theWObject->Type = VWEAPON; theWObject->next = w->Objects; if (w->Objects != NULL) w->Objects->previous = theWObject; w->Objects = theWObject; StartWeapon(theWeapon, &e->Object.Position, NULL, &e->Object.Front, &e->Object.Up); theWeapon->Speed = BULLETSPEED / 2; } } } } void HitEnemy(VEnemy * e, int Damage) { e->Shields -= Damage; } void InitEnemy(VEnemy * e, EnemyAIModule aiMod, void * Data) { e->Callback = aiMod; e->Data = Data; e->Idle = 0; e->next = NULL; e->taggedForRemoval = false; InitObject(&e->Object); BuildEnemyModel(&e->Object.Model); CalculateRadius(&e->Object); e->Object.Front.z = -1; e->Object.Position.z = -10; e->Object.Position.x = -2; e->Object.Position.y = -2; e->Shields = 5; } void CleanUpEnemy(VEnemy * e) { CleanUpObject(&e->Object); } void DrawEnemy(VEnemy * e) { DrawObject(&e->Object); } void RunEnemy(VEnemy * e, float interval) { e->Callback(e, blah, interval); }