Oolite
Loading...
Searching...
No Matches
OOQuiriumCascadeEntity.m
Go to the documentation of this file.
1/*
2
3OOQuiriumCascadeEntity.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 "OOMacroOpenGL.h"
28#import "PlayerEntity.h"
29#import "Universe.h"
30
31#define kQuiriumCascadeDuration (20.0) // seconds
32#define kQuiriumCollisionDelay (0.05) // seconds before we start colliding with and damaging things.
33
34@implementation OOQuiriumCascadeEntity
35
36- (id)initQuiriumCascadeFromShip:(ShipEntity*)ship
37{
38 if (ship == nil) {
39 [self release];
40 return nil;
41 }
42
43 if ((self = [super init])) {
44 [self setPosition:[ship position]];
45
46 [self setStatus:STATUS_EFFECT];
47 scanClass = CLASS_MINE;
48
49 [self setOwner:[ship owner]];
50
51 // Red and green channels are animated.
52 _color[2] = 1.0f;
53 _color[3] = 0.5f;
54 }
55
56 return self;
57}
58
59+ (instancetype)quiriumCascadeFromShip:(ShipEntity*)ship
60{
61 return [[[self alloc] initQuiriumCascadeFromShip:ship] autorelease];
62}
63
65{
66 return [NSString stringWithFormat:@"%f seconds passed of %f", _timePassed, kQuiriumCascadeDuration];
67}
68
69- (void)update:(OOTimeDelta)delta_t
70{
71 [super update:delta_t];
72 _timePassed += delta_t;
73
75
77 GLfloat stf = tf * tf;
78 GLfloat expansionSpeed = 0.0;
79 if (_timePassed > 0) // Avoid divide by 0
80 {
81 expansionSpeed = fmin(240.0f + 10.0f / (tf * tf), 1000.0f);
82 }
83
84 collision_radius += delta_t * expansionSpeed; // expand
85 energy = delta_t * (100000 - 90000 * tf); // adjusted to take into account delta_t
86
87 _color[3] = OOClamp_0_1_f(0.5f * ((0.025f / tf) + 1.0f - stf));
88
89 _color[0] = _color[1] = fmin(1.0f - 5.0f * tf, 1.0f);
90 if (_color[0] < 0.0f) {
91 _color[0] = 0.25f * tf * randf();
92 _color[1] = 0.0f;
93 }
94
95 // manage collisions
96 Entity* owner = [self owner];
97 Entity* e = nil;
98 foreach (e, collidingEntities) {
99 // we're going to force the weapon id to be the qbomb key here, because at this point the cascade entity isn't a ship any more
100 // and there's no link back to the original.
101 [e takeEnergyDamage:energy from:self becauseOf:owner weaponIdentifier:@"EQ_QC_MINE"];
102 }
103
104 // expire after ttl
106 [UNIVERSE removeEntity:self];
107 }
108}
109
110- (void)drawImmediate:(bool)immediate translucent:(bool)translucent
111{
112 if (!translucent || [UNIVERSE breakPatternHide])
113 return;
114
117
118 OOGL(glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT));
119
120 OOGL(glDisable(GL_CULL_FACE));
121 OOGL(glDisable(GL_TEXTURE_2D));
122 OOGL(glEnable(GL_BLEND));
123 OOGL(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
124
125 OOGL(glColor4fv(_color));
126 OOGLBEGIN(GL_TRIANGLE_FAN);
128 OOGLEND();
129
130 OOGL(glPopAttrib());
131
133 OOCheckOpenGLErrors(@"OOQuiriumCascadeEntity after drawing %@", self);
134}
135
136- (BOOL)isEffect
137{
138 return YES;
139}
140
142{
143 return YES;
144}
145
147{
149}
150
151- (BOOL)checkCloseCollisionWith:(Entity*)other
152{
153 return YES;
154}
155
156@end
157
158@implementation Entity (OOQuiriumCascadeExtensions)
159
161{
162 return NO;
163}
164
165@end
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#define OO_ENTER_OPENGL()
OOMatrix OOMatrixForBillboard(HPVector bbPos, HPVector eyePos) CONST_FUNC
Definition OOMatrix.m:186
#define OOGLBEGIN
Definition OOOpenGL.h:269
@ OPENGL_STATE_ADDITIVE_BLENDING
Definition OOOpenGL.h:123
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
void GLDrawBallBillboard(GLfloat radius, GLfloat step, GLfloat z_distance)
Definition OOOpenGL.m:107
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
#define OOGLEND
Definition OOOpenGL.h:270
return nil
#define kQuiriumCascadeDuration
#define kQuiriumCollisionDelay
double OOTimeDelta
Definition OOTypes.h:193
#define PLAYER
#define UNIVERSE
Definition Universe.h:827
GLfloat collision_radius
Definition Entity.h:107
NSMutableArray * collidingEntities
Definition Entity.h:144
void update:(OOTimeDelta delta_t)
Definition Entity.m:850
GLfloat energy
Definition Entity.m:753
OOScanClass scanClass
Definition Entity.m:743
void setOwner:(Entity *ent)
Definition Entity.m:542
GLfloat cam_zero_distance
Definition Entity.h:105
HPVector position
Definition Entity.m:576
void takeEnergyDamage:from:becauseOf:weaponIdentifier:(double amount,[from] Entity *ent,[becauseOf] Entity *other,[weaponIdentifier] NSString *weaponIdentifier)
Definition Entity.m:899
OOMatrix rotMatrix
Definition Entity.h:134
id init()
Definition Entity.m:64
void setStatus:(OOEntityStatus stat)
Definition Entity.m:728
id owner()
Definition Entity.m:548
void setPosition:(HPVector posn)
Definition Entity.m:608
float randf(void)