[3573] | 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 | |
---|
| 18 | |
---|
| 19 | #include "weapon.h" |
---|
| 20 | #include "stdincl.h" |
---|
| 21 | #include "world_entity.h" |
---|
| 22 | #include "vector.h" |
---|
[3677] | 23 | #include "model.h" |
---|
[3575] | 24 | #include "projectile.h" |
---|
[3620] | 25 | #include "list.h" |
---|
| 26 | #include "world.h" |
---|
[3573] | 27 | |
---|
| 28 | using namespace std; |
---|
| 29 | |
---|
| 30 | |
---|
[3862] | 31 | |
---|
[3870] | 32 | /** |
---|
| 33 | \brief this initializes the weaponManager for a given nnumber of weapon slots |
---|
| 34 | \param number of weapon slots of the model/ship <= 8 (limitied) |
---|
| 35 | */ |
---|
[3862] | 36 | WeaponManager::WeaponManager(int nrOfSlots) |
---|
| 37 | { |
---|
| 38 | this->nrOfSlots = nrOfSlots; |
---|
[3870] | 39 | |
---|
| 40 | this->currConfID = W_CONFIG1; |
---|
| 41 | this->configs[this->currConfID].bUsed = true; |
---|
[3862] | 42 | } |
---|
| 43 | |
---|
[3870] | 44 | |
---|
[3862] | 45 | WeaponManager::~WeaponManager() |
---|
| 46 | { |
---|
[3870] | 47 | /* i dont have to delete the weapons itself, because they are |
---|
| 48 | worldentities and therefore in the entities list of the world |
---|
| 49 | */ |
---|
[3862] | 50 | } |
---|
| 51 | |
---|
[3870] | 52 | |
---|
| 53 | void WeaponManager::addWeapon(Weapon* weapon, int slotID, int configID) |
---|
[3862] | 54 | { |
---|
[3870] | 55 | if( slotID == W_FREE_SLOT) |
---|
| 56 | { |
---|
| 57 | int freeSlot = this->getNextFreeSlot(); |
---|
| 58 | if( freeSlot < 0 || freeSlot >= this->nrOfSlots) |
---|
| 59 | { |
---|
| 60 | PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n"); |
---|
| 61 | return; |
---|
| 62 | } |
---|
| 63 | this->configs[configID].slots[freeSlot] = weapon; |
---|
| 64 | return; |
---|
| 65 | } |
---|
| 66 | this->configs[configID].slots[slotID] = weapon; |
---|
| 67 | PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID); |
---|
[3862] | 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | void WeaponManager::nextWeaponConf() |
---|
[3870] | 72 | { |
---|
| 73 | for(; this->currConfID < W_MAX_CONFIGS && !this->configs[this->currConfID].bUsed; this->currConfID+=1) |
---|
| 74 | printf(""); |
---|
| 75 | } |
---|
[3862] | 76 | |
---|
[3870] | 77 | |
---|
[3862] | 78 | void WeaponManager::prevWeaponConf() |
---|
| 79 | {} |
---|
| 80 | |
---|
| 81 | |
---|
[3870] | 82 | void WeaponManager::selectConfig(int confID) |
---|
[3862] | 83 | { |
---|
[3870] | 84 | PRINTF(0)("There is no weapon config defined with the number W_CONF%i", confID); |
---|
[3862] | 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
[3870] | 89 | int WeaponManager::getNextFreeSlot() |
---|
| 90 | { |
---|
| 91 | for( int i = 0; i < W_MAX_SLOTS; ++i) |
---|
| 92 | { |
---|
| 93 | if( this->configs[this->currConfID].slots[i] == NULL) |
---|
| 94 | return i; |
---|
| 95 | } |
---|
| 96 | return -1; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
[3575] | 100 | /** |
---|
| 101 | \brief standard constructor |
---|
[3573] | 102 | |
---|
[3575] | 103 | creates a new weapon |
---|
| 104 | */ |
---|
[3631] | 105 | Weapon::Weapon (PNode* parent, Vector* coordinate, Quaternion* direction) |
---|
| 106 | : WorldEntity() |
---|
[3620] | 107 | { |
---|
[3752] | 108 | parent->addChild(this, PNODE_ALL); |
---|
[3810] | 109 | this->setRelCoor(*coordinate); |
---|
| 110 | this->setRelDir(*direction); |
---|
[3620] | 111 | WorldInterface* wi = WorldInterface::getInstance(); |
---|
| 112 | this->worldEntities = wi->getEntityList(); |
---|
| 113 | } |
---|
[3573] | 114 | |
---|
| 115 | |
---|
[3575] | 116 | /** |
---|
| 117 | \brief standard deconstructor |
---|
| 118 | */ |
---|
[3573] | 119 | Weapon::~Weapon () |
---|
| 120 | { |
---|
[3579] | 121 | // model will be deleted from WorldEntity-destructor |
---|
[3573] | 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
[3577] | 125 | /** |
---|
| 126 | \brief enables the weapon |
---|
| 127 | |
---|
| 128 | a weapon can be enabled/disabled because of various reasons. if a weapon is |
---|
| 129 | been enabled, it can interact in a world. elswhere it wont react to any |
---|
| 130 | action. |
---|
| 131 | */ |
---|
| 132 | void Weapon::enable() |
---|
[3583] | 133 | { |
---|
| 134 | this->enabled = true; |
---|
| 135 | } |
---|
[3577] | 136 | |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | \brief disables the weapon |
---|
| 140 | |
---|
| 141 | a weapon can be enabled/disabled because of various reasons. if a weapon is |
---|
| 142 | been enabled, it can interact in a world. elswhere it wont react to any |
---|
| 143 | action. |
---|
| 144 | */ |
---|
| 145 | void Weapon::disable() |
---|
[3583] | 146 | { |
---|
| 147 | this->enabled = false; |
---|
| 148 | } |
---|
[3577] | 149 | |
---|
| 150 | |
---|
| 151 | /** |
---|
| 152 | \brief checks if the weapon is enabled |
---|
| 153 | \returns true if enabled |
---|
| 154 | |
---|
| 155 | a weapon can be ebabled/disabled because of various reasons. if a weapon is |
---|
| 156 | been enabled, it can interact in a world. elswhere it wont react to any |
---|
| 157 | action. |
---|
| 158 | */ |
---|
| 159 | bool Weapon::isEnabled() |
---|
[3583] | 160 | { |
---|
| 161 | return this->enabled; |
---|
| 162 | } |
---|
[3577] | 163 | |
---|
| 164 | |
---|
[3575] | 165 | /** |
---|
| 166 | \brief sets a new projectile to the weapon |
---|
| 167 | \param new projectile for this weapon |
---|
[3573] | 168 | |
---|
[3575] | 169 | weapon an projectile are independent, so you can combine them as you want |
---|
| 170 | */ |
---|
| 171 | void Weapon::setProjectile(Projectile* projectile) |
---|
| 172 | { |
---|
| 173 | this->projectile = projectile; |
---|
| 174 | } |
---|
[3573] | 175 | |
---|
| 176 | |
---|
[3575] | 177 | /** |
---|
| 178 | \brief sets a new projectile to the weapon |
---|
| 179 | \returns the current projectile of this weapon |
---|
| 180 | |
---|
| 181 | weapon an projectile are independent, so you can combine them as you want |
---|
| 182 | */ |
---|
| 183 | Projectile* Weapon::getProjectile() |
---|
| 184 | { |
---|
| 185 | return this->projectile; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | /** |
---|
| 190 | \brief this activates the weapon |
---|
| 191 | |
---|
| 192 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 193 | activation can be connected with an animation. for example the weapon is |
---|
| 194 | been armed out. |
---|
| 195 | */ |
---|
| 196 | void Weapon::activate() |
---|
| 197 | {} |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | /** |
---|
| 201 | \brief this deactivates the weapon |
---|
| 202 | |
---|
| 203 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 204 | activation can be connected with an animation. for example the weapon is |
---|
| 205 | been armed out. |
---|
| 206 | */ |
---|
| 207 | void Weapon::deactivate() |
---|
| 208 | {} |
---|
| 209 | |
---|
| 210 | /** |
---|
| 211 | \brief asks if the current weapon is active |
---|
| 212 | \returns true if it the weapon is active |
---|
| 213 | */ |
---|
| 214 | bool Weapon::isActive() |
---|
| 215 | {} |
---|
| 216 | |
---|
[3576] | 217 | /** |
---|
[3583] | 218 | \brief sets a weapon idle time |
---|
| 219 | \param idle time in ms |
---|
[3575] | 220 | |
---|
[3583] | 221 | a weapon idle time is the time spend after a shoot until the weapon can |
---|
| 222 | shoot again |
---|
[3576] | 223 | */ |
---|
[3583] | 224 | void Weapon::setWeaponIdleTime(float time) |
---|
[3685] | 225 | { |
---|
| 226 | this->idleTime = time; |
---|
| 227 | } |
---|
[3575] | 228 | |
---|
[3576] | 229 | /** |
---|
[3583] | 230 | \brief gets the weapon idle time |
---|
| 231 | \returns idle time in ms |
---|
[3575] | 232 | |
---|
[3583] | 233 | a weapon idle time is the time spend after a shoot until the weapon can |
---|
| 234 | shoot again |
---|
[3576] | 235 | */ |
---|
[3583] | 236 | float Weapon::getWeaponIdleTime(void) |
---|
[3685] | 237 | { |
---|
| 238 | return this->idleTime; |
---|
| 239 | } |
---|
[3576] | 240 | |
---|
[3575] | 241 | /** |
---|
[3583] | 242 | \brief checks if the idle time is elapsed |
---|
| 243 | \return true if time is elapsed |
---|
[3576] | 244 | |
---|
[3583] | 245 | a weapon idle time is the time spend after a shoot until the weapon can |
---|
| 246 | shoot again |
---|
[3576] | 247 | */ |
---|
[3583] | 248 | bool Weapon::hasWeaponIdleTimeElapsed(void) |
---|
[3685] | 249 | { |
---|
| 250 | return (this->localTime>this->idleTime)?true:false; |
---|
| 251 | } |
---|
[3576] | 252 | |
---|
| 253 | |
---|
| 254 | /** |
---|
[3577] | 255 | \brief fires the weapon |
---|
| 256 | |
---|
| 257 | this is called from the player.cc, when fire-button is been pushed |
---|
[3575] | 258 | */ |
---|
[3577] | 259 | void Weapon::fire() |
---|
[3646] | 260 | {} |
---|
[3575] | 261 | |
---|
[3577] | 262 | |
---|
[3575] | 263 | /** |
---|
| 264 | \brief is called, when the weapon gets hit (=collide with something) |
---|
| 265 | \param from which entity it is been hit |
---|
| 266 | \param where it is been hit |
---|
| 267 | |
---|
| 268 | this may not be used, since it would make the game relay complicated when one |
---|
| 269 | can destroy the weapons of enemies or vice versa. |
---|
| 270 | */ |
---|
[3578] | 271 | void Weapon::hit (WorldEntity* entity, Vector* position) |
---|
[3575] | 272 | {} |
---|
| 273 | |
---|
[3577] | 274 | |
---|
[3575] | 275 | /** |
---|
| 276 | \brief is called, when the weapon is destroyed |
---|
| 277 | |
---|
| 278 | this is in conjunction with the hit function, so when a weapon is able to get |
---|
| 279 | hit, it can also be destoryed. |
---|
| 280 | */ |
---|
| 281 | void Weapon::destroy () |
---|
| 282 | {} |
---|
| 283 | |
---|
| 284 | |
---|
| 285 | /** |
---|
[3577] | 286 | \brief tick signal for time dependent/driven stuff |
---|
| 287 | */ |
---|
| 288 | void Weapon::tick (float time) |
---|
| 289 | {} |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | /** |
---|
[3583] | 293 | \brief is called, when there is no fire button pressed |
---|
| 294 | */ |
---|
| 295 | void Weapon::weaponIdle() |
---|
| 296 | {} |
---|
| 297 | |
---|
| 298 | |
---|
| 299 | /** |
---|
[3575] | 300 | \brief this will draw the weapon |
---|
| 301 | */ |
---|
[3573] | 302 | void Weapon::draw () |
---|
[3583] | 303 | {} |
---|
[3575] | 304 | |
---|