[9156] | 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" |
---|
[9160] | 21 | |
---|
[9156] | 22 | #include "state.h" |
---|
| 23 | |
---|
[9166] | 24 | #include "aabb.h" |
---|
| 25 | |
---|
[9160] | 26 | #include <vector> |
---|
[9156] | 27 | |
---|
[9160] | 28 | |
---|
[9156] | 29 | using namespace std; |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * standart constructor |
---|
| 34 | */ |
---|
[9157] | 35 | AimingSystem::AimingSystem (const TiXmlElement* root) |
---|
[9156] | 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"); |
---|
[9166] | 59 | |
---|
| 60 | this->loadModel("models/guns/targeting_system_body.obj"); |
---|
[9156] | 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 | |
---|
[9160] | 80 | /** |
---|
| 81 | * get back the nearest target |
---|
[9163] | 82 | * @returns the nerest target |
---|
[9160] | 83 | */ |
---|
[9166] | 84 | WorldEntity* AimingSystem::getNearestTarget() |
---|
[9160] | 85 | { |
---|
| 86 | if( this->selectionList.size() == 0) |
---|
| 87 | return NULL; |
---|
| 88 | else if( this->selectionList.size() == 1) |
---|
| 89 | return this->selectionList.back(); |
---|
[9156] | 90 | |
---|
[9163] | 91 | WorldEntity* nearestEntity = this->selectionList.back(); |
---|
| 92 | float distance = 0.0f; |
---|
| 93 | float smalestDistance = this->range * 5.0f; |
---|
[9160] | 94 | |
---|
[9163] | 95 | |
---|
[9160] | 96 | for( int i = 0; i < this->selectionList.size(); i++) |
---|
| 97 | { |
---|
[9163] | 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 | } |
---|
[9160] | 105 | |
---|
[9163] | 106 | return nearestEntity; |
---|
[9160] | 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
[9156] | 110 | /** |
---|
[9160] | 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 | /** |
---|
[9156] | 123 | * ticks the AimingSystem |
---|
| 124 | * @param dt the time to ticks |
---|
| 125 | */ |
---|
| 126 | void AimingSystem::tick(float dt) |
---|
| 127 | { |
---|
[9163] | 128 | |
---|
| 129 | this->selectionList.clear(); |
---|
[9156] | 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * draws the crosshair |
---|
| 135 | */ |
---|
| 136 | void AimingSystem::draw() const |
---|
| 137 | { |
---|
[9166] | 138 | // if( this->getModelAABB() != NULL) |
---|
| 139 | // this->getModelAABB()->drawBV(0, 1); |
---|
[9156] | 140 | } |
---|