| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 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. | 
|---|
| 12 |  | 
|---|
| 13 | ### File Specific | 
|---|
| 14 | main-programmer: Patrick Boenzli | 
|---|
| 15 | co-programmer: | 
|---|
| 16 | */ | 
|---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY | 
|---|
| 18 |  | 
|---|
| 19 |  | 
|---|
| 20 | #include "executor/executor.h" | 
|---|
| 21 | #include "util/loading/factory.h" | 
|---|
| 22 | #include "util/loading/load_param.h" | 
|---|
| 23 |  | 
|---|
| 24 | #include "kill.h" | 
|---|
| 25 | #include "game_rules.h" | 
|---|
| 26 |  | 
|---|
| 27 | #include "test_entity.h" | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 | #include "interactive_model.h" | 
|---|
| 31 | #include "md2/md2Model.h" | 
|---|
| 32 |  | 
|---|
| 33 | #include "state.h" | 
|---|
| 34 |  | 
|---|
| 35 | using namespace std; | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | CREATE_FACTORY(TestEntity, CL_TEST_ENTITY); | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | TestEntity::TestEntity () | 
|---|
| 42 | { | 
|---|
| 43 | this->init(); | 
|---|
| 44 | this->md2Model = new MD2Model("models/droidika.md2", "models/droideka.pcx"); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 |  | 
|---|
| 48 | //   this->md2Model = new MD2Model("models/tris.md2", "models/tris.pcx"); | 
|---|
| 49 | // this->md2Model = new MD2Model("models/goblin.md2", "maps/goblin.bmp"); | 
|---|
| 50 | //   this->obbTree = new OBBTree(4, (sVec3D*)this->md2Model->data->pVertices, this->md2Model->data->numVertices); | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | TestEntity::TestEntity(const TiXmlElement* root) | 
|---|
| 54 | { | 
|---|
| 55 | this->init(); | 
|---|
| 56 | if (root != NULL) | 
|---|
| 57 | this->loadParams(root); | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | TestEntity::~TestEntity () | 
|---|
| 62 | {} | 
|---|
| 63 |  | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 66 | void TestEntity::init() | 
|---|
| 67 | { | 
|---|
| 68 | this->setClassID(CL_TEST_ENTITY, "TestEntity"); | 
|---|
| 69 | this->toList(OM_GROUP_00); | 
|---|
| 70 |  | 
|---|
| 71 | this->lastCollided = NULL; | 
|---|
| 72 | this->bDeath = false; | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | /** | 
|---|
| 76 | * loads the Settings of a MD2Creature from an XML-element. | 
|---|
| 77 | * @param root the XML-element to load the MD2Creature's properties from | 
|---|
| 78 | */ | 
|---|
| 79 | void TestEntity::loadParams(const TiXmlElement* root) | 
|---|
| 80 | { | 
|---|
| 81 | WorldEntity::loadParams(root); | 
|---|
| 82 |  | 
|---|
| 83 | LoadParam(root, "md2animation", this, TestEntity, setAnim) | 
|---|
| 84 | .describe("sets the animation of the md2 model") | 
|---|
| 85 | .defaultValues(1); | 
|---|
| 86 |  | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 |  | 
|---|
| 90 | void  TestEntity::setAnim(int animationIndex, int animPlaybackMode) | 
|---|
| 91 | { | 
|---|
| 92 | if( likely(this->getModel(0) != NULL)) | 
|---|
| 93 | ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode); | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 |  | 
|---|
| 97 | void TestEntity::tick (float time) | 
|---|
| 98 | { | 
|---|
| 99 | if( likely(this->getModel(0) != NULL)) | 
|---|
| 100 | ((InteractiveModel*)this->getModel(0))->tick(time); | 
|---|
| 101 |  | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 | void TestEntity::collidesWith(WorldEntity* entity, const Vector& location) | 
|---|
| 106 | { | 
|---|
| 107 | if( this->lastCollided != entity) | 
|---|
| 108 | { | 
|---|
| 109 | this->dieHard(); | 
|---|
| 110 | this->lastCollided = entity; | 
|---|
| 111 |  | 
|---|
| 112 | if(State::getGameRules()) | 
|---|
| 113 | State::getGameRules()->registerKill(Kill(entity, this)); | 
|---|
| 114 | } | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 |  | 
|---|
| 118 |  | 
|---|
| 119 | void TestEntity::dieHard() | 
|---|
| 120 | { | 
|---|
| 121 | if( this->bDeath) | 
|---|
| 122 | return; | 
|---|
| 123 |  | 
|---|
| 124 | this->bDeath = true; | 
|---|
| 125 | int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX); | 
|---|
| 126 |  | 
|---|
| 127 | PRINTF(0)("randi = %i\n", randi); | 
|---|
| 128 |  | 
|---|
| 129 | if( randi == 1) | 
|---|
| 130 | this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE); | 
|---|
| 131 | else if( randi == 2) | 
|---|
| 132 | this->setAnim(DEATH_FALLFORWARD, MD2_ANIM_ONCE); | 
|---|
| 133 | else if( randi == 3) | 
|---|
| 134 | this->setAnim(DEATH_FALLBACKSLOW, MD2_ANIM_ONCE); | 
|---|
| 135 | else if( randi == 4) | 
|---|
| 136 | this->setAnim(CROUCH_DEATH, MD2_ANIM_ONCE); | 
|---|
| 137 | else | 
|---|
| 138 | this->setAnim(DEATH_FALLBACK, MD2_ANIM_ONCE); | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|