Oolite
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 "OOColor.h"
29#import "PlayerEntity.h"
30#import "Universe.h"
31
32#define kPlasmaShotSize 12.0f
33#define kPlasmaShotActivationDelay 0.05f
34
35/* If nonzero, plasma shots fade with distance. Bits of this were in the old
36 ParticleEntity code, but I think it was disabled on purpose.
37 -- Ahruman 2009-09-25
38*/
39#define PLASMA_ATTENUATION 0
40
41@implementation OOPlasmaShotEntity
42
43- (id)initWithPosition:(HPVector)inPosition
44 velocity:(Vector)inVelocity
45 energy:(float)inEnergy
46 duration:(OOTimeDelta)duration
47 color:(OOColor*)color
48{
49 if ((self = [super initWithDiameter:kPlasmaShotSize])) {
50 [self setPosition:inPosition];
51 [self setVelocity:inVelocity];
52 [self setCollisionRadius:2.0];
53
54 [self setColor:color alpha:1.0];
55 _colorComponents[3] = 1.0f;
56
57 [self setEnergy:inEnergy];
58 _duration = duration;
59 }
60
61 return self;
62}
63
65{
66 return [UNIVERSE getTime] > [self spawnTime] + kPlasmaShotActivationDelay;
67}
68
69- (BOOL)checkCloseCollisionWith:(Entity*)other
70{
71 return ([other rootShipEntity] != [self owner]) && ![other isEffect];
72}
73
74- (void)update:(double)delta_t
75{
76 [super update:delta_t];
77
78 OOTimeDelta lifeTime = [self timeElapsedSinceSpawn];
79
80#if PLASMA_ATTENUATION
81 float attenuation = OOClamp_0_1_f(1.0f - lifeTime / _duration);
82#else
83 const float attenuation = 1.0f;
84#endif
85
86 NSUInteger i, count = [collidingEntities count];
87 for (i = 0; i < count; i++) {
88 Entity* e = (Entity*)[collidingEntities objectAtIndex:i];
89 if ([e rootShipEntity] != [self owner]) {
90 // we're going to force the weapon id to be a phantom equipment key so there is something for
91 // the PlayerEntitySound to reference. it allow allows for the sound effects to be overridden by OXP.
92 [e takeEnergyDamage:[self energy] * attenuation
93 from:self
94 becauseOf:[self owner]
95 weaponIdentifier:@"EQ_WEAPON_PLASMA_SHOT"];
96 [UNIVERSE removeEntity:self];
97
98 // Spawn a plasma burst.
99 OOPlasmaBurstEntity* burst = [[OOPlasmaBurstEntity alloc] initWithPosition:[self position]];
100 [UNIVERSE addEntity:burst];
101 [burst release];
102 }
103 }
104
105#if PLASMA_ATTENUATION
106 _colorComponents[3] = attenuation;
107#endif
108
109 if (lifeTime > _duration)
110 [UNIVERSE removeEntity:self];
111}
112
113@end
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
unsigned count
#define kPlasmaShotActivationDelay
#define kPlasmaShotSize
double OOTimeDelta
Definition OOTypes.h:193
GLfloat timeElapsedSinceSpawn()
Definition Entity.m:985
NSMutableArray * collidingEntities
Definition Entity.h:144
void setVelocity:(Vector vel)
Definition Entity.m:703
void update:(OOTimeDelta delta_t)
Definition Entity.m:850
GLfloat energy
Definition Entity.m:753
OOTimeAbsolute spawnTime
Definition Entity.m:980
void setCollisionRadius:(GLfloat amount)
Definition Entity.m:840
BOOL isEffect()
Definition Entity.m:180
ShipEntity * rootShipEntity()
Definition Entity.m:566
HPVector position
Definition Entity.m:576
void setEnergy:(GLfloat amount)
Definition Entity.m:748
void takeEnergyDamage:from:becauseOf:weaponIdentifier:(double amount,[from] Entity *ent,[becauseOf] Entity *other,[weaponIdentifier] NSString *weaponIdentifier)
Definition Entity.m:899
id owner()
Definition Entity.m:548
void setPosition:(HPVector posn)
Definition Entity.m:608
void setColor:alpha:(OOColor *color,[alpha] GLfloat alpha)