Changeset 10703 in orxonox.OLD for branches/presentation
- Timestamp:
- Jun 15, 2007, 10:18:36 AM (18 years ago)
- Location:
- branches/presentation/src/world_entities/npcs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/presentation/src/world_entities/npcs/adm_turret.cc
r10698 r10703 25 25 26 26 #include "environments/bsp_entity.h" 27 #include "effects/explosion.h" 27 28 28 29 ObjectListDefinition(AdmTurret); … … 68 69 .describe("The filename of the World Entity, that is to be shot at") 69 70 .defaultValues(""); 70 71 LoadParam(root, "type", this, AdmTurret, setType) 72 .describe("floor|ceil"); 73 71 LoadParam(root, "type", this, AdmTurret, setType) 72 .describe("floor|ceil"); 74 73 LoadParamXML(root, "Cannons", this, AdmTurret, addCannons) 75 74 .describe("add cannons to ADM"); … … 78 77 LoadParamXML(root, "Weapon", this, AdmTurret, addWeapon) 79 78 .describe("add weapon to ADM"); 80 81 79 } 82 80 // this->removeNodeFlags( PNODE_ALL ); … … 134 132 { 135 133 this->registerObject(this, AdmTurret::_objectList); 136 134 this->setHealthMax(100); 135 this->setHealth(100); 137 136 this->bodyAngle = this->cannonAngle = 0.0f; 138 137 this->isActive = true; … … 149 148 WorldEntity::tick(dt); 150 149 if (this->weapon) this->weapon->fire(false); 151 this->updatePlayerVisible(); 152 153 //rotate sensor 2PI/sec 154 this->sensor->setAbsDir( this->sensor->getAbsDir() * Quaternion( PI*2*dt, Vector( 0, -1, 0 ) ) ); 155 156 157 Vector playerPos = this->myTarget->getAbsCoor() + Vector(0, 12, 0); 158 Vector ds = playerPos - ( this->cannons->getAbsCoor() ); 159 if ( isActive && ds.len() <= range && playerVisible ) 160 { 161 this->moveTowards( ds, dt); 150 if ( this->getHealth() <= 0 ) 151 { 152 this->moveTowards( Vector(0, -1, 0), dt*2 ); 153 } 154 else 155 { 156 162 157 163 //if target within +/- 2.5 degrees of aim -> fire 164 Vector dv1 = ds; 165 dv1.normalize(); 166 Vector dv2 = this->cannons->getAbsDir().apply( Vector(-1, 0, 0)); 167 dv2.normalize(); 168 float angle = dv1.dot(dv2); 169 if (angle > 0.999) 158 this->updatePlayerVisible(); 159 160 //rotate sensor 2PI/sec 161 this->sensor->setAbsDir( this->sensor->getAbsDir() * Quaternion( PI*2*dt, Vector( 0, -1, 0 ) ) ); 162 163 164 Vector playerPos = this->myTarget->getAbsCoor() + Vector(0, 12, 0); 165 Vector ds = playerPos - ( this->cannons->getAbsCoor() ); 166 if ( isActive && ds.len() <= range && playerVisible ) 170 167 { 171 if (this->weapon) this->weapon->fire(true); 168 this->moveTowards( ds, dt); 169 170 //if target within +/- 2.5 degrees of aim -> fire 171 Vector dv1 = ds; 172 dv1.normalize(); 173 Vector dv2 = this->cannons->getAbsDir().apply( Vector(-1, 0, 0)); 174 dv2.normalize(); 175 float angle = dv1.dot(dv2); 176 if (angle > 0.999) 177 { 178 if (this->weapon) this->weapon->fire(true); 179 } 172 180 } 173 } 174 else 175 this->moveTowards( Vector(0, -1, 0), dt ); 181 else 182 { 183 if ( !( isActive && ds.len() <= range ) ) 184 this->moveTowards( Vector(0, -1, 0), dt ); 185 } 186 } 176 187 } 177 188 … … 237 248 //this->cannons->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 238 249 //this->cannons->addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 239 250 240 251 this->cannons->toList( getOMListNumber() ); 241 242 243 252 } 244 253 … … 270 279 this->cannons->setParent( NullParent::getNullParent() ); 271 280 this->cannons->shiftCoor( this->getAbsCoor() ); 272 281 273 282 this->sensor->setParent( NullParent::getNullParent() ); 274 283 this->sensor->shiftCoor( this->getAbsCoor() ); 275 284 } 276 285 277 286 targetDir.normalize(); 278 287 279 288 float dAngle = dt; 280 289 281 290 float bestResult = -1.0f; 282 291 Quaternion bestBodyRot; … … 284 293 float bestBodyAngle = 0.0f; 285 294 float bestCannonAngle = 0.0f; 286 295 287 296 Quaternion baseRot(0, Vector(1, 0, 0)); 288 297 if ( isCeil ) … … 290 299 baseRot = Quaternion( PI, Vector( 1, 0, 0 ) ); 291 300 } 292 301 293 302 for ( int dBodyAngle = -1; dBodyAngle<2; dBodyAngle++ ) 294 303 { … … 297 306 float bodyAngle = this->bodyAngle + dBodyAngle*dAngle; 298 307 float cannonAngle = this->cannonAngle + dCannonAngle*dAngle; 299 308 300 309 while ( bodyAngle > 2*PI ) 301 310 bodyAngle -= 2*PI; … … 306 315 while ( cannonAngle < 0 ) 307 316 cannonAngle += 2*PI; 308 317 309 318 Quaternion bodyRot( bodyAngle, Vector( 0, 1, 0 ) ); 310 319 Quaternion cannonRot( cannonAngle, Vector( 0, 0, 1) ); 311 320 312 321 bodyRot = baseRot * bodyRot; 313 322 cannonRot = baseRot * cannonRot; 314 323 315 324 float result = (bodyRot * cannonRot).apply( Vector( -1, 0, 0 ) ).dot( targetDir ); 316 325 317 326 if ( result > bestResult ) 318 327 { … … 325 334 } 326 335 } 327 336 328 337 this->bodyAngle = bestBodyAngle; 329 338 this->cannonAngle = bestCannonAngle; 330 339 331 340 this->setAbsDir( bestBodyRot ); 332 341 this->cannons->setAbsDir( bestBodyRot * bestCannonRot ); … … 338 347 // for all bsp managers check all entities 339 348 Vector pos = this->cannons->getAbsCoor(); 340 Vector dir = this->myTarget->getAbsCoor() - pos; 341 349 Vector dir = this->myTarget->getAbsCoor() - pos + Vector(0, 12, 0); 342 350 343 351 this->playerVisible = true; … … 346 354 bspIterator++) { 347 355 float res = (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollisionRay( pos, dir, dir.len() + 1 ); 348 349 if ( res < dir.len() ) 350 this->playerVisible = false; 351 } 352 } 356 357 if ( res < dir.len() ) this->playerVisible = false; 358 } 359 } 360 361 void AdmTurret::destroy( WorldEntity * killer ) 362 { 363 Explosion().explode(this->cannons,Vector(1,1,1)); 364 } -
branches/presentation/src/world_entities/npcs/adm_turret.h
r10698 r10703 12 12 #include "world_entity.h" 13 13 #include "weapons/bsp_weapon.h" 14 14 15 15 16 class AdmTurret : public WorldEntity … … 32 33 33 34 virtual void setTarget(const std::string& target); 35 36 virtual void destroy(WorldEntity* killer); 34 37 35 38 private:
Note: See TracChangeset
for help on using the changeset viewer.