[1853] | 1 | |
---|
| 2 | |
---|
[4597] | 3 | /* |
---|
[1853] | 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
[1855] | 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
| 15 | co-programmer: |
---|
[1853] | 16 | */ |
---|
[5357] | 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
[1853] | 18 | |
---|
| 19 | |
---|
| 20 | #include "npc.h" |
---|
[5033] | 21 | #include "obb_tree.h" |
---|
[1853] | 22 | |
---|
[4984] | 23 | #include "state.h" |
---|
[5064] | 24 | #include "list.h" |
---|
[5427] | 25 | #include "stdlibincl.h" |
---|
[5451] | 26 | #include "power_ups/turret_power_up.h" |
---|
[5458] | 27 | #include "power_ups/laser_power_up.h" |
---|
[4984] | 28 | |
---|
[1858] | 29 | using namespace std; |
---|
[1853] | 30 | |
---|
[1858] | 31 | |
---|
[4976] | 32 | NPC::NPC() |
---|
[1931] | 33 | { |
---|
[4597] | 34 | this->setClassID(CL_NPC, "NPC"); |
---|
[4976] | 35 | |
---|
[5499] | 36 | this->loadModel("models/ships/bolido.obj", 2); |
---|
[5059] | 37 | |
---|
[5427] | 38 | this->randomRotAxis = VECTOR_RAND(1); |
---|
[1931] | 39 | } |
---|
[1853] | 40 | |
---|
[5034] | 41 | |
---|
[1853] | 42 | NPC::~NPC () {} |
---|
| 43 | |
---|
| 44 | |
---|
[5029] | 45 | void NPC::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 46 | { |
---|
[5451] | 47 | if (entity->isA(CL_PROJECTILE) && entity != this->collider) |
---|
[5258] | 48 | { |
---|
[5451] | 49 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z); |
---|
| 50 | // this->applyForce(Vector(0,0,0)-location*1000); |
---|
| 51 | if ((float)rand()/RAND_MAX < .3) |
---|
| 52 | { |
---|
| 53 | WorldEntity* powerUp = new TurretPowerUp(); |
---|
| 54 | powerUp->setAbsCoor(this->getAbsCoor()); |
---|
| 55 | State::getWorldEntityList()->add(powerUp); |
---|
| 56 | } |
---|
[5458] | 57 | else if ((float)rand()/RAND_MAX < .3) |
---|
| 58 | { |
---|
| 59 | WorldEntity* powerUp = new LaserPowerUp(); |
---|
| 60 | powerUp->setAbsCoor(this->getAbsCoor()); |
---|
| 61 | State::getWorldEntityList()->add(powerUp); |
---|
| 62 | } |
---|
[5451] | 63 | State::getWorldEntityList()->remove(this); |
---|
| 64 | |
---|
| 65 | this->collider = entity; |
---|
[5258] | 66 | } |
---|
[5259] | 67 | else if (entity->isA(CL_PLAYER)) |
---|
| 68 | this->applyForce(Vector(0,0,0)-location*100); |
---|
[5451] | 69 | else if (entity->isA(CL_NPC)) |
---|
[5258] | 70 | { |
---|
| 71 | this->setVisibiliy(false); |
---|
[5451] | 72 | State::getWorldEntityList()->remove(this); |
---|
[5258] | 73 | } |
---|
[1931] | 74 | } |
---|
| 75 | |
---|
[5029] | 76 | |
---|
[4984] | 77 | void NPC::tick(float dt) |
---|
| 78 | { |
---|
[5257] | 79 | // Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor()); |
---|
[2036] | 80 | |
---|
[4986] | 81 | //if (directin.len() < 100) |
---|
[5257] | 82 | // this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0)); |
---|
[5060] | 83 | this->shiftDir(Quaternion(dt, this->randomRotAxis)); |
---|
[4986] | 84 | |
---|
[4984] | 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
[5033] | 88 | |
---|