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