Changeset 5924 in orxonox.OLD for branches/avi_play/src/world_entities
- Timestamp:
- Dec 4, 2005, 11:37:49 PM (19 years ago)
- Location:
- branches/avi_play/src/world_entities
- Files:
-
- 10 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/avi_play/src/world_entities/Makefile.am
r5750 r5924 7 7 world_entity.cc \ 8 8 camera.cc \ 9 player.cc \ 9 playable.cc \ 10 player.cc \ 10 11 npc.cc \ 11 12 npc2.cc \ … … 17 18 character_attributes.cc \ 18 19 test_entity.cc \ 20 space_ships/space_ship.cc \ 19 21 weapons/weapon_manager.cc \ 20 22 weapons/weapon.cc \ … … 35 37 world_entity.h \ 36 38 camera.h \ 37 player.h \ 39 playable.h \ 40 player.h \ 38 41 npc.h \ 39 42 npc2.h \ … … 45 48 character_attributes.h \ 46 49 test_entity.h \ 50 space_ships/space_ship.h \ 47 51 weapons/weapon_manager.h \ 48 52 weapons/weapon.h \ -
branches/avi_play/src/world_entities/player.cc
r5767 r5924 10 10 11 11 ### File Specific: 12 main-programmer: Patrick Boenzli13 co-programmer: Christian Meyer12 main-programmer: Silvan Nellen 13 co-programmer: Benjamin Knecht 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY17 18 19 #include "executor/executor.h"20 16 #include "player.h" 21 22 #include "track_manager.h" 23 #include "objModel.h" 24 #include "resource_manager.h" 25 #include "factory.h" 26 27 #include "weapons/weapon_manager.h" 28 #include "weapons/test_gun.h" 29 #include "weapons/turret.h" 30 #include "weapons/cannon.h" 31 32 #include "list.h" 17 #include "playable.h" 33 18 34 19 #include "event_handler.h" 35 20 36 #include "event.h"37 38 21 using namespace std; 39 22 40 CREATE_FACTORY(Player, CL_PLAYER);41 23 42 24 /** 43 25 * creates a new Player 44 * @param isFree if the player is free45 26 */ 46 27 Player::Player() … … 49 30 } 50 31 51 /**52 * loads a Players information from a specified file.53 * @param fileName the name of the File to load the player from (absolute path)54 */55 Player::Player(const char* fileName)56 {57 this->init();58 TiXmlDocument doc(fileName);59 60 if(!doc.LoadFile())61 {62 PRINTF(2)("Loading file %s failed for player.\n", fileName);63 return;64 }65 66 this->loadParams(doc.RootElement());67 }68 69 /**70 * creates a new Player from Xml Data71 * @param root the xml element containing player data72 73 @todo add more parameters to load74 */75 Player::Player(const TiXmlElement* root)76 {77 this->init();78 if (root != NULL)79 this->loadParams(root);80 81 //weapons:82 Weapon* wpRight = new TestGun(0);83 wpRight->setName("testGun Right");84 Weapon* wpLeft = new TestGun(1);85 wpLeft->setName("testGun Left");86 Weapon* cannon = dynamic_cast<Weapon*>(Factory::getFirst()->fabricate(CL_CANNON));87 88 cannon->setName("BFG");89 90 this->weaponMan->addWeapon(wpLeft, 1, 0);91 this->weaponMan->addWeapon(wpRight,1 ,1);92 this->weaponMan->addWeapon(cannon, 0, 6);93 94 //this->weaponMan->addWeapon(turret, 3, 0);95 96 this->weaponMan->changeWeaponConfig(1);97 }98 32 99 33 /** … … 102 36 Player::~Player () 103 37 { 104 /* do not delete the weapons, they are contained in the pnode tree105 and will be deleted there.106 this only frees the memory allocated to save the list.107 */108 delete this->weaponMan;109 38 } 110 39 111 //#include "glgui_pushbutton.h"112 40 113 41 /** … … 120 48 121 49 PRINTF(4)("PLAYER INIT\n"); 122 travelSpeed = 15.0;123 bUp = bDown = bLeft = bRight = bAscend = bDescend = false;124 bFire = false;125 acceleration = 10.0;126 50 127 // GLGuiButton* button = new GLGuiPushButton(); 128 // button->show(); 129 // button->setLabel("orxonox"); 130 // button->setBindNode(this); 131 132 this->weaponMan = new WeaponManager(this); 133 this->weaponMan->setSlotCount(7); 134 135 this->weaponMan->setSlotPosition(0, Vector(-2.6, .1, -3.0)); 136 this->weaponMan->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); 137 138 this->weaponMan->setSlotPosition(1, Vector(-2.6, .1, 3.0)); 139 this->weaponMan->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); 140 141 this->weaponMan->setSlotPosition(2, Vector(-1.5, .5, -.5)); 142 this->weaponMan->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); 143 144 this->weaponMan->setSlotPosition(3, Vector(-1.5, .5, .5)); 145 this->weaponMan->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); 146 147 this->weaponMan->setSlotPosition(4, Vector(-1.5, -.5, .5)); 148 this->weaponMan->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); 149 150 this->weaponMan->setSlotPosition(5, Vector(-1.5, -.5, -.5)); 151 this->weaponMan->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); 152 // 153 this->weaponMan->setSlotPosition(6, Vector(-1, 0.0, 0)); 154 this->weaponMan->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); 155 // 156 // this->weaponMan->setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); 157 // this->weaponMan->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); 158 // 159 // this->weaponMan->setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); 160 // this->weaponMan->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: 161 51 this->controllable = NULL; 162 52 } 163 53 164 54 165 /** 166 * loads the Settings of a Player from an XML-element. 167 * @param root the XML-element to load the Player's properties from 168 */ 169 void Player::loadParams(const TiXmlElement* root) 55 bool Player::setControllable(Playable* controllable) 170 56 { 171 static_cast<WorldEntity*>(this)->loadParams(root); 172 173 174 57 if(controllable != NULL && controllable->subscribePlayer(this)) 58 { 59 this->controllable = controllable; 60 return true; 61 } 62 else 63 return false; 175 64 } 176 65 177 /** 178 * adds a weapon to the weapon list of player 179 * @param weapon to add 180 */ 181 void Player::addWeapon(Weapon* weapon) 182 { 183 this->weaponMan->addWeapon(weapon); 184 } 66 bool Player::disconnectControllable() 67 { 68 if(this->controllable == NULL) return true; 185 69 70 if(this->controllable->unsubscribePlayer(this)) 71 { 72 this->controllable = NULL; 73 return true; 74 } 75 else 76 return false; 77 } 186 78 187 /** 188 * removes a weapon from the player 189 * @param weapon to remove 190 */ 191 void Player::removeWeapon(Weapon* weapon) 192 { 193 this->weaponMan->removeWeapon(weapon); 194 } 79 void Player::process(const Event &event) 80 { 81 if (likely(this->controllable != NULL)) 82 this->controllable->process(event); 83 } 195 84 196 197 /**198 * effect that occurs after the player is spawned199 */200 void Player::postSpawn ()201 {202 //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));203 }204 205 206 /**207 * the action occuring if the player left the game208 */209 void Player::leftWorld ()210 {}211 212 213 WorldEntity* ref = NULL;214 /**215 * this function is called, when two entities collide216 * @param entity: the world entity with whom it collides217 *218 * Implement behaviour like damage application or other miscellaneous collision stuff in this function219 */220 void Player::collidesWith(WorldEntity* entity, const Vector& location)221 {222 if (entity->isA(CL_TURRET_POWER_UP) && entity != ref)223 {224 this->ADDWEAPON();225 ref = entity;226 }227 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);228 }229 230 /**231 * draws the player after transforming him.232 */233 void Player::draw () const234 {235 glMatrixMode(GL_MODELVIEW);236 glPushMatrix();237 /* translate */238 glTranslatef (this->getAbsCoor ().x,239 this->getAbsCoor ().y,240 this->getAbsCoor ().z);241 /* rotate */242 Vector tmpRot = this->getAbsDir().getSpacialAxis();243 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );244 this->model->draw();245 glPopMatrix();246 247 this->weaponMan->draw();248 249 //this->debug(0);250 }251 252 253 /**254 * the function called for each passing timeSnap255 * @param time The timespan passed since last update256 */257 void Player::tick (float time)258 {259 // player controlled movement260 this->move(time);261 262 this->weaponMan->tick(time);263 // weapon system manipulation264 this->weaponAction();265 }266 267 268 /**269 * action if player moves270 * @param time the timeslice since the last frame271 */272 void Player::move (float time)273 {274 Vector accel(0.0, 0.0, 0.0);275 Vector rot(0.0, 0.0, 0.0);276 float rotVal = 0.0;277 /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */278 /* calculate the direction in which the craft is heading */279 Vector direction (1.0, 0.0, 0.0);280 //direction = this->absDirection.apply (direction);281 Vector orthDirection (0.0, 0.0, 1.0);282 //orthDirection = orthDirection.cross (direction);283 284 if( this->bUp && this->getRelCoor().x < 20)285 accel += direction;286 if( this->bDown && this->getRelCoor().x > -5)287 accel -= direction;288 289 if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)290 {291 accel -=(orthDirection);292 rot +=Vector(1,0,0);293 rotVal -= .4;294 }295 if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)296 {297 accel += orthDirection;298 rot += Vector(1,0,0);299 rotVal += .4;300 }301 if (this->bAscend )302 {303 accel += Vector(0,1,0);304 rot += Vector(0,0,1);305 rotVal += .4;306 }307 if (this->bDescend )308 {309 accel -= Vector(0,1,0);310 rot += Vector(0,0,1);311 rotVal -= .4;312 }313 314 Vector move = accel * time *acceleration;315 316 /* if (accel.z < 0)317 this->setRelDirSoft(Quaternion(-.4, accel), 5);318 else if (accel.z > 0)319 this->setRelDirSoft(Quaternion(.4, accel), 5);320 else*/321 rot.normalize();322 this->setRelDirSoft(Quaternion(rotVal, rot), 5);323 this->shiftCoor (move);324 }325 326 327 /**328 * weapon manipulation by the player329 */330 void Player::weaponAction()331 {332 if( this->bFire)333 {334 this->weaponMan->fire();335 }336 }337 338 /**339 * @todo switch statement ??340 */341 void Player::process(const Event &event)342 {343 if( event.type == KeyMapper::PEV_UP)344 this->bUp = event.bPressed;345 else if( event.type == KeyMapper::PEV_DOWN)346 this->bDown = event.bPressed;347 else if( event.type == KeyMapper::PEV_RIGHT)348 this->bRight= event.bPressed;349 else if( event.type == KeyMapper::PEV_LEFT)350 this->bLeft = event.bPressed;351 else if( event.type == KeyMapper::PEV_FIRE1)352 this->bFire = event.bPressed;353 else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)354 this->weaponMan->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;355 else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)356 this->weaponMan->previousWeaponConfig();357 358 else if( event.type == SDLK_PAGEUP)359 this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);360 else if( event.type == SDLK_PAGEDOWN)361 this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0);362 }363 364 #include "weapons/aiming_turret.h"365 // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG366 void Player::ADDWEAPON()367 {368 Weapon* turret = NULL;369 370 if ((float)rand()/RAND_MAX < .1)371 {372 //if (this->weaponMan->hasFreeSlot(2, WTYPE_TURRET))373 {374 turret = new Turret();375 this->weaponMan->addWeapon(turret, 2);376 this->weaponMan->changeWeaponConfig(2);377 }378 }379 else380 {381 //if (this->weaponMan->hasFreeSlot(3))382 {383 turret = new AimingTurret();384 this->weaponMan->addWeapon(turret, 3);385 386 this->weaponMan->changeWeaponConfig(3);387 }388 }389 390 if(turret != NULL)391 {392 turret->setName("Turret");393 turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);394 }395 } -
branches/avi_play/src/world_entities/player.h
r5500 r5924 7 7 #define _PLAYER_H 8 8 9 #include "world_entity.h"10 #include "physics_interface.h"11 9 #include "event_listener.h" 12 10 13 template<class T> class tList; 14 class Weapon; 15 class WeaponManager; 16 class Vector; 17 class Event; 11 /* Forward Declaration */ 12 class Playable; 18 13 19 14 //! Basic controllable WorldEntity … … 23 18 the player.cc for debug also 24 19 */ 25 class Player : public WorldEntity, publicEventListener20 class Player : public EventListener 26 21 { 27 friend class World;28 22 29 23 public: 30 24 Player(); 31 Player(const char* fileName);32 Player(const TiXmlElement* root);33 25 virtual ~Player(); 34 26 35 void init();36 void loadParams(const TiXmlElement* root);27 bool setControllable(Playable* controllalble); 28 inline Playable* getControllable() { return this->controllable; }; 37 29 38 void addWeapon(Weapon* weapon); 39 void removeWeapon(Weapon* weapon); 30 bool disconnectControllable(); 40 31 41 virtual void postSpawn();42 virtual void leftWorld();32 // eventListener extension. 33 virtual void process(const Event &event); 43 34 44 virtual void collidesWith(WorldEntity* entity, const Vector& location); 45 virtual void tick(float time); 46 virtual void draw() const; 47 48 virtual void process(const Event &event); 35 private: 36 void init(); 49 37 50 38 51 39 private: 52 void move(float time); 53 void weaponAction(); 54 55 // !! temporary !! 56 void ADDWEAPON(); 57 58 private: 59 bool bUp; //!< up button pressed. 60 bool bDown; //!< down button pressed. 61 bool bLeft; //!< left button pressed. 62 bool bRight; //!< right button pressed. 63 bool bAscend; //!< ascend button pressed. 64 bool bDescend; //!< descend button presses. 65 bool bFire; //!< fire button pressed. 66 67 WeaponManager* weaponMan; //!< the weapon manager: managing a list of weapon to wepaon-slot mapping 68 69 Vector velocity; //!< the velocity of the player. 70 float travelSpeed; //!< the current speed of the player (to make soft movement) 71 float acceleration; //!< the acceleration of the player. 40 Playable* controllable; //!< The one we controll or NULL if none 72 41 }; 73 42 -
branches/avi_play/src/world_entities/power_ups/laser_power_up.cc
r5750 r5924 79 79 { 80 80 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); 81 if (entity->isA(CL_PLAY ER))81 if (entity->isA(CL_PLAYABLE)) 82 82 State::getWorldEntityList()->remove(this); 83 83 } -
branches/avi_play/src/world_entities/power_ups/turret_power_up.cc
r5750 r5924 79 79 { 80 80 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); 81 if (entity->isA(CL_PLAY ER))81 if (entity->isA(CL_PLAYABLE)) 82 82 State::getWorldEntityList()->remove(this); 83 83 } -
branches/avi_play/src/world_entities/weapons/aiming_turret.cc
r5819 r5924 93 93 94 94 this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); 95 this->setProjectileType(CL_ ROCKET);95 this->setProjectileType(CL_GUIDED_MISSILE); 96 96 97 97 … … 142 142 return; 143 143 144 144 pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13) 145 145 /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); 146 146 147 pj->setTarget(this->target->getParent()); 147 148 pj->setParent(NullParent::getInstance()); 148 149 pj->setAbsCoor(this->getEmissionPoint()); -
branches/avi_play/src/world_entities/weapons/ground_turret.cc
r5819 r5924 145 145 void GroundTurret::collidesWith (WorldEntity* entity, const Vector& location) 146 146 { 147 147 if (entity->isA(CL_PROJECTILE)) 148 this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); 148 149 } 149 150 -
branches/avi_play/src/world_entities/weapons/guided_missile.cc
r5779 r5924 48 48 this->energyMin = 1; 49 49 this->energyMax = 10; 50 this->lifeSpan = 5 ;51 this->agility = 5 ;50 this->lifeSpan = 5.0; 51 this->agility = 5.0; 52 52 this->maxVelocity = 100; 53 53 -
branches/avi_play/src/world_entities/weapons/weapon_manager.cc
r5779 r5924 110 110 this->crossHairSizeAnim->addKeyFrame(100, .05, ANIM_LINEAR); 111 111 this->crossHairSizeAnim->addKeyFrame(50, .01, ANIM_LINEAR); 112 113 this->targetIterator = NULL;114 112 } 115 113 … … 337 335 } 338 336 } 339 }340 341 342 /**343 * Selects an Entity from the NPC-list, and returns the Target344 */345 PNode* WeaponManager::getSomeTarget()346 {347 if (this->targetIterator == NULL)348 {349 std::list<BaseObject*>* npcList = ClassList::getList(CL_NPC);350 if (npcList != NULL)351 {352 this->targetIterator = npcList->begin();353 }354 else355 return NULL;356 }357 358 ///FIXME359 // this->targetIterator++;360 PNode* retNode = dynamic_cast<PNode*>((*targetIterator));361 // if (retNode == NULL && this->targetIterator->getList()->getSize() > 0)362 // retNode = dynamic_cast<PNode*>(targetIterator->firstElement());363 364 return retNode;365 }366 367 368 /**369 * Selects an Entity from the Entity-List, that is near of the carrier PNode.370 * @param carrier: The PNode from which the distance should be measured371 * @param distance: The Maximum Distance to Return.372 */373 PNode* WeaponManager::getDistanceTarget(const PNode* carrier, float distance)374 {375 std::list<BaseObject*>* npcList = ClassList::getList(CL_NPC);376 if (npcList != NULL)377 {378 list<BaseObject*>::iterator node;379 for (node= npcList->begin(); node != npcList->end(); node++)380 if ((carrier->getAbsCoor() - dynamic_cast<PNode*>(*node)->getAbsCoor()).len() < distance)381 return dynamic_cast<PNode*>(*node);382 }383 return this->getFixedTarget();384 337 } 385 338 -
branches/avi_play/src/world_entities/weapons/weapon_manager.h
r5779 r5924 80 80 /** @returns a fixed target namely the Crosshair's 3D position */ 81 81 inline PNode* getFixedTarget() const { return this->crosshair; }; 82 PNode* getSomeTarget();83 PNode* getDistanceTarget(const PNode* carrier, float distance);84 82 85 83 void fire(); … … 109 107 Crosshair* crosshair; //!< an aim. 110 108 tAnimation<Crosshair>* crossHairSizeAnim; //!< An animation for the crosshair (scaling) 111 112 std::list<BaseObject*>::iterator targetIterator; //!< An iterator for traversion lists of enemies.113 109 };
Note: See TracChangeset
for help on using the changeset viewer.