Changeset 3953 in orxonox.OLD for orxonox/branches/physics/src/world_entities
- Timestamp:
- Apr 25, 2005, 9:29:41 AM (20 years ago)
- Location:
- orxonox/branches/physics/src/world_entities
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/physics/src/world_entities/player.cc
r3811 r3953 38 38 Player::Player() : WorldEntity() 39 39 { 40 this->weapons = new tList<Weapon>();41 this->activeWeapon = NULL;42 40 /* 43 41 this is the debug player - actualy we would have to make a new … … 46 44 */ 47 45 this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN); 48 //this->model = (Model*)ResourceManager::getInstance()->load("models/weapon_packet.obj", OBJ, RP_CAMPAIGN);49 46 travelSpeed = 15.0; 50 47 velocity = new Vector(); 51 48 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; 52 49 bFire = false; 50 this->bWeaponChange = false; 53 51 acceleration = 10.0; 54 52 //weapons: 55 Weapon* wpRight = new TestGun(this, new Vector(-2.6, 0.1, 3.0), new Quaternion(), 0); 56 Weapon* wpLeft = new TestGun(this, new Vector(-2.6, 0.1, -3.0), new Quaternion(), 1); 57 this->weapons->add(wpRight); 58 this->activeWeapon = wpRight; 59 this->activeWeaponL = wpLeft; 53 this->weaponMan = new WeaponManager(); 54 Weapon* wpRight = new TestGun(this,Vector(-2.6, 0.1, 3.0), Quaternion(), 0); 55 Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1); 56 57 this->weaponMan->addWeapon(wpRight, W_CONFIG0); 58 this->weaponMan->addWeapon(wpLeft, W_CONFIG1); 59 this->weaponMan->addWeapon(wpRight, W_CONFIG2); 60 this->weaponMan->addWeapon(wpLeft, W_CONFIG2); 61 60 62 } 61 63 … … 69 71 this only frees the memory allocated to save the list. 70 72 */ 71 delete this->weapon s;73 delete this->weaponMan; 72 74 } 73 75 … … 79 81 void Player::addWeapon(Weapon* weapon) 80 82 { 81 this->weapon s->add(weapon);83 this->weaponMan->addWeapon(weapon); 82 84 } 83 85 … … 89 91 void Player::removeWeapon(Weapon* weapon) 90 92 { 91 this->weapon s->remove(weapon);93 this->weaponMan->removeWeapon(weapon); 92 94 } 93 95 … … 151 153 glPopMatrix(); 152 154 153 this->activeWeapon->draw(); 154 this->activeWeaponL->draw(); 155 this->weaponMan->draw(); 155 156 } 156 157 … … 163 164 { 164 165 /* link tick to weapon */ 165 this->activeWeapon->tick(time); 166 this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE 166 //this->activeWeapon->tick(time); 167 //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE 168 this->weaponMan->tick(time); 167 169 // player controlled movement 168 170 this->move(time); … … 180 182 Vector accel(0.0, 0.0, 0.0); 181 183 /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ 182 183 184 /* calculate the direction in which the craft is heading */ 184 185 Vector direction (1.0, 0.0, 0.0); … … 210 211 if( this->bFire) 211 212 { 212 //if(this->activeWeapon != NULL) 213 this->activeWeapon->fire(); 214 //FIX THIS FIX FIIIIIIIIIIIX 215 this->activeWeaponL->fire(); 213 this->weaponMan->fire(); 216 214 } 217 if( this->bWeaponChange && this->weapons->getSize() > 1)215 if( this->bWeaponChange) 218 216 { 219 PRINTF(1)("changing the weapon of the player: deactivate old, activate new\n"); 220 this->activeWeapon->deactivate(); 221 //this->weapons->enumerate(); FIX: strang weapon change... 222 this->activeWeapon = this->weapons->nextElement(this->activeWeapon); 223 this->activeWeapon->activate(); 217 this->weaponMan->nextWeaponConf(); 218 this->bWeaponChange = false; 224 219 } 225 220 } … … 240 235 if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp; 241 236 if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp; 242 if( !strcmp( cmd->cmd, "mode")) this->bWeaponChange = !cmd->bUp;243 } 237 if( !strcmp( cmd->cmd, "mode")) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange; 238 } -
orxonox/branches/physics/src/world_entities/player.h
r3755 r3953 11 11 template<class T> class tList; 12 12 class Weapon; 13 class WeaponManager; 13 14 class Vector; 14 15 class World; … … 49 50 Weapon* activeWeapon; //!< the weapon that is currenty activated 50 51 Weapon* activeWeaponL; //temporary -- FIX THIS 52 WeaponManager* weaponMan; //!< the weapon manager: managing a list of weapon to wepaon-slot mapping 51 53 52 54 World* myWorld; //!< reference to the world object -
orxonox/branches/physics/src/world_entities/skybox.cc
r3807 r3953 187 187 model->addVertexNormal (-1.0, 0.0, 0.0); 188 188 189 model-> addUseMtl(material[0]);190 model->addFace (4, 3, 3,2,4, 4,3,4, 6,4,4, 5,1,4); // top191 model-> addUseMtl(material[1]);192 model->addFace (4, 3, 7,4,2, 8,1,2, 2,2,2, 1,3,2); // bottom193 model-> addUseMtl(material[2]);194 model->addFace (4, 3, 1,1,3, 2,2,3, 4,3,3, 3,4,3); // left195 model-> addUseMtl(material[3]);196 model->addFace (4, 3, 5,3,1, 6,4,1, 8,1,1, 7,2,1); // right197 model-> addUseMtl(material[4]);198 model->addFace (4, 3, 2,1,6, 8,2,6, 6,3,6, 4,4,6); // front199 model-> addUseMtl(material[5]);200 model->addFace (4, 3, 7,1,5, 1,2,5, 3,3,5, 5,4,5); // back189 model->setMaterial(material[0]); 190 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 3,2,4, 4,3,4, 6,4,4, 5,1,4); // top 191 model->setMaterial(material[1]); 192 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,4,2, 8,1,2, 2,2,2, 1,3,2); // bottom 193 model->setMaterial(material[2]); 194 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,3, 2,2,3, 4,3,3, 3,4,3); // left 195 model->setMaterial(material[3]); 196 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 5,3,1, 6,4,1, 8,1,1, 7,2,1); // right 197 model->setMaterial(material[4]); 198 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,1,6, 8,2,6, 6,3,6, 4,4,6); // front 199 model->setMaterial(material[5]); 200 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,1,5, 1,2,5, 3,3,5, 5,4,5); // back 201 201 202 202 model->finalize(); -
orxonox/branches/physics/src/world_entities/test_gun.cc
r3855 r3953 40 40 creates a new weapon 41 41 */ 42 TestGun::TestGun (PNode* parent, Vector* coordinate, Quaternion*direction, int leftRight)42 TestGun::TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight) 43 43 : Weapon (parent, coordinate, direction) 44 44 { … … 47 47 this->leftRight = leftRight; 48 48 49 if( this->leftRight == 0) 50 this->projOffset = new Vector(1.0, 0.0, -0.35); 51 else if( this->leftRight == 1) 52 this->projOffset = new Vector(1.0, 0.0, 0.5); 49 this->objectComponent1 = new PNode(); 50 this->animation1 = new Animation3D(this->objectComponent1); 51 parent->addChild(this->objectComponent1, PNODE_ALL); 53 52 53 this->animation1->setInfinity(ANIM_INF_CONSTANT); 54 // ANIM_LINEAR was ANIM_NEG_EXP 55 if( this->leftRight == W_LEFT) 56 { 57 this->projectileOffset = Vector(1.0, 0.0, -0.35); 54 58 55 this->dummy1 = new WorldEntity(); // a world entity that is not drawed: use this for the weapon 56 this->animation = new Animation3D(dummy1); 59 this->animation1->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR); 60 this->animation1->addKeyFrame(Vector(-3.0, 0.1, 3.0), Quaternion(), 0.5, ANIM_LINEAR); 61 this->animation1->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR); 62 } 63 else if( this->leftRight == W_RIGHT) 64 { 65 this->projectileOffset = Vector(1.0, 0.0, 0.5); 57 66 58 parent->addChild(this->dummy1, PNODE_ALL); 59 60 this->animation->setInfinity(ANIM_INF_CONSTANT); 61 // ANIM_LINEAR was ANIM_NEG_EXP 62 if( this->leftRight == 0) 63 { 64 this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR); 65 this->animation->addKeyFrame(Vector(-3.0, 0.1, 3.0), Quaternion(), 0.5, ANIM_LINEAR); 66 this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR); 67 this->animation1->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR); 68 this->animation1->addKeyFrame(Vector(-3.0, 0.1, -2.5), Quaternion(), 0.5, ANIM_LINEAR); 69 this->animation1->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR); 67 70 } 68 else if( this->leftRight == 1)69 {70 this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR);71 this->animation->addKeyFrame(Vector(-3.0, 0.1, -2.5), Quaternion(), 0.5, ANIM_LINEAR);72 this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR);73 }74 /*75 if( this->leftRight == 0)76 {77 this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.0, ANIM_NEG_EXP);78 this->animation->addKeyFrame(Vector(-3.0, 0.1, 3.0), Quaternion(), 0.1, ANIM_NEG_EXP);79 this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.5, ANIM_NEG_EXP);80 }81 else if( this->leftRight == 1)82 {83 this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.0, ANIM_NEG_EXP);84 this->animation->addKeyFrame(Vector(-3.0, 0.1, -2.5), Quaternion(), 0.1, ANIM_NEG_EXP);85 this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.5, ANIM_NEG_EXP);86 }87 */88 71 } 89 72 … … 127 110 void TestGun::fire() 128 111 { 129 if( this->localTime < this->idleTime)112 if( !this->hasWeaponIdleTimeElapsed()) 130 113 { 131 114 this->weaponIdle(); 132 115 return; 133 116 } 117 134 118 Projectile* pj = new TestBullet(this); 135 136 pj->setAbsCoor(this->getAbsCoor() + *this->projOffset); 119 pj->setAbsCoor(this->getAbsCoor() + this->projectileOffset); 137 120 pj->setAbsDir(this->getAbsDir()); 138 139 121 pj->setFlightDirection(this->getAbsDir()); 140 122 pj->setSpeed(this->getSpeed()); 141 142 123 this->worldEntities->add(pj); 143 124 this->localTime = 0; 144 125 145 this->animation ->replay();126 this->animation1->replay(); 146 127 } 147 128 … … 190 171 void TestGun::draw () 191 172 { 192 193 /* draw gun body 1 */ 173 /* draw gun body */ 194 174 glMatrixMode(GL_MODELVIEW); 195 175 glPushMatrix(); 196 176 float matrix[4][4]; 197 198 if( this->leftRight == 0) 199 { 200 glTranslatef (this->getAbsCoor ().x, 201 this->getAbsCoor ().y, 202 this->getAbsCoor ().z); 203 204 this->getAbsDir ().matrix (matrix); 205 glMultMatrixf((float*)matrix); 206 this->model->draw(1); 207 } 208 else if( this->leftRight == 1) 209 { 210 glTranslatef (this->getAbsCoor ().x, 211 this->getAbsCoor ().y, 212 this->getAbsCoor ().z); 213 214 this->getAbsDir ().matrix (matrix); 215 glMultMatrixf((float*)matrix); 216 glScalef(1.0, 1.0, -1.0); 217 this->model->draw(1); 218 } 219 177 glTranslatef (this->getAbsCoor ().x, 178 this->getAbsCoor ().y, 179 this->getAbsCoor ().z); 180 this->getAbsDir ().matrix (matrix); 181 glMultMatrixf((float*)matrix); 182 if( this->leftRight == W_RIGHT) 183 glScalef(1.0, 1.0, -1.0); 184 this->model->draw(1); 220 185 glPopMatrix(); 221 186 222 223 /* draw gun coil 1 */ 187 /* draw objectComponent1: gun coil - animated stuff */ 224 188 glMatrixMode(GL_MODELVIEW); 225 189 glPushMatrix(); 226 227 glTranslatef (this->dummy1->getAbsCoor ().x, 228 this->dummy1->getAbsCoor ().y, 229 this->dummy1->getAbsCoor ().z); 230 231 this->dummy1->getAbsDir ().matrix (matrix); 190 glTranslatef (this->objectComponent1->getAbsCoor ().x, 191 this->objectComponent1->getAbsCoor ().y, 192 this->objectComponent1->getAbsCoor ().z); 193 this->objectComponent1->getAbsDir ().matrix (matrix); 232 194 glMultMatrixf((float*)matrix); 233 195 this->model->draw(0); -
orxonox/branches/physics/src/world_entities/test_gun.h
r3855 r3953 37 37 38 38 public: 39 TestGun (PNode* parent, Vector* coordinate, Quaternion*direction, int leftRight);39 TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight); 40 40 virtual ~TestGun (); 41 41 … … 51 51 virtual void draw(void); 52 52 53 private: 54 Animation3D* animation; 55 Vector* projOffset; 56 WorldEntity* dummy1; 57 int leftRight; // this will become an enum 53 54 58 55 59 56 }; -
orxonox/branches/physics/src/world_entities/weapon.cc
r3862 r3953 16 16 */ 17 17 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON 18 19 19 20 #include "weapon.h" … … 30 31 31 32 33 /** 34 \brief this initializes the weaponManager for a given nnumber of weapon slots 35 \param number of weapon slots of the model/ship <= 8 (limitied) 36 */ 32 37 WeaponManager::WeaponManager(int nrOfSlots) 33 38 { 39 for(int i = 0; i < W_MAX_CONFIGS; ++i) 40 { 41 this->configs[i].bUsed = false; 42 for(int j = 0; j < W_MAX_SLOTS; ++j) 43 this->configs[i].slots[j] = NULL; 44 } 34 45 this->nrOfSlots = nrOfSlots; 35 this->nrOfConfigs = 1; 36 37 for(int i = 0; i < W_MAX_CONFS; ++i) 38 this->configs[i] = NULL; 39 this->currentConfig = new weaponConfig; 40 this->configs[0] = this->currentConfig; 41 } 46 this->currConfID = W_CONFIG0; 47 } 48 42 49 43 50 WeaponManager::~WeaponManager() 44 51 { 45 46 } 47 48 void WeaponManager::addWeapon(Weapon* weapon, slotID slot, configID config) 49 { 50 if(this->configs[config] == NULL) 51 PRINTF(0)(""); 52 // this->configs[(int)config]-> 53 } 54 55 void WeaponManager::addWeaponConfig(weaponConfig* config) 56 {} 57 52 /* 53 i dont have to delete the weapons itself, because they are 54 worldentities and therefore in the entities list of the world. 55 world will clean them up for me 56 */ 57 for(int i = 0; i < W_MAX_CONFIGS; ++i) 58 { 59 this->configs[i].bUsed = false; 60 for(int j = 0; j < W_MAX_SLOTS; ++j) 61 this->configs[i].slots[j] = NULL; 62 } 63 } 64 65 66 /** 67 \brief adds a weapon to the selected weaponconfiguration into the selected slot 68 \param the weapon to add 69 \param an identifier for the slot: number between 0..7 if not specified: slotID=next free slot 70 \param an identifier for the weapon configuration, number between 0..3 71 72 if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be 73 replaced by the weapon specified. if you use the W_FREE_SLOT, the manager will look for a free 74 slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be 75 a error message. 76 */ 77 void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID) 78 { 79 if( slotID == W_FREE_SLOT) 80 { 81 int freeSlot = this->getNextFreeSlot( configID); 82 if( freeSlot < 0 || freeSlot >= this->nrOfSlots) 83 { 84 PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n"); 85 return; 86 } 87 PRINTF(3)("Added new Weapon to Config:%i/Slot:%i\n", configID, freeSlot); 88 this->configs[configID].bUsed = true; 89 this->configs[configID].slots[freeSlot] = weapon; 90 return; 91 } 92 this->configs[configID].bUsed = true; 93 this->configs[configID].slots[slotID] = weapon; 94 PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID); 95 } 96 97 98 void WeaponManager::removeWeapon(Weapon* weapon, int configID) 99 { 100 /* empty */ 101 } 102 103 104 /** 105 \brief changes to the next weapon configuration 106 107 if there are multiple weapon configurations defined by the manager, use this to switch between them 108 this function will deactivate the weapons first, change the config and reactivate them later 109 */ 58 110 void WeaponManager::nextWeaponConf() 59 {} 60 61 void WeaponManager::prevWeaponConf() 62 {} 63 64 65 void WeaponManager::selectConfig(configID config) 66 { 67 if( this->configs[(int)config] != NULL) 68 this->currentConfig = this->configs[(int)config]; 69 else 70 PRINTF(0)("There is no weapon config defined with the number W_CONF%i", (int)config); 71 } 111 { 112 PRINTF(4)("Changing weapon configuration: from %i\n", this->currConfID); 113 114 Weapon* w; 115 for(int i = 0; i < W_MAX_SLOTS; ++i) 116 { 117 w = this->configs[this->currConfID].slots[i]; 118 if( w != NULL) w->deactivate(); 119 } 120 int i; 121 for(i = this->currConfID + 1; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i); 122 if( i == W_MAX_CONFIGS) this->currConfID = W_CONFIG0; 123 else this->currConfID = i; 124 PRINTF(4)("\tto %i\n", this->currConfID); 125 126 for(int i = 0; i < W_MAX_SLOTS; ++i) 127 { 128 w = this->configs[this->currConfID].slots[i]; 129 if( w != NULL) w->activate(); 130 } 131 } 132 133 134 135 /** 136 \brief triggers fire of all weapons in the current weaponconfig 137 */ 138 void WeaponManager::fire() 139 { 140 Weapon* firingWeapon; 141 for(int i = 0; i < W_MAX_SLOTS; ++i) 142 { 143 firingWeapon = this->configs[this->currConfID].slots[i]; 144 if( firingWeapon != NULL) firingWeapon->fire(); 145 } 146 } 147 148 149 /** 150 \brief triggers tick of all weapons in the current weaponconfig 151 \param second passed since last tick 152 */ 153 void WeaponManager::tick(float sec) 154 { 155 Weapon* w; 156 for(int i = 0; i < W_MAX_SLOTS; ++i) 157 { 158 w = this->configs[this->currConfID].slots[i]; 159 if( w != NULL) w->tick(sec); 160 } 161 } 162 163 164 /** 165 \brief triggers draw of all weapons in the current weaponconfig 166 */ 167 void WeaponManager::draw() 168 { 169 Weapon* w; 170 for(int i = 0; i < W_MAX_SLOTS; ++i) 171 { 172 w = this->configs[this->currConfID].slots[i]; 173 if( w != NULL) w->draw(); 174 } 175 } 176 177 178 /** 179 \brief private gets the next free slot in a certain weaponconfig 180 \param the selected weaponconfig 181 */ 182 int WeaponManager::getNextFreeSlot(int configID) 183 { 184 for( int i = 0; i < W_MAX_SLOTS; ++i) 185 { 186 if( this->configs[configID].slots[i] == NULL) 187 return i; 188 } 189 return -1; 190 } 191 192 193 72 194 73 195 … … 78 200 creates a new weapon 79 201 */ 80 Weapon::Weapon (PNode* parent, Vector* coordinate, Quaternion*direction)202 Weapon::Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction) 81 203 : WorldEntity() 82 204 { 83 205 parent->addChild(this, PNODE_ALL); 84 this->setRelCoor( *coordinate);85 this->setRelDir( *direction);206 this->setRelCoor(coordinate); 207 this->setRelDir(direction); 86 208 WorldInterface* wi = WorldInterface::getInstance(); 87 209 this->worldEntities = wi->getEntityList(); 210 211 this->objectComponent1 = NULL; 212 this->objectComponent2 = NULL; 213 this->objectComponent3 = NULL; 214 215 this->animation1 = NULL; 216 this->animation2 = NULL; 217 this->animation3 = NULL; 88 218 } 89 219 … … 95 225 { 96 226 // model will be deleted from WorldEntity-destructor 227 //this->worldEntities = NULL; 228 229 /* dont delete objectComponentsX here, they will be killed when the pnodes are cleaned out */ 230 231 /* all animations are deleted via the animation player*/ 97 232 } 98 233 … … 190 325 {} 191 326 192 /** 193 \brief sets a weapon idle time 194 \param idle time in ms 195 196 a weapon idle time is the time spend after a shoot until the weapon can 197 shoot again 198 */ 199 void Weapon::setWeaponIdleTime(float time) 200 { 201 this->idleTime = time; 202 } 203 204 /** 205 \brief gets the weapon idle time 206 \returns idle time in ms 207 208 a weapon idle time is the time spend after a shoot until the weapon can 209 shoot again 210 */ 211 float Weapon::getWeaponIdleTime(void) 212 { 213 return this->idleTime; 214 } 215 216 /** 217 \brief checks if the idle time is elapsed 218 \return true if time is elapsed 219 220 a weapon idle time is the time spend after a shoot until the weapon can 221 shoot again 222 */ 223 bool Weapon::hasWeaponIdleTimeElapsed(void) 224 { 225 return (this->localTime>this->idleTime)?true:false; 226 } 227 228 229 /** 230 \brief fires the weapon 231 232 this is called from the player.cc, when fire-button is been pushed 233 */ 234 void Weapon::fire() 235 {} 327 328 329 236 330 237 331 -
orxonox/branches/physics/src/world_entities/weapon.h
r3862 r3953 34 34 35 35 #define W_MAX_SLOTS 8 36 #define W_MAX_CONF S 436 #define W_MAX_CONFIGS 4 37 37 38 38 class Projectile; 39 39 class Weapon; 40 class Animation3D; 40 41 41 42 typedef enum { … … 48 49 } weaponSoundType; 49 50 51 50 52 //! this is an identifier for the slot. there are up to 8 weapon slots -> this means there can't be more than 8 weapons at the same time 51 typedef enum slotID {W_SLOT0=0, W_SLOT1, W_SLOT2, W_SLOT3, 52 W_SLOT4, W_SLOT5, W_SLOT6, W_SLOT7}; 53 #define W_SLOT0 0 54 #define W_SLOT1 1 55 #define W_SLOT2 2 56 #define W_SLOT3 3 57 #define W_SLOT4 4 58 #define W_SLOT5 5 59 #define W_SLOT6 6 60 #define W_SLOT7 7 61 #define W_FREE_SLOT 99 62 53 63 54 64 //! this is an identifier for the weapon config 55 typedef enum configID {W_CONFIG0=0, W_CONFIG1, 56 W_CONFIG2, W_CONFIG3}; 65 #define W_CONFIG0 0 66 #define W_CONFIG1 1 67 #define W_CONFIG2 2 68 #define W_CONFIG3 3 69 70 //! a weapon can be left or right sided 71 #define W_LEFT 0 72 #define W_RIGHT 1 57 73 58 74 //! this is a weapon Configuration: it has up to 8 slots 59 75 typedef struct weaponConfig { 60 Weapon* slot1; //<! standard right side weapon 61 Weapon* slot2; //<! standard left side weapon 62 Weapon* slot3; //<! custom 63 Weapon* slot4; //<! custom 64 Weapon* slot5; //<! custom 65 Weapon* slot6; //<! custom 66 Weapon* slot7; //<! custom 67 Weapon* slot8; //<! custom 76 bool bUsed; //<! is set to true, if this configuration is 77 Weapon* slots[8]; 68 78 }; 69 79 … … 74 84 ~WeaponManager(); 75 85 76 void addWeapon(Weapon* weapon, slotID slot, configID config = W_CONFIG0); 77 void addWeaponConfig(weaponConfig* config); 86 void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT); 87 void removeWeapon(Weapon* weapon, int configID = W_CONFIG0); 88 void nextWeaponConf(); 78 89 79 void nextWeaponConf();80 void prevWeaponConf();81 void selectConfig(configID config);90 void fire(); 91 void tick(float sec); 92 void draw(); 82 93 83 94 private: 84 int nrOfConfigs; //<! number of configurations defined85 95 int nrOfSlots; //<! number of weapon slots a ship has 86 weaponConfig* currentConfig; //<! the currently selected config 87 weaponConfig* configs[4]; //<! a list of four configurations 96 int currConfID; //<! the currently selected config 97 weaponConfig configs[4]; //<! a list of four configurations 98 99 int getNextFreeSlot(int configID); 88 100 }; 89 101 … … 93 105 94 106 public: 95 Weapon (PNode* parent, Vector* coordinate, Quaternion*direction);107 Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction); 96 108 virtual ~Weapon (); 97 109 … … 107 119 bool isActive(void); 108 120 109 void setWeaponIdleTime(float time);110 float getWeaponIdleTime(void);111 bool hasWeaponIdleTimeElapsed(void);112 121 122 /** 123 \brief sets a weapon idle time 124 \param idle time in ms 125 126 a weapon idle time is the time spend after a shoot until the weapon can 127 shoot again 128 */ 129 inline void setWeaponIdleTime(float time) { this->idleTime = time; } 130 /** 131 \brief gets the weapon idle time 132 \returns idle time in ms 133 134 a weapon idle time is the time spend after a shoot until the weapon can 135 shoot again 136 */ 137 inline float getWeaponIdleTime(void) const { return this->idleTime;} 138 /** 139 \brief checks if the idle time is elapsed 140 \return true if time is elapsed 141 142 a weapon idle time is the time spend after a shoot until the weapon can 143 shoot again 144 */ 145 inline bool hasWeaponIdleTimeElapsed(void) const { return (this->localTime>this->idleTime)?true:false; } 146 147 /** 148 \brief fires the weapon 149 150 this is called from the player.cc, when fire-button is been pushed 151 */ 113 152 virtual void fire(void) = 0; 114 153 virtual void hit (WorldEntity* weapon, Vector* loc); … … 121 160 protected: 122 161 tList<WorldEntity>* worldEntities; 123 float localTime; 124 float idleTime; 125 float slowDownFactor; 162 float localTime; //<! this is the local time. important for shooting attributes like frequency 163 float idleTime; //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay 164 float slowDownFactor; //<! if the shooting frequency is a linear function of time... 165 166 PNode* objectComponent1; //<! the gun is made of multiple parts, these PNodes represent their location and orientation 167 PNode* objectComponent2; 168 PNode* objectComponent3; 169 170 Animation3D* animation1; 171 Animation3D* animation2; 172 Animation3D* animation3; 173 174 Vector projectileOffset; 175 int leftRight; // this will become an enum 126 176 127 177 private: 128 bool enabled; 129 Projectile* projectile; 178 bool enabled; //<! states if the weapon is enabled or not 179 Projectile* projectile; //<! the projectile used for this weapon 130 180 //WeaponSound sound; 131 181 };
Note: See TracChangeset
for help on using the changeset viewer.