Changeset 6693 in orxonox.OLD for branches/network/src/world_entities
- Timestamp:
- Jan 25, 2006, 2:19:46 PM (19 years ago)
- Location:
- branches/network/src/world_entities
- Files:
-
- 21 edited
- 7 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/world_entities/Makefile.am
r6634 r6693 27 27 \ 28 28 world_entities/weapons/weapon_manager.cc \ 29 world_entities/weapons/ammo_container.cc \ 29 30 world_entities/weapons/weapon.cc \ 30 31 world_entities/weapons/test_gun.cc \ … … 51 52 world_entities/space_ships/space_ship.cc \ 52 53 world_entities/space_ships/helicopter.cc \ 54 world_entities/space_ships/hover.cc \ 53 55 world_entities/creatures/md2_creature.cc \ 54 56 \ … … 78 80 \ 79 81 world_entities/weapons/weapon_manager.h \ 82 world_entities/weapons/ammo_container.h \ 80 83 world_entities/weapons/weapon.h \ 81 84 world_entities/weapons/test_gun.h \ … … 102 105 world_entities/space_ships/space_ship.h \ 103 106 world_entities/space_ships/helicopter.h \ 107 world_entities/space_ships/hover.h \ 104 108 world_entities/creatures/md2_creature.h \ 105 109 \ -
branches/network/src/world_entities/environments/water.cc
r6686 r6693 54 54 this->rebuildGrid(); 55 55 this->waterMaterial = new Material(); 56 this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, (void*)"shaders/water.frag");56 this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, "shaders/water.frag"); 57 57 58 58 this->grid->height(this->grid->columns()/2,this->grid->rows()/2) = 100; … … 70 70 71 71 LoadParam(root, "size", this, Water, setSize) 72 73 72 .describe("the size of the WaterSurface") 73 .defaultValues(2, 1.0f, 1.0f); 74 74 75 75 LoadParam(root, "resolution", this, Water, setResolution) 76 77 76 .describe("sets the resolution of the water surface") 77 .defaultValues(2, 10, 10); 78 78 79 79 LoadParam(root, "height", this, Water, setHeight) 80 81 80 .describe("the height of the Waves") 81 .defaultValues(1, 0.5f); 82 82 } 83 83 … … 92 92 } 93 93 94 // WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();95 // if (this->grid != NULL)96 // this->grid = NULL;94 // WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel(); 95 // if (this->grid != NULL) 96 // this->grid = NULL; 97 97 98 98 this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY); … … 127 127 void Water::draw() const 128 128 { 129 //SkyBox::enableCubeMap(); 130 131 glBindTexture(GL_TEXTURE_2D, 15); 132 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 133 134 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 135 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 136 glEnable(GL_TEXTURE_GEN_S); 137 glEnable(GL_TEXTURE_GEN_T); 138 139 glEnable(GL_BLEND); 140 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 141 // this->waterShader->activateShader(); 142 // this->waterMaterial->select(); 143 WorldEntity::draw(); 144 //Shader::deactivateShader(); 145 146 SkyBox::disableCubeMap(); 129 if (this->grid != NULL) 130 { 131 //SkyBox::enableCubeMap(); 132 WorldEntity::draw(); 133 glBindTexture(GL_TEXTURE_2D, 15); 134 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 135 136 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 137 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 138 glEnable(GL_TEXTURE_GEN_S); 139 glEnable(GL_TEXTURE_GEN_T); 140 141 glEnable(GL_BLEND); 142 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 143 // this->waterShader->activateShader(); 144 // this->waterMaterial->select(); 145 //Shader::deactivateShader(); 146 147 SkyBox::disableCubeMap(); 148 } 147 149 } 148 150 149 151 void Water::tick(float dt) 150 152 { 151 /* 152 THE OLD USELESS ALGORITHM153 phase += dt *.1;154 for (unsigned int i = 0; i < this->grid->rows(); i++)155 {156 for (unsigned int j = 0; j < this->grid->columns(); j++)153 if (unlikely(this->velocities == NULL)) 154 return; 155 /* 156 THE OLD USELESS ALGORITHM 157 phase += dt *.1; 158 for (unsigned int i = 0; i < this->grid->rows(); i++) 157 159 { 158 this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+ 159 this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0); 160 for (unsigned int j = 0; j < this->grid->columns(); j++) 161 { 162 this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+ 163 this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0); 164 } 160 165 } 161 } 162 this->grid->rebuildNormals(this->height);*/ 166 this->grid->rebuildNormals(this->height);*/ 163 167 164 168 … … 168 172 // wave/advection 169 173 // calc movement 170 for(j = 1; j < this->grid->rows() - 1; j++) { 171 for(i = 1; i < this->grid->columns() - 1; i++) { 174 for(j = 1; j < this->grid->rows() - 1; j++) 175 { 176 for(i = 1; i < this->grid->columns() - 1; i++) 177 { 172 178 u = this->grid->height(i+1,j)+ this->grid->height(i-1, j) + 173 this->grid->height(i, j+1) + this->grid->height(i, j-1) -174 4 * this->grid->height(i, j);179 this->grid->height(i, j+1) + this->grid->height(i, j-1) - 180 4 * this->grid->height(i, j); 175 181 this->velocities[i][j] += dt * this->viscosity * this->viscosity * u / this->height; 176 182 this->grid->height(i, j) += dt * this->velocities[i][j]; 177 183 } 178 184 } 179 /* // advect 180 for(j = 1; j < this->grid->rows() - 1; j++) { 181 for(i = 1; i < this->grid->columns() - 1; i++) { 182 this->grid->height(i, j) += dt * this->velocities[i][j]; 183 } 184 }*/ 185 // boundraries 186 for (j = 0; j < this->grid->rows(); j++) 187 { 188 this->grid->height(0,j) = this->grid->height(1,j); 189 this->grid->height(this->grid->rows()-1,j) = this->grid->height(this->grid->rows()-2, j); 190 } 191 for (i = 0; i < this->grid->rows(); i++) 192 { 193 this->grid->height(i,0) = this->grid->height(i,1); 194 this->grid->height(i,this->grid->columns()-1) = this->grid->height(i, this->grid->columns()-2); 195 } 196 /* // advect 197 for(j = 1; j < this->grid->rows() - 1; j++) { 198 for(i = 1; i < this->grid->columns() - 1; i++) { 199 this->grid->height(i, j) += dt * this->velocities[i][j]; 200 } 201 }*/ 185 202 // bound 186 // unsigned int w = this->grid->columns - 1;187 // for(i = 0; i < this->grid->columns; i++) {188 // _map[i][0].u[1] = _map[i][1 ].u[1];189 // _map[i][w].u[1] = _map[i][w-1].u[1];190 // _map[0][i].u[1] = _map[1 ][i].u[1];191 // _map[w][i].u[1] = _map[w-1][i].u[1];192 // }203 // unsigned int w = this->grid->columns - 1; 204 // for(i = 0; i < this->grid->columns; i++) { 205 // _map[i][0].u[1] = _map[i][1 ].u[1]; 206 // _map[i][w].u[1] = _map[i][w-1].u[1]; 207 // _map[0][i].u[1] = _map[1 ][i].u[1]; 208 // _map[w][i].u[1] = _map[w-1][i].u[1]; 209 // } 193 210 194 211 // diffusion 195 for(j = 1; j < this->grid->rows() - 1; j++) { 196 for(i = 1; i < this->grid->columns() - 1 ; i++) { 212 for(j = 1; j < this->grid->rows() - 1; j++) 213 { 214 for(i = 1; i < this->grid->columns() - 1 ; i++) 215 { 197 216 u = this->grid->height(i+1, j) + this->grid->height(i-1, j) + 198 217 this->grid->height(i, j+1) + this->grid->height(i, j-1) - … … 203 222 204 223 // calc normals 205 // float l[3];206 // float m[3];207 // for(j = 1; j < this->grid->rows() -1; j++) {208 // for(i = 1; i < this->grid->columns() - 1; i++) {209 // l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;210 // l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;211 // l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;212 // m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;213 // m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;214 // m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;215 // this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];216 // this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];217 // this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];218 // }219 // }224 // float l[3]; 225 // float m[3]; 226 // for(j = 1; j < this->grid->rows() -1; j++) { 227 // for(i = 1; i < this->grid->columns() - 1; i++) { 228 // l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x; 229 // l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y; 230 // l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z; 231 // m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x; 232 // m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y; 233 // m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z; 234 // this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1]; 235 // this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2]; 236 // this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0]; 237 // } 238 // } 220 239 this->grid->rebuildNormals(this->height); 221 240 } -
branches/network/src/world_entities/movie_entity.cc
r6678 r6693 19 19 #include "load_param.h" 20 20 #include "factory.h" 21 22 #include "network_game_manager.h"23 #include "converter.h"24 21 25 22 using namespace std; -
branches/network/src/world_entities/projectiles/guided_missile.cc
r6627 r6693 43 43 this->setMaxEnergy(10); 44 44 this->lifeSpan = 10.0; 45 this->agility = 5 00;45 this->agility = 5; 46 46 this->maxVelocity = 75; 47 47 -
branches/network/src/world_entities/projectiles/laser.cc
r6654 r6693 17 17 18 18 #include "laser.h" 19 #include <assert.h> 20 19 21 20 22 #include "fast_factory.h" … … 26 28 #include "particle_emitter.h" 27 29 #include "sprite_particles.h" 30 #include <cassert> 28 31 29 32 #include "assert.h" -
branches/network/src/world_entities/space_ships/helicopter.cc
r6512 r6693 117 117 bFire = false; 118 118 xMouse = yMouse = 0; 119 mouseSensitivity = 0.0 01;120 rotorspeed = 1;121 tailrotorspeed = 0;122 123 cycle = 0.0;124 125 126 travelSpeed = 15.0;119 mouseSensitivity = 0.05; 120 //rotorspeed = 1; 121 //tailrotorspeed = 0; 122 123 //cycle = 0.0; 124 125 126 //travelSpeed = 15.0; 127 127 this->velocity = Vector(0.0,0.0,0.0); 128 128 this->velocityDir = Vector(1.0,0.0,0.0); … … 134 134 135 135 //add events to the eventlist 136 registerEvent( SDLK_w);137 registerEvent( SDLK_s);138 registerEvent( SDLK_a);139 registerEvent( SDLK_d);140 registerEvent(SDLK_q);136 registerEvent(KeyMapper::PEV_UP); 137 registerEvent(KeyMapper::PEV_DOWN); 138 registerEvent(KeyMapper::PEV_LEFT); 139 registerEvent(KeyMapper::PEV_RIGHT); 140 //registerEvent(SDLK_q); 141 141 registerEvent(SDLK_e); 142 142 registerEvent(SDLK_c); … … 144 144 registerEvent(KeyMapper::PEV_NEXT_WEAPON); 145 145 registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); 146 registerEvent(SDLK_PAGEUP);147 registerEvent(SDLK_PAGEDOWN);146 //registerEvent(SDLK_PAGEUP); 147 //registerEvent(SDLK_PAGEDOWN); 148 148 registerEvent(EV_MOUSE_MOTION); 149 149 … … 249 249 void Helicopter::tick (float time) 250 250 { 251 /* 251 252 tailrotorspeed += xMouse/20; 252 253 if (tailrotorspeed >= 0.07) tailrotorspeed = 0.07; … … 256 257 else if (tailrotorspeed < -0.0008) tailrotorspeed += 0.001; 257 258 if (tailrotorspeed <= 0.001 && tailrotorspeed >= -0.001) tailrotorspeed = 0; 258 259 */ 260 259 261 // spaceship controlled movement 260 262 this->calculateVelocity(time); 261 263 262 Vector move = (velocity) ;264 Vector move = (velocity)*time; 263 265 264 266 // this is the air friction (necessary for a smooth control) 265 267 if(velocity.len() != 0) velocity -= velocity*0.1; 268 269 //travelSpeed = velocity.len(); 266 270 267 271 //physics: Gravity 268 this->shiftCoor(Vector(0,-1,0));272 /*this->shiftCoor(Vector(0,-1,0)); 269 273 270 274 this->shiftCoor(getAbsDirY()*rotorspeed); 271 275 */ 276 277 /* 272 278 //hoover effect 273 279 cycle += time; 274 280 this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); 281 */ 275 282 276 283 //readjust … … 281 288 282 289 this->shiftCoor (move); 283 this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0)));290 //this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0))); 284 291 285 292 this->getWeaponManager()->tick(time); … … 295 302 { 296 303 Vector accel(0.0, 0.0, 0.0); 297 Vector rot(0.0, 0.0, 0.0);298 float rotVal = 0.0;304 float rotValX = 0.0; 305 float rotValZ = 0.0; 299 306 /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ 300 307 /* calculate the direction in which the craft is heading */ … … 304 311 //this->shiftCoor(this->getAbsDirX()); 305 312 //accel -= this->getAbsDirY(); 306 rot += Vector (0,0,1); 307 rotVal -= time/5; 313 314 accel += Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); 315 if((this->getAbsDirX()).y >= -0.1) rotValZ -= time; 308 316 } 309 317 else 310 318 { 311 if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time /8, Vector(0,0,1)));319 if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time, Vector(0,0,1))); 312 320 } 313 321 … … 316 324 //this->shiftCoor((this->getAbsDirX())*-1); 317 325 //accel -= this->getAbsDirY(); 318 rot += Vector (0,0,1); 319 rotVal += time/5; 326 327 accel -= Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); 328 rotValZ += time; 320 329 } 321 330 else 322 331 { 323 if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time /8, Vector(0,0,1)));332 if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time, Vector(0,0,1))); 324 333 } 325 334 … … 329 338 //accel -= this->getAbsDirY(); 330 339 //velocityDir.normalize(); 331 rot += Vector(1,0,0); 332 rotVal -= time/5; 340 341 accel -= Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); 342 rotValX -= time; 333 343 } 334 344 else 335 345 { 336 if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time /5, Vector(1,0,0)));346 if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time, Vector(1,0,0))); 337 347 } 338 348 … … 340 350 { 341 351 //this->shiftDir(Quaternion(-time, Vector(0,1,0))); 342 accel += this->getAbsDirY();352 //accel += this->getAbsDirY(); 343 353 //velocityDir.normalize(); 344 rot += Vector(1,0,0); 345 rotVal += time/5; 354 355 accel += Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); 356 rotValX += time; 346 357 } 347 358 else 348 359 { 349 if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time /5, Vector(1,0,0)));360 if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time, Vector(1,0,0))); 350 361 } 351 362 … … 371 382 //this->shiftDir(Quaternion(time, Vector(0,0,1))); 372 383 373 rotorspeed += 0.05; 374 if (rotorspeed >= 2) rotorspeed = 2; 384 accel += this->getAbsDirY(); 385 //rotorspeed += 0.05; 386 //if (rotorspeed >= 2) rotorspeed = 2; 375 387 //velocityDir.normalize(); 376 388 //rot += Vector(0,0,1); … … 379 391 else 380 392 { 381 if(rotorspeed >= 1.05) rotorspeed -= 0.05;393 //if(rotorspeed >= 1.05) rotorspeed -= 0.05; 382 394 } 383 395 … … 386 398 //this->shiftDir(Quaternion(-time, Vector(0,0,1))); 387 399 388 rotorspeed -= 0.05; 389 if (rotorspeed <= 0) rotorspeed = 0; 400 accel -= this->getAbsDirY(); 401 //rotorspeed -= 0.05; 402 //if (rotorspeed <= 0) rotorspeed = 0; 390 403 //velocityDir.normalize(); 391 404 //rot += Vector(0,0,1); … … 394 407 else 395 408 { 396 if(rotorspeed <= 0.05) rotorspeed += 0.05;397 } 398 399 //velocity += accel;400 rot.normalize();401 this->shiftDir(Quaternion(rotVal, rot));409 //if(rotorspeed <= 0.05) rotorspeed += 0.05; 410 } 411 412 velocity += accel*3; 413 if((this->getAbsDirX()).y <= 0.3 && (this->getAbsDirX()).y >= -0.3) this->shiftDir(Quaternion(rotValZ, Vector(0,0,1))); 414 if((this->getAbsDirZ()).y <= 0.3 && (this->getAbsDirZ()).y >= -0.3) this->shiftDir(Quaternion(rotValX, Vector(1,0,0))); 402 415 } 403 416 … … 429 442 430 443 431 if( event.type == SDLK_a)444 if( event.type == KeyMapper::PEV_LEFT) 432 445 this->bLeft = event.bPressed; 433 else if( event.type == SDLK_d)446 else if( event.type == KeyMapper::PEV_RIGHT) 434 447 this->bRight = event.bPressed; 435 448 else if( event.type == KeyMapper::PEV_FIRE1) … … 443 456 else if( event.type == SDLK_c) 444 457 this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); 445 else if( event.type == SDLK_w)458 else if( event.type == KeyMapper::PEV_UP) 446 459 this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); 447 else if( event.type == SDLK_s)460 else if( event.type == KeyMapper::PEV_DOWN) 448 461 this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); 449 462 else if( event.type == EV_MOUSE_MOTION) … … 452 465 this->yMouse = event.yRel*mouseSensitivity; 453 466 454 //this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)));467 this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))/*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))*/); 455 468 } 456 469 } -
branches/network/src/world_entities/space_ships/helicopter.h
r6512 r6693 57 57 float xMouse; //!< mouse moved in x-Direction 58 58 float yMouse; //!< mouse moved in y-Direction 59 int yInvert; 59 60 float mouseSensitivity; //!< the mouse sensitivity 60 float cycle; //!< hovercycle61 //float cycle; //!< hovercycle 61 62 62 63 Vector velocity; //!< the velocity of the player. … … 64 65 float travelSpeed; //!< the current speed of the player (to make soft movement) 65 66 float acceleration; //!< the acceleration of the player. 66 float rotorspeed; //!< the speed of the rotor.67 float tailrotorspeed; //!< the relativ speed ot the tail rotor67 //float rotorspeed; //!< the speed of the rotor. 68 //float tailrotorspeed; //!< the relativ speed ot the tail rotor 68 69 69 70 float airViscosity; -
branches/network/src/world_entities/space_ships/space_ship.cc
r6688 r6693 128 128 this->addWeapon(cannon, 0, 6); 129 129 130 //this->addWeapon(turret, 3, 0);131 132 130 this->getWeaponManager()->changeWeaponConfig(1); 133 131 … … 137 135 bFire = false; 138 136 xMouse = yMouse = 0; 137 yInvert = 1; 139 138 mouseSensitivity = 0.001; 140 airViscosity = 1.0; 141 cycle = 0.0; 139 airViscosity = 0.05; 140 controlVelocityX = 25; 141 controlVelocityY = 150; 142 shipInertia = 0.5 ; 143 // cycle = 0.0; 142 144 143 145 this->setMaxEnergy(100); 144 146 this->setEnergy(80); 145 147 146 travelSpeed = 15.0; 147 this->velocity = Vector(0.0,0.0,0.0); 148 travelSpeed = 40.0; 149 acceleration = 3; 150 this->velocity = this->getAbsDirX()*travelSpeed; 148 151 this->mouseDir = this->getAbsDir(); 152 this->pitchDir = this->getAbsDir(); 149 153 150 154 // GLGuiButton* button = new GLGuiPushButton(); … … 160 164 161 165 //add events to the eventlist 162 registerEvent( SDLK_w);163 registerEvent( SDLK_s);164 registerEvent( SDLK_a);165 registerEvent( SDLK_d);166 registerEvent(SDLK_q);167 registerEvent(SDLK_e);166 registerEvent(KeyMapper::PEV_UP); 167 registerEvent(KeyMapper::PEV_DOWN); 168 registerEvent(KeyMapper::PEV_LEFT); 169 registerEvent(KeyMapper::PEV_RIGHT); 170 //registerEvent(SDLK_q); 171 //registerEvent(SDLK_e); 168 172 registerEvent(KeyMapper::PEV_FIRE1); 169 173 registerEvent(KeyMapper::PEV_NEXT_WEAPON); 170 174 registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); 171 registerEvent(SDLK_PAGEUP);172 registerEvent(SDLK_PAGEDOWN);175 //registerEvent(SDLK_PAGEUP); 176 //registerEvent(SDLK_PAGEDOWN); 173 177 registerEvent(EV_MOUSE_MOTION); 174 178 … … 285 289 this->weaponAction(); 286 290 291 if( xMouse != 0 || yMouse != 0) 292 { 293 if (xMouse > controlVelocityX) xMouse = controlVelocityX; 294 else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; 295 if (yMouse > controlVelocityY) yMouse = controlVelocityY; 296 else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; 297 298 pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0))); 299 300 mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir); 301 xMouse = yMouse = 0; 302 } 303 304 287 305 // if( this != State::getPlayer()->getControllable()) 288 306 // return; … … 291 309 this->calculateVelocity(time); 292 310 293 Vector move = (velocity)*time;311 Vector move = velocity*time; 294 312 295 313 //orient the velocity in the direction of the spaceship. … … 299 317 300 318 //orient the spaceship in direction of the mouse 301 rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)* 3.0);319 rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*shipInertia); 302 320 if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) 303 321 this->setAbsDir( rotQuat); … … 305 323 306 324 // this is the air friction (necessary for a smooth control) 307 if(velocity.len() != 0) velocity -= velocity*0.01; 325 if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; 326 else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; 327 328 //other physics (gravity) 329 //if(travelSpeed < 120) 330 //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time; 308 331 309 332 //hoover effect … … 312 335 313 336 //readjust 314 315 /*316 In the game "Yager" the spaceship gets readjusted when the player moves the mouse.317 I (bknecht) go and check it out how they do it, we could probably use this also in Orxonox.318 */319 //if (xMouse != 0 && yMouse != 0)320 321 337 //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); 322 338 //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); … … 324 340 //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); 325 341 326 this->shiftCoor 342 this->shiftCoor(move); 327 343 328 344 … … 343 359 /* calculate the direction in which the craft is heading */ 344 360 345 Plane plane(Vector(0,1,0), Vector(0,0,0));361 //Plane plane(Vector(0,1,0), Vector(0,0,0)); 346 362 347 363 if( this->bUp ) 348 364 { 349 365 //this->shiftCoor(this->getAbsDirX()); 350 accel += (this->getAbsDirX())*2; 351 352 /* Heli-Steuerung 353 accel += (this->getAbsDirX()*2; 354 if( 355 */ 366 //accel += (this->getAbsDirX())*2; 367 accel += (this->getAbsDirX())*acceleration; 368 356 369 } 357 370 … … 359 372 { 360 373 //this->shiftCoor((this->getAbsDirX())*-1); 361 accel -= (this->getAbsDirX())*2; 374 //accel -= (this->getAbsDirX())*2; 375 accel -= (this->getAbsDirX())*0.5*acceleration; 362 376 } 363 377 … … 383 397 if( this->bRollL /* > -this->getRelCoor().z*2*/) 384 398 { 385 mouseDir *= Quaternion(-time , Vector(1,0,0));399 mouseDir *= Quaternion(-time*2, Vector(1,0,0)); 386 400 // accel -= rightDirection; 387 401 //velocityDir.normalize(); … … 391 405 if( this->bRollR /* > this->getRelCoor().z*2*/) 392 406 { 393 mouseDir *= Quaternion(time , Vector(1,0,0));407 mouseDir *= Quaternion(time*2, Vector(1,0,0)); 394 408 395 409 // accel += rightDirection; … … 438 452 void SpaceShip::process(const Event &event) 439 453 { 440 441 442 if( event.type == SDLK_a) 454 if( event.type == KeyMapper::PEV_LEFT) 443 455 this->bRollL = event.bPressed; 444 else if( event.type == SDLK_d)456 else if( event.type == KeyMapper::PEV_RIGHT) 445 457 this->bRollR = event.bPressed; 446 458 else if( event.type == KeyMapper::PEV_FIRE1) … … 452 464 else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed) 453 465 this->previousWeaponConfig(); 454 else if( event.type == SDLK_w)466 else if( event.type == KeyMapper::PEV_UP) 455 467 this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); 456 else if( event.type == SDLK_s)468 else if( event.type == KeyMapper::PEV_DOWN) 457 469 this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); 458 470 else if( event.type == EV_MOUSE_MOTION) 459 471 { 460 this->xMouse = event.xRel; 461 this->yMouse = event.yRel; 462 mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))); 463 // if( xMouse*xMouse + yMouse*yMouse < 0.9) 464 //this->setAbsDir(mouseDir); 472 this->xMouse += event.xRel; 473 this->yMouse += event.yRel; 465 474 } 466 475 } -
branches/network/src/world_entities/space_ships/space_ship.h
r6634 r6693 65 65 float yMouse; //!< mouse moved in y-Direction 66 66 float mouseSensitivity; //!< the mouse sensitivity 67 float cycle; //!< hovercycle 67 int yInvert; 68 int controlVelocityX; 69 int controlVelocityY; 70 // float cycle; //!< hovercycle 68 71 69 72 Vector velocity; //!< the velocity of the player. 70 73 Quaternion mouseDir; //!< the direction where the player wants to fly 74 float shipInertia; //!< the inertia of the ship(how fast the ship reacts to a mouse input) 71 75 Quaternion rotQuat; 76 Quaternion pitchDir; 72 77 float travelSpeed; //!< the current speed of the player (to make soft movement) 73 78 float acceleration; //!< the acceleration of the player. -
branches/network/src/world_entities/weapons/aim.cc
r6512 r6693 73 73 this->source = NULL; 74 74 75 this->range = 0; 76 this->angle = 0; 75 77 this->anim = new tAnimation<Aim>(this, &Aim::setSize); 76 78 this->anim->setInfinity(ANIM_INF_CONSTANT); … … 101 103 } 102 104 103 void Aim::searchTarget( float range)105 void Aim::searchTarget() 104 106 { 105 107 std::list<WorldEntity*>::iterator entity; 106 108 Vector diffVec(0.0, 0.0, 0.0); 109 diffVec = ( this->getAbsCoor() - this->source->getAbsCoor() ); 110 111 //only look for target if the aim hasn`t locked a target yet or if the actual target is out of range 112 if( this == PNode::getNullParent() || diffVec.len() > range || ( acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) > angle)) 107 113 for (entity = State::getObjectManager()->getObjectList(OM_GROUP_00).begin(); 108 114 entity != State::getObjectManager()->getObjectList(OM_GROUP_00).end(); 109 115 entity ++) 110 116 { 111 if (this->source->getAbsCoor().x < (*entity)->getAbsCoor().x && (this->source->getAbsCoor() - (*entity)->getAbsCoor()).len() < range) 117 diffVec = ( (*entity)->getAbsCoor() - this->source->getAbsCoor() ); 118 119 if ( diffVec.len() < range && acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) < angle) 112 120 { 113 121 if (this->getParent() != (*entity)) … … 119 127 } 120 128 } 121 } 122 129 //if no target found: 130 this->setParent(PNode::getNullParent()); 131 } 123 132 124 133 … … 155 164 156 165 157 if (this->source->getAbsCoor().x > this->getAbsCoor().x )158 this->searchTarget(1000);166 // if (this->source->getAbsCoor().x > this->getAbsCoor().x ) 167 this->searchTarget(); 159 168 // float z = 0.0f; 160 169 // glReadPixels ((int)this->getAbsCoor2D().x, -
branches/network/src/world_entities/weapons/aim.h
r6512 r6693 38 38 inline PNode* getTarget(PNode* target) { return this->getParent(); }; 39 39 40 void searchTarget(float range); 40 void searchTarget(); 41 42 void setRange(float range){this->range = range;}; 43 void setAngle(float angle){this->angle = angle;}; 41 44 42 45 void setSize(float size); … … 53 56 tAnimation<Aim>* anim; 54 57 58 float range; //!< 59 float angle; //!< 60 55 61 PNode* source; //!< Where this Shot has come from. 56 62 -
branches/network/src/world_entities/weapons/aiming_turret.cc
r6512 r6693 86 86 this->setStateDuration(WS_DEACTIVATING, .4); 87 87 88 this->set MaximumEnergy(10000, 50);88 this->setEnergyMax(10000); 89 89 this->increaseEnergy(100000); 90 90 … … 98 98 this->target = new Aim(this); 99 99 this->target->setVisibility(false); 100 this->target->setRange(100); 101 this->target->setAngle(M_PI); 100 102 } 101 103 … … 146 148 pj->setAbsDir(this->getAbsDir()); 147 149 pj->activate(); 148 this->target->searchTarget( 100);150 this->target->searchTarget(); 149 151 } 150 152 -
branches/network/src/world_entities/weapons/cannon.cc
r6517 r6693 81 81 this->setStateDuration(WS_DEACTIVATING, .4); 82 82 83 this->set MaximumEnergy(100, 20);83 this->setEnergyMax(100); 84 84 this->increaseEnergy(100); 85 85 //this->minCharge = 2; -
branches/network/src/world_entities/weapons/targeting_turret.cc
r6675 r6693 81 81 this->setStateDuration(WS_DEACTIVATING, .4); 82 82 83 this->set MaximumEnergy(10000, 50);83 this->setEnergyMax(10000); 84 84 this->increaseEnergy(100000); 85 85 … … 93 93 this->target = new Aim(this); 94 94 this->target->setVisibility(false); 95 95 this->target->setRange(100); 96 this->target->setAngle(M_PI_4/2); 97 this->lockedTime = 0; 98 this->neededLockTime = 2; 99 this->lockedTarget->setParent(PNode::getNullParent()); 96 100 this->loadModel("models/guns/turret2.obj"); 97 101 … … 120 124 void TargetingTurret::tick(float dt) 121 125 { 126 if( lockedTime >= neededLockTime ) 127 { 128 lockedTarget = this->target->getParent(); 129 lockedTime = 0; 130 } 122 131 123 132 this->target->tick(dt); 133 134 if(this->target->getParent() == PNode::getNullParent()) 135 lockedTime = 0; 136 else 137 lockedTime += dt; 138 124 139 } 125 140 … … 138 153 pj->setAbsDir(this->getAbsDir()); 139 154 pj->activate(); 140 this->target->searchTarget( 100);155 this->target->searchTarget(); 141 156 } 142 157 -
branches/network/src/world_entities/weapons/targeting_turret.h
r6512 r6693 32 32 33 33 private: 34 Aim* target; 35 }; 34 Aim* target; 35 PNode* lockedTarget; 36 float lockedTime; 37 float neededLockTime; 38 }; 36 39 37 40 #endif /* _TARGETING_TURRET_H */ -
branches/network/src/world_entities/weapons/test_gun.cc
r6512 r6693 122 122 this->setStateDuration(WS_DEACTIVATING, .4); 123 123 124 this->set MaximumEnergy(1000, 100);124 this->setEnergyMax(1000); 125 125 this->increaseEnergy(1000); 126 126 //this->minCharge = 2; -
branches/network/src/world_entities/weapons/turret.cc
r6589 r6693 86 86 this->setStateDuration(WS_DEACTIVATING, .4); 87 87 88 this->set MaximumEnergy(100, 5);88 this->setEnergyMax(100); 89 89 this->increaseEnergy(100); 90 90 //this->minCharge = 2; -
branches/network/src/world_entities/weapons/weapon.cc
r6674 r6693 95 95 this->maxCharge = 1.0; //< The maximum charge is also one unit. 96 96 97 this->energyLoaded = .0; //< How much energy is loaded in the Gun. (Weapons must be charged befor usage) 98 this->energyLoadedMax = 5.0; //< Each Weapon has a Maximum energy that can be charged onto it 99 this->energy = .0; //< The secondary Buffer (before we have to reload) 97 this->energy = 10; //< The secondary Buffer (before we have to reload) 100 98 this->energyMax = 10.0; //< How much energy can be carried 101 99 this->capability = WTYPE_ALL; //< The Weapon has all capabilities @see W_Capability. 102 100 103 101 this->energyWidget = NULL; 104 this->energyLoadedWidget = NULL;105 102 106 103 // set this object to be synchronized over network … … 291 288 } 292 289 293 294 GLGuiWidget* Weapon::getLoadedEnergyWidget()295 {296 if (this->energyLoadedWidget == NULL)297 {298 this->energyLoadedWidget = new GLGuiBar;299 //this->energyLoadedWidget->setParent2D(this->bar);300 this->energyLoadedWidget->setRelCoor2D(20,0);301 this->energyLoadedWidget->setSize2D(10,50);302 this->energyLoadedWidget->setMaximum(this->getLoadedEnergyMax());303 }304 return this->energyLoadedWidget;305 }306 307 290 void Weapon::updateWidgets() 308 291 { … … 311 294 this->energyWidget->setMaximum(this->energyMax); 312 295 this->energyWidget->setValue(this->energy); 313 }314 if (this->energyLoadedWidget != NULL)315 {316 this->energyLoadedWidget->setMaximum(this->energyLoadedMax);317 this->energyLoadedWidget->setValue(this->energyLoaded);318 296 } 319 297 } … … 395 373 switch (action) 396 374 { 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 375 case WA_SHOOT: 376 return this->fireW(); 377 break; 378 case WA_CHARGE: 379 return this->chargeW(); 380 break; 381 case WA_RELOAD: 382 return this->reloadW(); 383 break; 384 case WA_DEACTIVATE: 385 return this->deactivateW(); 386 break; 387 case WA_ACTIVATE: 388 return this->activateW(); 389 break; 412 390 } 413 391 } … … 457 435 bool Weapon::chargeW() 458 436 { 459 if ( this->currentState != WS_INACTIVE && this->energy Loaded>= this->minCharge)437 if ( this->currentState != WS_INACTIVE && this->energy >= this->minCharge) 460 438 { 461 439 // playing Sound … … 481 459 { 482 460 //if (likely(this->currentState != WS_INACTIVE)) 483 if (this->minCharge <= this->energy Loaded)461 if (this->minCharge <= this->energy) 484 462 { 485 463 // playing Sound … … 488 466 this->updateWidgets(); 489 467 // fire 490 this->energy Loaded-= this->minCharge;468 this->energy -= this->minCharge; 491 469 this->fire(); 492 470 // setting up for the next state … … 507 485 { 508 486 PRINTF(4)("Reloading Weapon %s\n", this->getName()); 509 if (unlikely(this->energy + this->energyLoaded < this->minCharge)) 487 if (this->ammoContainer.get() != NULL && 488 unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge)) 510 489 { 511 490 this->requestAction(WA_DEACTIVATE); … … 514 493 } 515 494 516 float chargeSize = this->energyLoadedMax - this->energyLoaded; //!< The energy to be charged517 495 518 496 if (this->soundBuffers[WA_RELOAD] != NULL) 519 497 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 520 498 521 if (chargeSize > this->energy) 522 { 523 this->energyLoaded += this->energy; 524 this->energy = 0.0; 525 PRINT(5)("Energy depleted\n"); 526 } 527 else 528 { 529 PRINTF(5)("Loaded %f energy into the Guns Buffer\n", chargeSize); 530 this->energyLoaded += chargeSize; 531 this->energy -= chargeSize; 532 } 533 499 if (this->ammoContainer.get() != NULL) 500 this->ammoContainer->fillWeapon(this); 501 else 502 { 503 this->energy = this->energyMax; 504 } 534 505 this->updateWidgets(); 535 506 this->reload(); … … 617 588 { 618 589 PRINT(0)("Weapon-Debug %s, state: %s (duration: %fs), nextAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), this->stateDuration, Weapon::actionToChar(requestedAction)); 619 PRINT(0)("Energy: max: %f; current: %f; loadedMax: %f; loadedCurrent: %f;chargeMin: %f, chargeMax %f\n",620 this->energyMax, this->energy, this-> energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);590 PRINT(0)("Energy: max: %f; current: %f; chargeMin: %f, chargeMax %f\n", 591 this->energyMax, this->energy, this->minCharge, this->maxCharge); 621 592 622 593 … … 663 634 switch (action) 664 635 { 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 636 case WA_SHOOT: 637 return "shoot"; 638 break; 639 case WA_CHARGE: 640 return "charge"; 641 break; 642 case WA_RELOAD: 643 return "reload"; 644 break; 645 case WA_ACTIVATE: 646 return "activate"; 647 break; 648 case WA_DEACTIVATE: 649 return "deactivate"; 650 break; 651 case WA_SPECIAL1: 652 return "special1"; 653 break; 654 default: 655 return "none"; 656 break; 686 657 } 687 658 } … … 726 697 switch (state) 727 698 { 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 } 753 } 699 case WS_SHOOTING: 700 return "shooting"; 701 break; 702 case WS_CHARGING: 703 return "charging"; 704 break; 705 case WS_RELOADING: 706 return "reloading"; 707 break; 708 case WS_ACTIVATING: 709 return "activating"; 710 break; 711 case WS_DEACTIVATING: 712 return "deactivating"; 713 break; 714 case WS_IDLE: 715 return "idle"; 716 break; 717 case WS_INACTIVE: 718 return "inactive"; 719 break; 720 default: 721 return "none"; 722 break; 723 } 724 } -
branches/network/src/world_entities/weapons/weapon.h
r6512 r6693 16 16 17 17 #include "world_entity.h" 18 #include "count_pointer.h" 19 #include "ammo_container.h" 18 20 19 21 // FORWARD DECLARATION … … 105 107 inline void setCapability(long capabilities) { this->capability = capabilities; }; 106 108 /** @returns the Capabilities of this Weapon */ 107 inline long getCapability() { return this->capability; };109 inline long getCapability() const { return this->capability; }; 108 110 void setProjectileType(ClassID projectile); 109 111 void setProjectileType(const char* projectile); … … 135 137 inline WeaponState getCurrentState() const { return this->currentState; }; 136 138 137 /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers*/138 inline void set MaximumEnergy(float energyMax, float energyLoadedMax) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };139 inline float get LoadedEnergyMax() const { return this->energyLoadedMax; };139 /** @param energyMax the maximum energy the Weapon can have */ 140 inline void setEnergyMax(float energyMax) { this->energyMax = energyMax; }; 141 inline float getEnergy() const { return this->energy; }; 140 142 inline float getEnergyMax() const { return this->energyMax; }; 141 inline float getEnergy() const { return this->energy; }; 142 inline float getLoadedEnergy() const { return this->energyLoaded; }; 143 inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;} 143 144 144 145 void setActionSound(WeaponAction action, const char* soundFile); … … 150 151 151 152 GLGuiWidget* getEnergyWidget(); 152 GLGuiWidget* getLoadedEnergyWidget();153 153 154 154 // FLOW … … 198 198 199 199 // it is all about energy 200 float energy; //!< The energy stored in the weapons secondary buffers (reserve) 201 float energyLoaded; //!< The energy stored in the weapons primary buffers (fire without reload) 200 float energy; //!< The energy stored in the weapons buffers 202 201 float energyMax; //!< The maximal energy that can be stored in the secondary buffers (reserveMax) 203 float energyLoadedMax; //!< The maximal energy that can be stored in the primary buffers202 CountPointer<AmmoContainer> ammoContainer; //!< Pointer to the AmmoContainer this weapon grabs Energy from. 204 203 //! @todo move this to projectile 205 204 float minCharge; //!< The minimal energy to be loaded onto one projectile if chargeable otherwise the power consumed by one projectile … … 207 206 208 207 GLGuiBar* energyWidget; 209 GLGuiBar* energyLoadedWidget;210 208 211 209 //////////// -
branches/network/src/world_entities/weapons/weapon_manager.cc
r6568 r6693 217 217 bool WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID) 218 218 { 219 assert(weapon != NULL); 220 219 221 if (unlikely(configID >= WM_MAX_CONFIGS || slotID >= (int)this->slotCount)) 220 222 { 221 PRINTF(2)("Slot %d of config %d is not availiabe (max: %d)\n", slotID, configID, this->slotCount); 223 PRINTF(2)("Slot %d of config %d is not availiabe (max: %d) searching for suitable slot\n", slotID, configID, this->slotCount); 224 if (configID >= WM_MAX_CONFIGS) 225 configID = -1; 226 if (slotID >= (int)this->slotCount) 227 slotID = -1; 228 } 229 // if no ConfigID is supplied set to Current Config. 230 if (configID <= -1) 231 configID = this->currentConfigID; 232 // 233 if (configID > -1 && slotID == -1) 234 { 235 slotID = this->getNextFreeSlot(configID, weapon->getCapability()); 236 if (slotID == -1) 237 configID = -1; 238 } 239 240 if (configID > 0 && slotID > 0 && this->configs[configID][slotID] != NULL) 241 { 242 PRINTF(3)("Weapon-slot %d/%d of %s already poulated, remove weapon (%s::%s) first\n", configID, slotID, this->getName(), weapon->getClassName(), weapon->getName()); 222 243 return false; 223 244 } 224 245 225 if (this->configs[configID][slotID] != NULL && configID > 0 && slotID > 0) 226 PRINTF(3)("Weapon-slot %d/%d of %s already poulated, overwriting\n", configID, slotID, this->getName()); 227 228 if (slotID == -1) // WM_FREE_SLOT 246 if (slotID <= -1) // WM_FREE_SLOT 229 247 { 230 248 slotID = this->getNextFreeSlot(configID, weapon->getCapability()); … … 245 263 246 264 //! @todo check if the weapon is already assigned to another config in another slot 265 assert(this->configs[configID][slotID] == NULL); 266 247 267 this->configs[configID][slotID] = weapon; 268 weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType())); 248 269 if (this->parent != NULL) 249 270 { 250 271 this->parent->addChild(weapon); 251 272 } 252 PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);273 PRINTF(3)("Added a new Weapon (%s::%s) to the WeaponManager: config %i/ slot %i\n", weapon->getClassName(), weapon->getName(), configID, slotID); 253 274 return true; 254 275 } … … 420 441 /** 421 442 * private gets the next free slot in a certain weaponconfig 422 * @param the selected weaponconfig 443 * @param the selected weaponconfig -1 if none found 423 444 */ 424 445 int WeaponManager::getNextFreeSlot(int configID, long capability) 425 446 { 426 for( int i = 0; i < this->slotCount; ++i) 427 { 428 if( this->configs[configID][i] == NULL && 429 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) && 430 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS)) 431 return i; 447 if (configID == -1) 448 { 449 for (configID = 0; configID < WM_MAX_CONFIGS; configID++) 450 for( int i = 0; i < this->slotCount; ++i) 451 { 452 if( this->configs[configID][i] == NULL && 453 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) && 454 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS)) 455 return i; 456 } 457 } 458 else 459 { 460 for( int i = 0; i < this->slotCount; ++i) 461 { 462 if( this->configs[configID][i] == NULL && 463 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) && 464 (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS)) 465 return i; 466 } 432 467 } 433 468 return -1; 434 469 } 435 470 471 CountPointer<AmmoContainer>& WeaponManager::getAmmoContainer(ClassID projectileType) 472 { 473 for (unsigned int i = 0; i < this->ammo.size(); i++) 474 { 475 if (this->ammo[i]->getProjectileType() == projectileType) 476 return this->ammo[i]; 477 } 478 this->ammo.push_back(CountPointer<AmmoContainer>(new AmmoContainer(projectileType))); 479 return this->ammo.back(); 480 } 436 481 437 482 -
branches/network/src/world_entities/weapons/weapon_manager.h
r6561 r6693 17 17 #include "crosshair.h" 18 18 #include "weapon.h" 19 20 #include "count_pointer.h" 21 #include "ammo_container.h" 19 22 20 23 // FORWARD DECLARATION … … 71 74 PNode* getParent() const { return this->parent; }; 72 75 73 bool addWeapon(Weapon* weapon);74 76 bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); 75 77 void removeWeapon(Weapon* weapon, int configID = -1); 78 76 79 Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; }; 77 80 … … 82 85 void previousWeaponConfig(); 83 86 void changeWeaponConfig(int weaponConfig); 87 88 float addAmmunition(ClassID projectileType, float ammo); 89 84 90 85 91 /** @returns a fixed target namely the Crosshair's 3D position */ … … 97 103 // private: 98 104 int getNextFreeSlot(int configID, long capability = WTYPE_ALL); 105 CountPointer<AmmoContainer>& getAmmoContainer(ClassID projectileType); 99 106 100 107 private: … … 112 119 Crosshair* crosshair; //!< an aim. 113 120 tAnimation<Crosshair>* crossHairSizeAnim; //!< An animation for the crosshair (scaling) 121 122 std::vector<CountPointer<AmmoContainer> > ammo; //!< Containers 114 123 }; 115 124
Note: See TracChangeset
for help on using the changeset viewer.