Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOPlasmaShotEntity.m
Go to the documentation of this file.
1/*
2
3OOPlasmaShotEntity.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27#import "Universe.h"
28#import "PlayerEntity.h"
29#import "OOColor.h"
31
32
33#define kPlasmaShotSize 12.0f
34#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#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- (BOOL) canCollide
70{
71 return [UNIVERSE getTime] > [self spawnTime] + kPlasmaShotActivationDelay;
72}
73
74
75- (BOOL) checkCloseCollisionWith:(Entity *)other
76{
77 return ([other rootShipEntity] != [self owner]) && ![other isEffect];
78}
79
80
81- (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
unsigned count
#define kPlasmaShotActivationDelay
#define kPlasmaShotSize
double OOTimeDelta
Definition OOTypes.h:224
#define UNIVERSE
Definition Universe.h:833
NSMutableArray * collidingEntities
Definition Entity.h:148
BOOL isEffect()
Definition Entity.m:196
ShipEntity * rootShipEntity()
Definition Entity.m:603
void takeEnergyDamage:from:becauseOf:weaponIdentifier:(double amount,[from] Entity *ent,[becauseOf] Entity *other,[weaponIdentifier] NSString *weaponIdentifier)
Definition Entity.m:990
id owner()
Definition Entity.m:583