Line data Source code
1 0 : /* 2 : 3 : OOPlasmaShotEntity.m 4 : 5 : 6 : Oolite 7 : Copyright (C) 2004-2013 Giles C Williams and contributors 8 : 9 : This program is free software; you can redistribute it and/or 10 : modify it under the terms of the GNU General Public License 11 : as published by the Free Software Foundation; either version 2 12 : of the License, or (at your option) any later version. 13 : 14 : This program is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU General Public License for more details. 18 : 19 : You should have received a copy of the GNU General Public License 20 : along with this program; if not, write to the Free Software 21 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 : MA 02110-1301, USA. 23 : 24 : */ 25 : 26 : #import "OOPlasmaShotEntity.h" 27 : #import "Universe.h" 28 : #import "PlayerEntity.h" 29 : #import "OOColor.h" 30 : #import "OOPlasmaBurstEntity.h" 31 : 32 : 33 0 : #define kPlasmaShotSize 12.0f 34 0 : #define kPlasmaShotActivationDelay 0.05f 35 : 36 : 37 : /* If nonzero, plasma shots fade with distance. Bits of this were in the old 38 : ParticleEntity code, but I think it was disabled on purpose. 39 : -- Ahruman 2009-09-25 40 : */ 41 0 : #define PLASMA_ATTENUATION 0 42 : 43 : 44 : @implementation OOPlasmaShotEntity 45 : 46 : - (id) initWithPosition:(HPVector)inPosition 47 : velocity:(Vector)inVelocity 48 : energy:(float)inEnergy 49 : duration:(OOTimeDelta)duration 50 : color:(OOColor *)color 51 : { 52 : if ((self = [super initWithDiameter:kPlasmaShotSize])) 53 : { 54 : [self setPosition:inPosition]; 55 : [self setVelocity:inVelocity]; 56 : [self setCollisionRadius:2.0]; 57 : 58 : [self setColor:color alpha:1.0]; 59 : _colorComponents[3] = 1.0f; 60 : 61 : [self setEnergy:inEnergy]; 62 : _duration = duration; 63 : } 64 : 65 : return self; 66 : } 67 : 68 : 69 0 : - (BOOL) canCollide 70 : { 71 : return [UNIVERSE getTime] > [self spawnTime] + kPlasmaShotActivationDelay; 72 : } 73 : 74 : 75 0 : - (BOOL) checkCloseCollisionWith:(Entity *)other 76 : { 77 : return ([other rootShipEntity] != [self owner]) && ![other isEffect]; 78 : } 79 : 80 : 81 0 : - (void) update:(double)delta_t 82 : { 83 : [super update:delta_t]; 84 : 85 : OOTimeDelta lifeTime = [self timeElapsedSinceSpawn]; 86 : 87 : #if PLASMA_ATTENUATION 88 : float attenuation = OOClamp_0_1_f(1.0f - lifeTime / _duration); 89 : #else 90 : const float attenuation = 1.0f; 91 : #endif 92 : 93 : NSUInteger i, count = [collidingEntities count]; 94 : for (i = 0; i < count; i++) 95 : { 96 : Entity *e = (Entity *)[collidingEntities objectAtIndex:i]; 97 : if ([e rootShipEntity] != [self owner]) 98 : { 99 : // we're going to force the weapon id to be a phantom equipment key so there is something for 100 : // the PlayerEntitySound to reference. it allow allows for the sound effects to be overridden by OXP. 101 : [e takeEnergyDamage:[self energy] * attenuation 102 : from:self 103 : becauseOf:[self owner] 104 : weaponIdentifier:@"EQ_WEAPON_PLASMA_SHOT"]; 105 : [UNIVERSE removeEntity:self]; 106 : 107 : // Spawn a plasma burst. 108 : OOPlasmaBurstEntity *burst = [[OOPlasmaBurstEntity alloc] initWithPosition:[self position]]; 109 : [UNIVERSE addEntity:burst]; 110 : [burst release]; 111 : } 112 : } 113 : 114 : #if PLASMA_ATTENUATION 115 : _colorComponents[3] = attenuation; 116 : #endif 117 : 118 : if (lifeTime > _duration) [UNIVERSE removeEntity:self]; 119 : } 120 : 121 : @end