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 "util/loading/factory.h" |
---|
21 | #include "util/loading/load_param.h" |
---|
22 | |
---|
23 | |
---|
24 | #include "interactive_model.h" |
---|
25 | |
---|
26 | #include "door.h" |
---|
27 | #include "class_list.h" |
---|
28 | |
---|
29 | |
---|
30 | using namespace std; |
---|
31 | |
---|
32 | |
---|
33 | CREATE_FACTORY(Door, CL_DOOR); |
---|
34 | |
---|
35 | |
---|
36 | Door::Door () |
---|
37 | { |
---|
38 | this->init(); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | Door::Door(const TiXmlElement* root) |
---|
43 | { |
---|
44 | this->init(); |
---|
45 | if (root != NULL) |
---|
46 | this->loadParams(root); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | Door::~Door () |
---|
51 | {} |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | void Door::init() |
---|
56 | { |
---|
57 | this->setClassID(CL_DOOR, "Door"); |
---|
58 | this->toList(OM_COMMON); |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * loads the Settings of a MD2Creature from an XML-element. |
---|
63 | * @param root the XML-element to load the MD2Creature's properties from |
---|
64 | */ |
---|
65 | void Door::loadParams(const TiXmlElement* root) |
---|
66 | { |
---|
67 | WorldEntity::loadParams(root); |
---|
68 | |
---|
69 | // LoadParam(root, "", this, Door, set) |
---|
70 | // .describe("sets the animation of the md2 model") |
---|
71 | // .defaultValues(1); |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | void Door::setAnim(int animationIndex, int animPlaybackMode) |
---|
77 | { |
---|
78 | if( likely(this->getModel(0) != NULL)) |
---|
79 | ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | void Door::tick (float time) |
---|
84 | { |
---|
85 | if( likely(this->getModel(0) != NULL)) |
---|
86 | ((InteractiveModel*)this->getModel(0))->tick(time); |
---|
87 | |
---|
88 | |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | * checks if the door is open |
---|
95 | */ |
---|
96 | bool Door::checkOpen() |
---|
97 | { |
---|
98 | |
---|
99 | std::list<BaseObject*>::const_iterator it; |
---|
100 | const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE); |
---|
101 | WorldEntity* entity; |
---|
102 | float distance; |
---|
103 | |
---|
104 | if( list == NULL) |
---|
105 | return false; |
---|
106 | |
---|
107 | // for all players |
---|
108 | for( it = list->begin(); it != list->end(); it++) |
---|
109 | { |
---|
110 | entity = dynamic_cast<WorldEntity*>(*it); |
---|
111 | |
---|
112 | distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len()); |
---|
113 | if( distance < this->actionRadius) |
---|
114 | return true; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | list = ClassList::getList(CL_GENERIC_NPC); |
---|
119 | if( list == NULL) |
---|
120 | return false; |
---|
121 | for( it = list->begin(); it != list->end(); it++) |
---|
122 | { |
---|
123 | entity = dynamic_cast<WorldEntity*>(*it); |
---|
124 | |
---|
125 | distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len()); |
---|
126 | if( distance < this->actionRadius) |
---|
127 | return true; |
---|
128 | } |
---|
129 | |
---|
130 | return false; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | |
---|