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