Oolite
Loading...
Searching...
No Matches
OOPlasmaShotEntity.m
Go to the documentation of this file.
1
/*
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 "
OOColor.h
"
28
#import "
OOPlasmaBurstEntity.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
64
- (BOOL)
canCollide
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
OOColor.h
OOClamp_0_1_f
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
Definition
OOFastArithmetic.h:65
count
unsigned count
Definition
OOParticleSystem.m:253
OOPlasmaBurstEntity.h
OOPlasmaShotEntity.h
kPlasmaShotActivationDelay
#define kPlasmaShotActivationDelay
Definition
OOPlasmaShotEntity.m:33
kPlasmaShotSize
#define kPlasmaShotSize
Definition
OOPlasmaShotEntity.m:32
OOTimeDelta
double OOTimeDelta
Definition
OOTypes.h:193
PlayerEntity.h
Universe.h
Entity
Definition
Entity.h:75
-[Entity timeElapsedSinceSpawn]
GLfloat timeElapsedSinceSpawn()
Definition
Entity.m:985
Entity::collidingEntities
NSMutableArray * collidingEntities
Definition
Entity.h:144
-[Entity setVelocity:]
void setVelocity:(Vector vel)
Definition
Entity.m:703
-[Entity update:]
void update:(OOTimeDelta delta_t)
Definition
Entity.m:850
Entity::energy
GLfloat energy
Definition
Entity.m:753
Entity::spawnTime
OOTimeAbsolute spawnTime
Definition
Entity.m:980
-[Entity setCollisionRadius:]
void setCollisionRadius:(GLfloat amount)
Definition
Entity.m:840
-[Entity isEffect]
BOOL isEffect()
Definition
Entity.m:180
-[Entity rootShipEntity]
ShipEntity * rootShipEntity()
Definition
Entity.m:566
Entity::position
HPVector position
Definition
Entity.m:576
-[Entity setEnergy:]
void setEnergy:(GLfloat amount)
Definition
Entity.m:748
-[Entity takeEnergyDamage:from:becauseOf:weaponIdentifier:]
void takeEnergyDamage:from:becauseOf:weaponIdentifier:(double amount,[from] Entity *ent,[becauseOf] Entity *other,[weaponIdentifier] NSString *weaponIdentifier)
Definition
Entity.m:899
-[Entity owner]
id owner()
Definition
Entity.m:548
-[Entity setPosition:]
void setPosition:(HPVector posn)
Definition
Entity.m:608
OOColor
Definition
OOColor.h:41
-[OOLightParticleEntity setColor:alpha:]
void setColor:alpha:(OOColor *color,[alpha] GLfloat alpha)
Definition
OOLightParticleEntity.m:84
OOLightParticleEntity::_colorComponents
GLfloat _colorComponents[4]
Definition
OOLightParticleEntity.h:34
OOPlasmaBurstEntity
Definition
OOPlasmaBurstEntity.h:29
OOPlasmaShotEntity
Definition
OOPlasmaShotEntity.h:28
OOPlasmaShotEntity::_duration
OOTimeDelta _duration
Definition
OOPlasmaShotEntity.h:30
-[OOPlasmaShotEntity canCollide]
BOOL canCollide()
Definition
OOPlasmaShotEntity.m:64
HPVector
Definition
OOHPVector.h:35
Vector
Definition
OOVector.h:31
src
Core
Entities
OOPlasmaShotEntity.m
Generated by
1.15.0