Oolite
Loading...
Searching...
No Matches
OOTrumble.m
Go to the documentation of this file.
1/*
2
3OOTrumble.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25#import "OOTrumble.h"
26#import "MyOpenGLView.h"
27#import "OOMaths.h"
28#import "OOSound.h"
29#import "OOStringParsing.h"
30#import "OOTexture.h"
31#import "PlayerEntity.h"
32#import "ResourceManager.h"
33#import "Universe.h"
34
35static void InitTrumbleSounds(void);
36static void PlayTrumbleIdle(void);
37static void PlayTrumbleSqueal(void);
38
39@implementation OOTrumble
40
41- (id)init
42{
43 self = [super init];
44
45 int i;
46 for (i = 0; i < 4; i++) {
47 colorPoint1[i] = 1.0;
48 colorPoint2[i] = 1.0;
49 }
50
51 return self;
52}
53
54- (id)initForPlayer:(PlayerEntity*)p1
55{
56 self = [super init];
57
58 [self setupForPlayer:p1 digram:@"a1"];
59
60 return self;
61}
62
63- (id)initForPlayer:(PlayerEntity*)p1 digram:(NSString*)digramString
64{
65 self = [super init];
66
67 [self setupForPlayer:p1 digram:digramString];
68
69 return self;
70}
71
72- (void)setupForPlayer:(PlayerEntity*)p1 digram:(NSString*)digramString
73{
74 // set digram
75 //
76 digram[0] = [digramString characterAtIndex:0];
77 digram[1] = [digramString characterAtIndex:1];
78
79 // set player
80 //
81 player = p1;
82
83 // set color points
84 int r0 = (int)digram[0];
85 int r1 = (int)digram[1];
86 int pointscheme[6] = { 1, 1, 0, 0, 1, 1 };
87 int ps = r0 >> 2; // first digram determines pattern of points
88 pointscheme[0] = (ps >> 3) & 1;
89 pointscheme[1] = (ps >> 2) & 1;
90 pointscheme[2] = (ps >> 1) & 1;
91 pointscheme[3] = ps & 1;
92 pointscheme[4] = (ps >> 2) & 1;
93 pointscheme[5] = (ps >> 3) & 1;
94
95 GLfloat c1[4] = { 1.0, 1.0, 1.0, 1.0 };
96 GLfloat c2[4] = { 1.0, 0.0, 0.0, 1.0 };
97
98 // I am missing something. Please clarify the intent of the following statement.
99 // The next statement shift the result of adding two masked values
100 // max_size = 0.90 + 0.50 * (((r0 & 0x38) + (r1 & 0x38)) >> 3) / 63.0; // inheritable
101 // The next statement adds masked(r0) to shifted(masked(r1)
102 // max_size = 0.90 + 0.50 * ((r0 & 0x38) + ((r1 & 0x38) >> 3)) / 63.0; // inheritable
103 // Sorry, but I cannot determine what you intended to do here.
104 //
105 // GILES: It's the second one, we're just determining a pseudo random max_size from the first digram
106 max_size = 0.90 + 0.50 * ((r0 & 0x38) + ((r1 & 0x38) >> 3)) / 63.0; // inheritable
107
108 // seed the random number generator
109 //
110 ranrot_srand(r0 + r1 * 256);
111
112 // set random colors
113 int col1 = r0 & 7;
114 int col2 = r1 & 7;
115 while (((col1 == 7) || (col1 == 0)) && ((col2 == 7) || (col2 == 0))) // monochrome not allowed
116 {
117 if (col1 == col2)
118 col1 = ranrot_rand() & 7;
119 else
120 col2 = ranrot_rand() & 7;
121 }
122 c1[0] = (GLfloat)(col1 & 1);
123 c1[1] = (GLfloat)((col1 >> 1) & 1);
124 c1[2] = (GLfloat)((col1 >> 2) & 1);
125 c2[0] = (GLfloat)(col2 & 1);
126 c2[1] = (GLfloat)((col2 >> 1) & 1);
127 c2[2] = (GLfloat)((col2 >> 2) & 1);
128 if (col1 == 0) {
129 c1[0] = 0.5 + 0.1 * c2[1];
130 c1[1] = 0.5 + 0.1 * c2[2];
131 c1[2] = 0.5;
132 }
133 if (col1 == 7) {
134 c1[0] = 1.0 - 0.1 * c2[1];
135 c1[1] = 1.0 - 0.1 * c2[2];
136 c1[2] = 0.9;
137 }
138 if (col2 == 0) {
139 c2[0] = 0.5 + 0.1 * c1[2];
140 c2[1] = 0.5 + 0.1 * c1[0];
141 c2[2] = 0.5;
142 }
143 if (col2 == 7) {
144 c2[0] = 1.0 - 0.1 * c1[2];
145 c2[1] = 1.0 - 0.1 * c1[0];
146 c2[2] = 0.9;
147 }
148
149 // position and motion
150 //
151 position.x = (ranrot_rand() & 15) * 28 - 210;
152 position.y = (ranrot_rand() & 15) * 28 - 210;
153 //
154 [self randomizeMotionX];
155 [self randomizeMotionY];
156
157 // rotation
158 //
161
162 //
163 int i;
164 for (i = 0; i < 4; i++) {
165 colorPoint1[i] = c1[i];
166 colorPoint2[i] = c2[i];
167 }
168 //
169 for (i = 0; i < 6; i++) {
171 if (pointscheme[i] == 0)
173 if (pointscheme[i] == 1)
175 }
176 //
177 for (i = 0; i < 4; i++) {
178 colorEyes[i] = 0.2 * (2.0 * pointColor[3][i] + 2.0 * pointColor[1][i] + 1.0); // eyes - paler than average
179 colorBase[i] = 0.5 * (pointColor[2][i] + pointColor[3][i]); // mouth
180 }
181 //
182 size = 0.5 * (1.0 + randf());
183 [self calcGrowthRate];
184 hunger = 0.0;
185 discomfort = 0.0;
186 //
187 eye_position = NSMakePoint(0.0, 0.075 * (randf() - randf()));
189 //
190 mouth_position = NSMakePoint(0.0, 0.035 * (randf() - randf()));
192 //
195 animationTime = 0.0;
196 animationDuration = 1.5 + randf() * 3.0; // time until next animation
197 //
198 texture = [OOTexture textureWithName:@"trumblekit.png"
199 inFolder:@"Textures"
200 options:kOOTextureDefaultOptions | kOOTextureNoShrink
201 anisotropy:0.0f
202 lodBias:kOOTextureDefaultLODBias];
203 [texture retain];
204
206
207 readyToSpawn = NO;
208}
209
210- (void)dealloc
211{
212 [texture release];
213
214 [super dealloc];
215}
216
217- (void)spawnFrom:(OOTrumble*)parentTrumble
218{
219 if (parentTrumble) {
220 // mutate..
221 unichar mutation1 = ranrot_rand() & ranrot_rand() & ranrot_rand() & 0xff; // each bit has a 1/8 chance of being set
222 unichar mutation2 = ranrot_rand() & ranrot_rand() & ranrot_rand() & 0xff; // each bit has a 1/8 chance of being set
223 unichar* parentdigram = [parentTrumble digram];
224 unichar newdigram[2];
225 newdigram[0] = parentdigram[0] ^ mutation1;
226 newdigram[1] = parentdigram[1] ^ mutation2;
227 //
228 [self setupForPlayer:player digram:[NSString stringWithCharacters:newdigram length:2]];
229 //
230 size = [parentTrumble size] * 0.4;
231 if (size < 0.5)
232 size = 0.5; // minimum size
236 movement.y += 8.0; // emerge!
237 } else {
238 size = 0.5; // minimum size
239 position.x = (ranrot_rand() & 15) * 28 - 210;
240 position.y = (ranrot_rand() & 15) * 28 - 210;
241 [self randomizeMotionX];
242 [self randomizeMotionY];
245 }
246 hunger = 0.25;
247 [self calcGrowthRate];
248 discomfort = 0.0;
249 [self actionSleep];
250}
251
253{
254 float rsize = size / max_size;
255 growth_rate = TRUMBLE_GROWTH_RATE * (1.0 - rsize);
256}
257
258- (unichar*)digram
259{
260 return digram;
261}
262
263- (NSPoint)position
264{
265 return position;
266}
267
268- (NSPoint)movement
269{
270 return movement;
271}
272
273- (GLfloat)rotation
274{
275 return rotation;
276}
277
278- (GLfloat)size
279{
280 return size;
281}
282
283- (GLfloat)hunger
284{
285 return hunger;
286}
287
288- (GLfloat)discomfort
289{
290 return discomfort;
291}
292
293// AI methods here
295{
297 animationDuration = 1.5 + 3.0 * randf(); // time until next animation
298}
299
301{
303 animationDuration = 0.5 + 0.5 * randf(); // time until next animation
304}
305
307{
309 animationDuration = 4.0 + 1.0 * randf(); // time until next animation
310}
311
313{
315 animationDuration = 1.5 + 0.5 * randf(); // time until next animation
316}
317
319{
321 animationDuration = 2.25 + randf() * 1.5; // time until next animation
322}
323
325{
327 animationDuration = 1.5 + randf() * 3.0; // time until next animation
328}
329
331{
333 animationDuration = 1.5 + randf() * 3.0; // time until next animation
334}
335
337{
339 animationDuration = 12.0 + 12.0 * randf(); // time until next animation
340}
341
343{
345 animationDuration = 9.0 + 3.0 * randf(); // time until next animation
346}
347
349{
350 movement.x = 36 * (randf() - 0.5);
351 movement.x += (movement.x > 0) ? 2.0 : -2.0;
353}
354
356{
357 movement.y = 36 * (randf() - 0.5);
358 movement.y += (movement.y > 0) ? 2.0 : -2.0;
360}
361
362- (void)drawTrumble:(double)z
363{
364 /*
365 draws a trumble body as a fan of triangles...
366 2-------3-------4
367 | \ | / |
368 | \ | / |
369 | \ | / |
370 1-------0-------5
371
372 */
373 GLfloat wd = 96 * size;
374 GLfloat ht = 96 * size;
375 OOGL(glShadeModel(GL_SMOOTH));
376 OOGL(glEnable(GL_TEXTURE_2D));
377
379
382
383 [texture apply];
384
385 //
386 // Body..
387 //
388 OOGLBEGIN(GL_TRIANGLE_FAN);
389 glColor4fv(pointColor[3]);
390 glTexCoord2f(0.25, 0.5);
391 glVertex2f(0.0, -0.5 * ht);
392
393 glColor4fv(pointColor[0]);
394 glTexCoord2f(0.0, 0.5);
395 glVertex2f(-0.5 * wd, -0.5 * ht);
396
397 glColor4fv(pointColor[1]);
398 glTexCoord2f(0.0, 0.0);
399 glVertex2f(-0.5 * wd, 0.5 * ht);
400
401 glColor4fv(pointColor[2]);
402 glTexCoord2f(0.25, 0.0);
403 glVertex2f(0.0, 0.5 * ht);
404
405 glColor4fv(pointColor[4]);
406 glTexCoord2f(0.5, 0.0);
407 glVertex2f(0.5 * wd, 0.5 * ht);
408
409 glColor4fv(pointColor[5]);
410 glTexCoord2f(0.5, 0.5);
411 glVertex2f(0.5 * wd, -0.5 * ht);
412 OOGLEND();
413
414 //
415 // Eyes
416 //
417 GLfloat eyeTextureOffset = 0.0;
418 switch (eyeFrame) {
421 eyeTextureOffset = 0.0;
422 break;
424 eyeTextureOffset = 0.25;
425 break;
427 eyeTextureOffset = 0.5;
428 break;
429 }
430
432
433 OOGL(glColor4fv(colorEyes));
434 OOGLBEGIN(GL_QUADS);
435 glTexCoord2f(0.5, eyeTextureOffset);
436 glVertex2f(-0.5 * wd, 0.20 * ht);
437
438 glTexCoord2f(1.0, eyeTextureOffset);
439 glVertex2f(0.5 * wd, 0.20 * ht);
440
441 glTexCoord2f(1.0, eyeTextureOffset + 0.25);
442 glVertex2f(0.5 * wd, -0.30 * ht);
443
444 glTexCoord2f(0.5, eyeTextureOffset + 0.25);
445 glVertex2f(-0.5 * wd, -0.30 * ht);
446 OOGLEND();
447
448 //
449 // Mouth
450 //
451 GLfloat mouthTextureOffset = 0.0;
452 switch (mouthFrame) {
454 mouthTextureOffset = 0.500;
455 break;
458 mouthTextureOffset = 0.625;
459 break;
461 mouthTextureOffset = 0.750;
462 break;
464 mouthTextureOffset = 0.875;
465 break;
466 }
467
469
470 OOGL(glColor4fv(colorBase));
471 OOGLBEGIN(GL_QUADS);
472 glTexCoord2f(0.0, mouthTextureOffset);
473 glVertex2f(-0.25 * wd, -0.10 * ht);
474
475 glTexCoord2f(0.25, mouthTextureOffset);
476 glVertex2f(0.25 * wd, -0.10 * ht);
477
478 glTexCoord2f(0.25, mouthTextureOffset + 0.125);
479 glVertex2f(0.25 * wd, -0.35 * ht);
480
481 glTexCoord2f(0.0, mouthTextureOffset + 0.125);
482 glVertex2f(-0.25 * wd, -0.35 * ht);
483 OOGLEND();
484
485 // finally..
487 OOGL(glDisable(GL_TEXTURE_2D));
488}
489
490- (void)updateTrumble:(double)delta_t
491{
492 // player movement
493 NSPoint p_mov = NSMakePoint(TRUMBLE_MAX_ROTATIONAL_VELOCITY * [player dialPitch], TRUMBLE_MAX_ROTATIONAL_VELOCITY * [player dialRoll]);
494 switch ([UNIVERSE viewDirection]) {
495 GLfloat t;
496 case VIEW_AFT:
497 p_mov.x = -p_mov.x;
498 p_mov.y = -p_mov.y;
499 break;
500 case VIEW_STARBOARD:
501 t = p_mov.x;
502 p_mov.x = -p_mov.y;
503 p_mov.y = t;
504 break;
505 case VIEW_PORT:
506 t = p_mov.x;
507 p_mov.x = p_mov.y;
508 p_mov.y = -t;
509 break;
510
511 default:
512 break;
513 }
514 p_mov.x *= -4.0;
515
516 // movement
517 //
518 GLfloat wd = 0.5 * 96 * size;
519 GLfloat ht = 0.5 * 96 * size;
520 //
521 GLfloat bumpx = 320 * 1.5 - wd;
522 GLfloat bumpy = 240 * 1.5 - ht;
523 //
524 position.x += delta_t * movement.x;
525 if ((position.x < -bumpx) || (position.x > bumpx)) {
526 position.x = (position.x < -bumpx) ? -bumpx : bumpx;
527 [self randomizeMotionX];
528 }
529 position.y += delta_t * (movement.y + p_mov.x);
530 if ((position.y < -bumpy) || (position.y > bumpy)) {
531 position.y = (position.y < -bumpy) ? -bumpy : bumpy;
532 [self randomizeMotionY];
533 }
534
535 // rotation
536 //
537 rotation += delta_t * (rotational_velocity + p_mov.y);
542 }
546 }
547 }
548 // growth
549 //
550 size += delta_t * growth_rate;
551 hunger += delta_t * (growth_rate + TRUMBLE_GROWTH_RATE);
552 if (size > max_size) // fully_grown.. stop growing
553 {
554 size = max_size;
555 growth_rate = 0.0;
556 }
557 [self calcGrowthRate];
558 if (hunger > 0.75)
559 growth_rate = 0.0;
560 if (hunger > 1.0)
561 hunger = 1.0; // clamp
562
563 // feelings
564 //
565 GLfloat temp = [player hullHeatLevel];
566 discomfort += delta_t * hunger * 0.02 * (1.0 - hunger);
567 if (temp > 0.33)
568 discomfort += delta_t * (temp - 0.33) * (temp - 0.33) * 0.05;
569 if (discomfort > 1.0)
570 discomfort = 1.0; // clamp
571
572 // feeding & reproducing
573 //
574 // am I really hungry?
575 if (hunger > 0.50) {
576 // consult menu...
577 ShipEntity* selectedCargopod = nil;
578 float mostYummy = 0.0;
579 NSMutableArray* cargopods = [player cargo]; // the cargo pods
580 NSUInteger i, n_pods = [cargopods count];
581 for (i = 0; i < n_pods; i++) {
582 ShipEntity* cargopod = [cargopods objectAtIndex:i];
584 float yumminess = (1.0 + randf()) * [[UNIVERSE commodityMarket] trumbleOpinionForGood:cargo_type];
585 if (yumminess > mostYummy) {
586 selectedCargopod = cargopod;
587 mostYummy = yumminess;
588 }
589 }
590 if (selectedCargopod) {
591 // feed
592 float trumbleAppetiteAccumulator = [player trumbleAppetiteAccumulator];
593
594 trumbleAppetiteAccumulator += hunger;
595 hunger = 0.0;
596 discomfort -= mostYummy * 0.5;
597 if (discomfort < 0.0)
598 discomfort = 0.0;
599 if (trumbleAppetiteAccumulator > 10.0) {
600 // eaten all of this cargo!
601 NSString* ms = [NSString stringWithFormat:DESC(@"trumbles-eat-@"),
602 [UNIVERSE displayNameForCommodity:[selectedCargopod commodityType]]];
603
604 [UNIVERSE addMessage:ms forCount:4.5];
605 [cargopods removeObject:selectedCargopod];
606 trumbleAppetiteAccumulator -= 10.0;
607
608 // consider breeding - must be full grown and happy
609 if ((size > 0.95) && (discomfort < 0.25)) {
610 readyToSpawn = YES;
611 }
612
613 [player setTrumbleAppetiteAccumulator:trumbleAppetiteAccumulator];
614 }
615 }
616 }
617
618 // animations
619 //
620 switch (animation) {
622 [self updateSnarl:delta_t];
623 break;
625 [self updateShudder:delta_t];
626 break;
628 [self updateStoned:delta_t];
629 break;
630 case TRUMBLE_ANIM_DIE:
631 [self updatePop:delta_t];
632 break;
634 [self updateBlink:delta_t];
635 break;
637 [self updateProot:delta_t];
638 break;
640 [self updateSleep:delta_t];
641 break;
643 [self updateSpawn:delta_t];
644 break;
646 default:
647 [self updateIdle:delta_t];
648 break;
649 }
650}
651
652- (void)updateIdle:(double)delta_t
653{
654 animationTime += delta_t;
656 // blink or proot or idle and/or change direction
657 [self actionIdle];
658 if (randf() < 0.25)
659 [self actionBlink];
660 if (randf() < 0.10)
661 [self randomizeMotionX];
662 if (randf() < 0.10)
663 [self randomizeMotionY];
664 if (randf() < 0.05)
665 [self actionProot];
666 if (randf() < 0.01)
667 [self actionSleep];
668 if (randf() < 0.01)
669 [self actionSnarl];
670 //
671 if (readyToSpawn) {
672 [self actionSpawn];
673 readyToSpawn = NO;
674 }
675 //
676 if (discomfort > 0.5 + randf()) {
677 [self actionShudder];
678 }
679 //
680 if (discomfort > 0.96) {
681 [self actionPop];
682 }
683 //
685 animationTime = 0.0;
686 }
687}
688
689- (void)updateBlink:(double)delta_t
690{
692 animationTime += delta_t;
694 // blink or proot or idle
695 [self actionIdle];
696 if (randf() < 0.05)
697 [self actionBlink];
698 if (randf() < 0.1)
699 [self actionProot];
701 animationTime = 0.0;
703 }
704}
705
706- (void)updateSnarl:(double)delta_t
707{
708 int pc = 100 * animationTime / animationDuration;
709 if (pc < 25) {
712 }
713 if ((pc >= 25) && (pc < 90)) {
714 double vibr = (pc & 1) ? -1.0 : 1.0;
715 if (digram[1] & 4)
716 position.x += size * vibr * 0.5;
717 else
718 position.y += size * vibr * 0.5;
720 if (pc & 2)
722 else
724 }
725 if ((pc >= 90) && (pc < 100)) {
728 }
729 animationTime += delta_t;
731 // blink or idle
732 [self actionIdle];
733 if (randf() < 0.1)
734 [self actionBlink];
736 animationTime = 0.0;
739 }
740}
741
742- (void)updateProot:(double)delta_t
743{
744 if (!animationTime) {
745 animationStage = 0;
746 }
747 int pc = 100 * animationTime / animationDuration;
748 if (pc < 10) {
751 }
752 if (pc >= 10) {
753 double vibr = (pc & 2) ? -1.0 : 1.0;
754 position.x += size * vibr * 0.25;
757 if (!animationStage) {
758 animationStage = 1;
760 }
761 }
762 animationTime += delta_t;
764 // blink or idle
765 [self actionIdle];
766 if (randf() < 0.1)
767 [self actionBlink];
769 animationTime = 0.0;
772 }
773}
774
775- (void)updateShudder:(double)delta_t
776{
777 if (!animationTime) {
781 }
782 int pc = 100 * animationTime / animationDuration;
783 if (pc < 10) {
786 }
787 if (pc >= 10) {
788 double vibr = (pc & 2) ? -0.25 : 0.25;
789 position.x += size * vibr;
792 }
793 animationTime += delta_t;
795 // feel better
796 discomfort *= 0.9;
797 // blink or idle
798 [self actionIdle];
799 if (randf() < 0.1)
800 [self actionBlink];
802 animationTime = 0.0;
805 }
806}
807
808- (void)updateStoned:(double)delta_t
809{
810}
811
812- (void)updatePop:(double)delta_t
813{
814 if (!animationTime) {
817 movement.y = (ranrot_rand() & 7);
818 if (randf() < 0.5)
819 rotational_velocity = 63 + (ranrot_rand() & 127);
820 else
821 rotational_velocity = -63 - (ranrot_rand() & 127);
822 // squeal here!
824 }
825 float pc = animationTime / animationDuration;
826
827 // fading alpha
828 colorPoint1[1] *= (1.0 - delta_t);
829 colorPoint2[1] *= (1.0 - delta_t);
830 colorPoint1[2] *= (1.0 - delta_t);
831 colorPoint2[2] *= (1.0 - delta_t);
832 colorPoint1[3] = (1.0 - pc);
833 colorPoint2[3] = (1.0 - pc);
834 colorBase[3] = (1.0 - pc);
835
836 // falling
837 movement.y -= delta_t * 98.0;
838 rotational_velocity *= (1.0 + delta_t);
839
840 // shrinking
841 size -= delta_t * (1.0 - pc) * size;
842
843 animationTime += delta_t;
845 // kaputnik!
846 [player removeTrumble:self];
847 }
848}
849
850- (void)updateSleep:(double)delta_t
851{
852 if (!animationTime) {
855 }
857 int pc = 512 * animationTime / animationDuration;
858 if (pc & 16) {
859 double vibr = (pc & 2) ? -0.0025 : 0.0025;
860 eye_position.y += size * vibr;
861 mouth_position.y += size * vibr * -0.5;
862 } else {
865 }
866 animationTime += delta_t;
868 // idle or proot
871 [self actionIdle];
872 if (randf() < 0.25)
873 [self actionProot];
875 animationTime = 0.0;
877 }
878}
879
880- (void)updateSpawn:(double)delta_t
881{
882 movement.x *= (1.0 - delta_t);
883 movement.y *= (1.0 - delta_t);
884 rotation *= (1.0 - delta_t);
885 rotational_velocity *= (1.0 - delta_t);
888 int pc = 256 * animationTime / animationDuration;
889 double vibr = (pc & 2) ? -0.002 * pc : 0.002 * pc;
890 position.x += size * vibr;
891 animationTime += delta_t;
893 // proot
896 [self actionProot];
898 animationTime = 0.0;
901 [self randomizeMotionX];
902 [player addTrumble:self];
903 }
904}
905
906- (NSDictionary*)dictionary
907{
908 return [NSDictionary dictionaryWithObjectsAndKeys:
909 [NSString stringWithCharacters:digram
910 length:2],
911 @"digram",
912 [NSNumber numberWithFloat:hunger], @"hunger",
913 [NSNumber numberWithFloat:discomfort], @"discomfort",
914 [NSNumber numberWithFloat:size], @"size",
915 [NSNumber numberWithFloat:growth_rate], @"growth_rate",
916 [NSNumber numberWithFloat:rotation], @"rotation",
917 [NSNumber numberWithFloat:rotational_velocity], @"rotational_velocity",
918 StringFromPoint(position), @"position",
919 StringFromPoint(movement), @"movement",
920 nil];
921}
922
923- (void)setFromDictionary:(NSDictionary*)dict
924{
925 NSString* digramString = (NSString*)[dict objectForKey:@"digram"];
926 [self setupForPlayer:player digram:digramString];
927 hunger = [[dict objectForKey:@"hunger"] floatValue];
928 discomfort = [[dict objectForKey:@"discomfort"] floatValue];
929 size = [[dict objectForKey:@"size"] floatValue];
930 growth_rate = [[dict objectForKey:@"growth_rate"] floatValue];
931 rotation = [[dict objectForKey:@"rotation"] floatValue];
932 rotational_velocity = [[dict objectForKey:@"rotational_velocity"] floatValue];
933 position = PointFromString([dict objectForKey:@"position"]);
934 movement = PointFromString([dict objectForKey:@"movement"]);
935}
936
937@end
938
942
943static void InitTrumbleSounds(void)
944{
945 if (sTrumbleSoundSource == nil) {
946 sTrumbleSoundSource = [[OOSoundSource alloc] init];
947 sTrumbleIdleSound = [[OOSound alloc] initWithCustomSoundKey:@"[trumble-idle]"];
948 sTrumbleSqealSound = [[OOSound alloc] initWithCustomSoundKey:@"[trumble-squeal]"];
949 }
950}
951
952static void PlayTrumbleIdle(void)
953{
954 // Only play idle sound if no trumble is making noise.
955 if (![sTrumbleSoundSource isPlaying]) {
956 // trumble sound from random direction - where's it gone now?
957 [sTrumbleSoundSource setPosition:OORandomUnitVector()];
958 [sTrumbleSoundSource playSound:sTrumbleIdleSound];
959 }
960}
961
962static void PlayTrumbleSqueal(void)
963{
964 // Play squeal sound if no trumble is currently squealing, but trumping idle sound.
965 if (![sTrumbleSoundSource isPlaying] || [sTrumbleSoundSource sound] == sTrumbleIdleSound) {
966 // trumble sound from random direction - where's it gone now?
967 [sTrumbleSoundSource setPosition:OORandomUnitVector()];
968 [sTrumbleSoundSource playSound:sTrumbleSqealSound];
969 }
970}
OOINLINE OOMatrix OOMatrixForRotationZ(OOScalar angle) INLINE_CONST_FUNC
Definition OOMatrix.h:219
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
void OOGLMultModelView(OOMatrix matrix)
OOMatrix OOGLPopModelView(void)
#define OOGLBEGIN
Definition OOOpenGL.h:269
#define OOGL(statement)
Definition OOOpenGL.h:262
#define OOGLEND
Definition OOOpenGL.h:270
return nil
NSPoint PointFromString(NSString *xyString)
#define TRUMBLE_MAX_ROTATION
Definition OOTrumble.h:32
@ TRUMBLE_MOUTH_NONE
Definition OOTrumble.h:58
@ TRUMBLE_MOUTH_GROWL
Definition OOTrumble.h:60
@ TRUMBLE_MOUTH_NORMAL
Definition OOTrumble.h:62
@ TRUMBLE_MOUTH_POUT
Definition OOTrumble.h:59
@ TRUMBLE_MOUTH_SNARL
Definition OOTrumble.h:61
#define TRUMBLE_GROWTH_RATE
Definition OOTrumble.h:35
@ TRUMBLE_ANIM_SLEEP
Definition OOTrumble.h:46
@ TRUMBLE_ANIM_IDLE
Definition OOTrumble.h:39
@ TRUMBLE_ANIM_SHUDDER
Definition OOTrumble.h:43
@ TRUMBLE_ANIM_PROOT
Definition OOTrumble.h:42
@ TRUMBLE_ANIM_STONED
Definition OOTrumble.h:44
@ TRUMBLE_ANIM_SNARL
Definition OOTrumble.h:41
@ TRUMBLE_ANIM_DIE
Definition OOTrumble.h:47
@ TRUMBLE_ANIM_BLINK
Definition OOTrumble.h:40
@ TRUMBLE_ANIM_SPAWN
Definition OOTrumble.h:45
#define TRUMBLE_MAX_ROTATIONAL_VELOCITY
Definition OOTrumble.h:33
@ TRUMBLE_EYES_OPEN
Definition OOTrumble.h:52
@ TRUMBLE_EYES_NONE
Definition OOTrumble.h:51
@ TRUMBLE_EYES_WIDE
Definition OOTrumble.h:54
@ TRUMBLE_EYES_SHUT
Definition OOTrumble.h:53
static OOSound * sTrumbleIdleSound
Definition OOTrumble.m:940
static void PlayTrumbleSqueal(void)
Definition OOTrumble.m:962
static OOSoundSource * sTrumbleSoundSource
Definition OOTrumble.m:939
static OOSound * sTrumbleSqealSound
Definition OOTrumble.m:941
static void InitTrumbleSounds(void)
Definition OOTrumble.m:943
static void PlayTrumbleIdle(void)
Definition OOTrumble.m:952
NSString * OOCommodityType
Definition OOTypes.h:97
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
#define UNIVERSE
Definition Universe.h:827
void playSound:(OOSound *inSound)
void setPosition:(Vector inPosition)
void apply()
Definition OOTexture.m:258
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
Definition OOTexture.m:132
void actionStoned()
Definition OOTrumble.m:324
void actionIdle()
Definition OOTrumble.m:294
void randomizeMotionX()
Definition OOTrumble.m:348
NSDictionary * dictionary()
Definition OOTrumble.m:906
void updateBlink:(double delta_t)
Definition OOTrumble.m:689
NSPoint mouth_position
Definition OOTrumble.h:91
void actionSnarl()
Definition OOTrumble.m:306
enum trumble_animation animation
Definition OOTrumble.h:96
void setupForPlayer:digram:(PlayerEntity *p1,[digram] NSString *digramString)
Definition OOTrumble.m:72
GLfloat discomfort
Definition OOTrumble.m:288
NSPoint position
Definition OOTrumble.m:263
GLfloat rotation
Definition OOTrumble.m:273
void actionSleep()
Definition OOTrumble.m:336
GLfloat colorBase[4]
Definition OOTrumble.h:71
GLfloat size
Definition OOTrumble.m:278
void updateShudder:(double delta_t)
Definition OOTrumble.m:775
GLfloat colorPoint1[4]
Definition OOTrumble.h:72
void randomizeMotionY()
Definition OOTrumble.m:355
enum trumble_eyes eyeFrame
Definition OOTrumble.h:102
int animationStage
Definition OOTrumble.h:99
NSPoint movement
Definition OOTrumble.m:268
void actionProot()
Definition OOTrumble.m:312
GLfloat colorEyes[4]
Definition OOTrumble.h:74
GLfloat colorPoint2[4]
Definition OOTrumble.h:73
OOTexture * texture
Definition OOTrumble.h:104
GLfloat rotational_velocity
Definition OOTrumble.h:85
BOOL readyToSpawn
Definition OOTrumble.h:108
GLfloat saved_float2
Definition OOTrumble.h:106
GLfloat max_size
Definition OOTrumble.h:81
void actionBlink()
Definition OOTrumble.m:300
void updateIdle:(double delta_t)
Definition OOTrumble.m:652
enum trumble_mouth mouthFrame
Definition OOTrumble.h:101
void updateProot:(double delta_t)
Definition OOTrumble.m:742
void actionSpawn()
Definition OOTrumble.m:342
GLfloat * pointColor[6]
Definition OOTrumble.h:75
GLfloat growth_rate
Definition OOTrumble.h:82
void calcGrowthRate()
Definition OOTrumble.m:252
double animationDuration
Definition OOTrumble.h:94
void updateSleep:(double delta_t)
Definition OOTrumble.m:850
void updateSpawn:(double delta_t)
Definition OOTrumble.m:880
GLfloat saved_float1
Definition OOTrumble.h:106
PlayerEntity * player
Definition OOTrumble.h:67
GLfloat hunger
Definition OOTrumble.m:283
void updateSnarl:(double delta_t)
Definition OOTrumble.m:706
unichar digram[2]
Definition OOTrumble.m:258
enum trumble_animation nextAnimation
Definition OOTrumble.h:97
void actionShudder()
Definition OOTrumble.m:318
double animationTime
Definition OOTrumble.h:93
void dealloc()
Definition OOTrumble.m:210
void updatePop:(double delta_t)
Definition OOTrumble.m:812
void actionPop()
Definition OOTrumble.m:330
NSPoint eye_position
Definition OOTrumble.h:90
void updateStoned:(double delta_t)
Definition OOTrumble.m:808
void removeTrumble:(OOTrumble *deadTrumble)
void addTrumble:(OOTrumble *papaTrumble)
float trumbleAppetiteAccumulator()
void setTrumbleAppetiteAccumulator:(float value)
NSMutableArray * cargo
OOCommodityType commodityType()
GLfloat hullHeatLevel()
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
float randf(void)
void ranrot_srand(uint32_t seed)
#define ranrot_rand()