home *** CD-ROM | disk | FTP | other *** search
- #include "RocketlauncherShot.h"
-
- #include "Game.h"
- #include "Network.h"
- #include "WeaponEffectsParticleClusters.h"
- #include "intersection.h"
-
- RocketlauncherShot::RocketlauncherShot(int clientId, int weaponId): Shot(clientId, weaponId, 10000){
- this->type = GAME_WEAPON_ROCKETLAUNCHER;
- this->moveSpeed = 25.0f;
- this->inflictedDamage = 45;
-
- this->model = Game::preloadedGameMedia.rocketlauncherShotModel;
-
- this->nextSmokePuffMillis = 0;
- }
-
- RocketlauncherShot::~RocketlauncherShot(){
- }
-
- void RocketlauncherShot::leaveMuzzle(){
- if( Renderer::info.var.useDynamicLighting ){
- vec3_t col;
- vectorInit3d(0.7f, 0.4f, 0.2f, col);
- Renderer::particleSystem.linkParticleCluster( new DynamicLightParticleCluster(this, col, 5.0f, 10000) );
- }
-
- if( Sound::info.var.enabled && Sound::info.var.playSamples ){
- Sound::playEffect(pos, Game::preloadedGameMedia.rocketlauncherFireSound, 0);
- }
-
- // push
- if( Network::server->clients[clientId] != NULL && Network::server->clients[clientId]->vehicle != NULL ){
- vec3_t pushForce;
- vectorScale3d(-1000.0f , this->dir, pushForce);
- Network::server->clients[clientId]->vehicle->physicsInfo.addPushForce(pushForce, 100);
- }
-
- Shot::leaveMuzzle(); // animation and some other stuff
- }
-
- void RocketlauncherShot::move(float deltaT){
- vec3_t newPos;
- vectorMA3d(pos, deltaT*moveSpeed, dir, newPos);
-
- unsigned int i;
- trace_t trace;
- trace.ignoreFlags = 0 | COLLISION_FLAG_BACKFACES | COLLISION_FLAG_SHOOT_THROUGH;
-
- traceLinesegment(pos, newPos, &trace);
-
- for(i=0;i<trace.hits.size();i++){
- if( trace.hits[i].face != NULL ){ // hit a face of the arena
- hitFace( trace.hits[i].face, trace.hits[i].pos );
- break;
- }
- if( trace.hits[i].vehicle != NULL ){ // hit a vehicle
- if( trace.hits[i].vehicle == Network::server->clients[clientId]->vehicle )
- continue;
-
- hitVehicle( trace.hits[i].vehicle, trace.hits[i].pos );
- break;
- }
- }
-
- if( Renderer::info.var.renderParticleEffects >= 2 && SDL_GetTicks() > nextSmokePuffMillis ){
- Renderer::particleSystem.linkParticleCluster( new SmallSmokePuffParticleCluster(pos) );
- nextSmokePuffMillis = SDL_GetTicks() + 30;
- }
-
-
- vectorCopy3d(newPos, pos);
-
- vectorRotateAroundNormal3d(up, dir, deltaT*10.0f, up);
- vectorRotateAroundNormal3d(left, dir, deltaT*10.0f, left);
-
- }
-
- void RocketlauncherShot::hitFace(Face* face, vec3_t hp){
- vec3_t p;
- vectorMA3d(hp, 0.5f, face->normal, p);
- Renderer::particleSystem.linkParticleCluster( new MediumExplosionParticleCluster(p) );
-
- doSplashDamage(hp);
-
- Shot::hitFace(face, hp);
- }
-
- void RocketlauncherShot::hitVehicle(Vehicle* vehicle, vec3_t hp){
-
- Renderer::particleSystem.linkParticleCluster( new MediumExplosionParticleCluster(hp) );
-
- if( Sound::info.var.enabled && Sound::info.var.playSamples ){
- Sound::playEffect(hp, Game::preloadedGameMedia.rocketlauncherImpactSound, 0);
- }
-
- doSplashDamage(hp);
-
- //Shot::hitVehicle(vehicle, hp);
- this->lifetimeMillis = 0;
- }
-
- void RocketlauncherShot::doSplashDamage(vec3_t hp){
- float r = 3.0f;
- vec3_t min, max;
- vectorInit3d(hp[0]-r, hp[1]-r, hp[2]-r, min);
- vectorInit3d(hp[0]+r, hp[1]+r, hp[2]+r, max);
-
- for(int i=0;i<GAME_MAX_VEHICLES;i++){
- if( Game::vehicles[i] == NULL )
- continue;
-
- Vehicle* v = Game::vehicles[i];
-
- vec3_t absMin, absMax;
- vectorAdd3d(v->pos, v->hitAABB.min, absMin);
- vectorAdd3d(v->pos, v->hitAABB.max, absMax);
-
- if( AABBIntersectsAABB(min, max, absMin, absMax ) ){
- vec3_t tmp;
- vectorSub3d(v->pos, hp, tmp);
- float dist = vectorLength3d(tmp);
-
- if( dist < r ){
- // push
- vec3_t pushForce;
- vectorScale3d(3000.0f * (1.0f/dist - 1.0f/r), tmp, pushForce);
- v->physicsInfo.addPushForce(pushForce, 100);
-
- // damage
- if( !Game::info.var.clientGame ){ // we are the server -> send client Hurt
- unsigned char damage = (unsigned char)( this->inflictedDamage * (1.0f - dist/r) );
- v->takeDamage(damage);
- if( v->armor > 0 ){
- Network::server->sendClientHurt(v->client->clientId, this->clientId, damage);
- }else{
- Network::server->sendClientKill(v->client->clientId, this->clientId, this->type);
- Game::killClient(v->client, Network::server->clients[this->clientId], this->type);
- }
- }
- }
-
- }
- }
- }
-
-
- void RocketlauncherShot::render(){
- glPushMatrix();
- float m[] = { left[0], left[1], left[2], 0.0f,
- up[0], up[1], up[2], 0.0f,
- dir[0], dir[1], dir[2], 0.0f,
- pos[0], pos[1], pos[2], 1.0f
- };
- glMultMatrixf(m);
-
- Renderer::renderModel(model);
-
- glPopMatrix();
- }
-