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