/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific main-programmer: Patrick Boenzli co-programmer: */ #include "weapon.h" #include "stdincl.h" #include "world_entity.h" #include "vector.h" #include "model.h" #include "projectile.h" #include "list.h" #include "world.h" using namespace std; /** \brief this initializes the weaponManager for a given nnumber of weapon slots \param number of weapon slots of the model/ship <= 8 (limitied) */ WeaponManager::WeaponManager(int nrOfSlots) { this->nrOfSlots = nrOfSlots; this->currConfID = W_CONFIG1; this->configs[this->currConfID].bUsed = true; } WeaponManager::~WeaponManager() { /* i dont have to delete the weapons itself, because they are worldentities and therefore in the entities list of the world */ } void WeaponManager::addWeapon(Weapon* weapon, int slotID, int configID) { if( slotID == W_FREE_SLOT) { int freeSlot = this->getNextFreeSlot(); if( freeSlot < 0 || freeSlot >= this->nrOfSlots) { PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n"); return; } this->configs[configID].slots[freeSlot] = weapon; return; } this->configs[configID].slots[slotID] = weapon; PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID); } void WeaponManager::nextWeaponConf() { for(; this->currConfID < W_MAX_CONFIGS && !this->configs[this->currConfID].bUsed; this->currConfID+=1) printf(""); } void WeaponManager::prevWeaponConf() {} void WeaponManager::selectConfig(int confID) { PRINTF(0)("There is no weapon config defined with the number W_CONF%i", confID); } int WeaponManager::getNextFreeSlot() { for( int i = 0; i < W_MAX_SLOTS; ++i) { if( this->configs[this->currConfID].slots[i] == NULL) return i; } return -1; } /** \brief standard constructor creates a new weapon */ Weapon::Weapon (PNode* parent, Vector* coordinate, Quaternion* direction) : WorldEntity() { parent->addChild(this, PNODE_ALL); this->setRelCoor(*coordinate); this->setRelDir(*direction); WorldInterface* wi = WorldInterface::getInstance(); this->worldEntities = wi->getEntityList(); } /** \brief standard deconstructor */ Weapon::~Weapon () { // model will be deleted from WorldEntity-destructor } /** \brief enables the weapon a weapon can be enabled/disabled because of various reasons. if a weapon is been enabled, it can interact in a world. elswhere it wont react to any action. */ void Weapon::enable() { this->enabled = true; } /** \brief disables the weapon a weapon can be enabled/disabled because of various reasons. if a weapon is been enabled, it can interact in a world. elswhere it wont react to any action. */ void Weapon::disable() { this->enabled = false; } /** \brief checks if the weapon is enabled \returns true if enabled a weapon can be ebabled/disabled because of various reasons. if a weapon is been enabled, it can interact in a world. elswhere it wont react to any action. */ bool Weapon::isEnabled() { return this->enabled; } /** \brief sets a new projectile to the weapon \param new projectile for this weapon weapon an projectile are independent, so you can combine them as you want */ void Weapon::setProjectile(Projectile* projectile) { this->projectile = projectile; } /** \brief sets a new projectile to the weapon \returns the current projectile of this weapon weapon an projectile are independent, so you can combine them as you want */ Projectile* Weapon::getProjectile() { return this->projectile; } /** \brief this activates the weapon This is needed, since there can be more than one weapon on a ship. the activation can be connected with an animation. for example the weapon is been armed out. */ void Weapon::activate() {} /** \brief this deactivates the weapon This is needed, since there can be more than one weapon on a ship. the activation can be connected with an animation. for example the weapon is been armed out. */ void Weapon::deactivate() {} /** \brief asks if the current weapon is active \returns true if it the weapon is active */ bool Weapon::isActive() {} /** \brief sets a weapon idle time \param idle time in ms a weapon idle time is the time spend after a shoot until the weapon can shoot again */ void Weapon::setWeaponIdleTime(float time) { this->idleTime = time; } /** \brief gets the weapon idle time \returns idle time in ms a weapon idle time is the time spend after a shoot until the weapon can shoot again */ float Weapon::getWeaponIdleTime(void) { return this->idleTime; } /** \brief checks if the idle time is elapsed \return true if time is elapsed a weapon idle time is the time spend after a shoot until the weapon can shoot again */ bool Weapon::hasWeaponIdleTimeElapsed(void) { return (this->localTime>this->idleTime)?true:false; } /** \brief fires the weapon this is called from the player.cc, when fire-button is been pushed */ void Weapon::fire() {} /** \brief is called, when the weapon gets hit (=collide with something) \param from which entity it is been hit \param where it is been hit this may not be used, since it would make the game relay complicated when one can destroy the weapons of enemies or vice versa. */ void Weapon::hit (WorldEntity* entity, Vector* position) {} /** \brief is called, when the weapon is destroyed this is in conjunction with the hit function, so when a weapon is able to get hit, it can also be destoryed. */ void Weapon::destroy () {} /** \brief tick signal for time dependent/driven stuff */ void Weapon::tick (float time) {} /** \brief is called, when there is no fire button pressed */ void Weapon::weaponIdle() {} /** \brief this will draw the weapon */ void Weapon::draw () {}