1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
17 | |
---|
18 | #include "aiming_system.h" |
---|
19 | |
---|
20 | #include "util/loading/load_param.h" |
---|
21 | |
---|
22 | #include "state.h" |
---|
23 | |
---|
24 | #include "aabb.h" |
---|
25 | |
---|
26 | #include <vector> |
---|
27 | |
---|
28 | |
---|
29 | using namespace std; |
---|
30 | |
---|
31 | |
---|
32 | /** |
---|
33 | * standart constructor |
---|
34 | */ |
---|
35 | AimingSystem::AimingSystem (const TiXmlElement* root) |
---|
36 | { |
---|
37 | this->init(); |
---|
38 | |
---|
39 | |
---|
40 | if (root) |
---|
41 | this->loadParams(root); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | /** |
---|
46 | * destroys a AimingSystem |
---|
47 | */ |
---|
48 | AimingSystem::~AimingSystem () |
---|
49 | {} |
---|
50 | |
---|
51 | |
---|
52 | /** |
---|
53 | * initializes the AimingSystem |
---|
54 | */ |
---|
55 | void AimingSystem::init() |
---|
56 | { |
---|
57 | this->setClassID(CL_CROSSHAIR, "AimingSystem"); |
---|
58 | this->setName("AimingSystem"); |
---|
59 | |
---|
60 | this->loadModel("models/guns/targeting_system_body.obj"); |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | void AimingSystem::loadParams(const TiXmlElement* root) |
---|
65 | { |
---|
66 | PNode::loadParams(root); |
---|
67 | |
---|
68 | // LoadParam(root, "texture", this, AimingSystem, setTexture) |
---|
69 | // .describe("the texture-file to load onto the AimingSystem"); |
---|
70 | // |
---|
71 | // LoadParam(root, "size", this, AimingSystem, setSize) |
---|
72 | // .describe("the size of the AimingSystem in Pixels"); |
---|
73 | // |
---|
74 | // LoadParam(root, "rotation-speed", this, AimingSystem, setRotationSpeed) |
---|
75 | // .describe("the Speed with which the AimingSystem should rotate"); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | /** |
---|
81 | * get back the nearest target |
---|
82 | * @returns the nerest target |
---|
83 | */ |
---|
84 | WorldEntity* AimingSystem::getNearestTarget() |
---|
85 | { |
---|
86 | if( this->selectionList.size() == 0) |
---|
87 | return NULL; |
---|
88 | else if( this->selectionList.size() == 1) |
---|
89 | return this->selectionList.back(); |
---|
90 | |
---|
91 | WorldEntity* nearestEntity = this->selectionList.back(); |
---|
92 | float distance = 0.0f; |
---|
93 | float smalestDistance = this->range * 5.0f; |
---|
94 | |
---|
95 | |
---|
96 | for( int i = 0; i < this->selectionList.size(); i++) |
---|
97 | { |
---|
98 | distance = fabs((this->getAbsCoor() - this->selectionList[i]->getAbsCoor()).len()); |
---|
99 | if( distance < smalestDistance) |
---|
100 | { |
---|
101 | nearestEntity = this->selectionList[i]; |
---|
102 | smalestDistance = distance; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | return nearestEntity; |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | /** |
---|
111 | * called when an object is "selected" |
---|
112 | * @param damage damage to be dealt |
---|
113 | * @param killer the entity |
---|
114 | */ |
---|
115 | void AimingSystem::hit(float damage, WorldEntity* killer) |
---|
116 | { |
---|
117 | this->selectionList.push_back(killer); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | /** |
---|
123 | * ticks the AimingSystem |
---|
124 | * @param dt the time to ticks |
---|
125 | */ |
---|
126 | void AimingSystem::tick(float dt) |
---|
127 | { |
---|
128 | |
---|
129 | this->selectionList.clear(); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | /** |
---|
134 | * draws the crosshair |
---|
135 | */ |
---|
136 | void AimingSystem::draw() const |
---|
137 | { |
---|
138 | // if( this->getModelAABB() != NULL) |
---|
139 | // this->getModelAABB()->drawBV(0, 1); |
---|
140 | } |
---|