33#import "MyOpenGLView.h"
48 for (i = 0; i < 4; i++)
61 [
self setupForPlayer: p1 digram: @"a1"];
66- (id) initForPlayer:(
PlayerEntity*) p1 digram:(NSString*) digramString
70 [
self setupForPlayer: p1 digram: digramString];
75- (void) setupForPlayer:(
PlayerEntity*) p1 digram:(NSString*) digramString
79 digram[0] = [digramString characterAtIndex:0];
80 digram[1] = [digramString characterAtIndex:1];
89 int pointscheme[6] = { 1, 1, 0, 0, 1, 1};
91 pointscheme[0] = (ps >> 3) & 1;
92 pointscheme[1] = (ps >> 2) & 1;
93 pointscheme[2] = (ps >> 1) & 1;
94 pointscheme[3] = ps & 1;
95 pointscheme[4] = (ps >> 2) & 1;
96 pointscheme[5] = (ps >> 3) & 1;
98 GLfloat c1[4] = { 1.0, 1.0, 1.0, 1.0};
99 GLfloat c2[4] = { 1.0, 0.0, 0.0, 1.0};
109 max_size = 0.90 + 0.50 * ((r0 & 0x38) + ((r1 & 0x38) >> 3)) / 63.0;
118 while (((col1 == 7)||(col1 == 0)) && ((col2 == 7)||(col2 == 0)))
125 c1[0] = (GLfloat)(col1 & 1);
126 c1[1] = (GLfloat)((col1 >> 1) & 1);
127 c1[2] = (GLfloat)((col1 >> 2) & 1);
128 c2[0] = (GLfloat)(col2 & 1);
129 c2[1] = (GLfloat)((col2 >> 1) & 1);
130 c2[2] = (GLfloat)((col2 >> 2) & 1);
133 c1[0] = 0.5 + 0.1 * c2[1]; c1[1] = 0.5 + 0.1 * c2[2]; c1[2] = 0.5;
137 c1[0] = 1.0 - 0.1 * c2[1]; c1[1] = 1.0 - 0.1 * c2[2]; c1[2] = 0.9;
141 c2[0] = 0.5 + 0.1 * c1[2]; c2[1] = 0.5 + 0.1 * c1[0]; c2[2] = 0.5;
145 c2[0] = 1.0 - 0.1 * c1[2]; c2[1] = 1.0 - 0.1 * c1[0]; c2[2] = 0.9;
153 [
self randomizeMotionX];
154 [
self randomizeMotionY];
163 for (i = 0; i < 4; i++)
169 for (i = 0; i < 6; i++)
172 if (pointscheme[i] == 0)
174 if (pointscheme[i] == 1)
178 for (i = 0; i < 4; i++)
185 [
self calcGrowthRate];
202 options:kOOTextureDefaultOptions | kOOTextureNoShrink
204 lodBias:kOOTextureDefaultLODBias];
219- (void) spawnFrom:(
OOTrumble*) parentTrumble
226 unichar* parentdigram = [parentTrumble
digram];
227 unichar newdigram[2];
228 newdigram[0] = parentdigram[0] ^ mutation1;
229 newdigram[1] = parentdigram[1] ^ mutation2;
231 [
self setupForPlayer: player digram: [NSString stringWithCharacters:newdigram length:2]];
246 [
self randomizeMotionX];
247 [
self randomizeMotionY];
252 [
self calcGrowthRate];
371- (void) drawTrumble:(
double) z
382 GLfloat wd = 96 *
size;
383 GLfloat ht = 96 *
size;
384 OOGL(glShadeModel(GL_SMOOTH));
385 OOGL(glEnable(GL_TEXTURE_2D));
399 glTexCoord2f( 0.25, 0.5);
400 glVertex2f( 0.0, -0.5 * ht);
403 glTexCoord2f( 0.0, 0.5);
404 glVertex2f( -0.5 * wd, -0.5 * ht);
407 glTexCoord2f( 0.0, 0.0);
408 glVertex2f( -0.5 * wd, 0.5 * ht);
411 glTexCoord2f( 0.25, 0.0);
412 glVertex2f( 0.0, 0.5 * ht);
415 glTexCoord2f( 0.5, 0.0);
416 glVertex2f( 0.5 * wd, 0.5 * ht);
419 glTexCoord2f( 0.5, 0.5);
420 glVertex2f( 0.5 * wd, -0.5 * ht);
426 GLfloat eyeTextureOffset = 0.0;
431 eyeTextureOffset = 0.0;
break;
433 eyeTextureOffset = 0.25;
break;
435 eyeTextureOffset = 0.5;
break;
442 glTexCoord2f( 0.5, eyeTextureOffset);
443 glVertex2f( -0.5 * wd, 0.20 * ht);
445 glTexCoord2f( 1.0, eyeTextureOffset);
446 glVertex2f( 0.5 * wd, 0.20 * ht);
448 glTexCoord2f( 1.0, eyeTextureOffset + 0.25);
449 glVertex2f( 0.5 * wd, -0.30 * ht);
451 glTexCoord2f( 0.5, eyeTextureOffset + 0.25);
452 glVertex2f( -0.5 * wd, -0.30 * ht);
458 GLfloat mouthTextureOffset = 0.0;
462 mouthTextureOffset = 0.500;
break;
465 mouthTextureOffset = 0.625;
break;
467 mouthTextureOffset = 0.750;
break;
469 mouthTextureOffset = 0.875;
break;
476 glTexCoord2f( 0.0, mouthTextureOffset);
477 glVertex2f( -0.25 * wd, -0.10 * ht);
479 glTexCoord2f( 0.25, mouthTextureOffset);
480 glVertex2f( 0.25 * wd, -0.10 * ht);
482 glTexCoord2f( 0.25, mouthTextureOffset + 0.125);
483 glVertex2f( 0.25 * wd, -0.35 * ht);
485 glTexCoord2f( 0.0, mouthTextureOffset + 0.125);
486 glVertex2f( -0.25 * wd, -0.35 * ht);
491 OOGL(glDisable(GL_TEXTURE_2D));
494- (void) updateTrumble:(
double) delta_t
523 GLfloat wd = 0.5 * 96 *
size;
524 GLfloat ht = 0.5 * 96 *
size;
526 GLfloat bumpx = 320 * 1.5 - wd;
527 GLfloat bumpy = 240 * 1.5 - ht;
533 [
self randomizeMotionX];
538 position.y = (position.y < -bumpy)? -bumpy : bumpy;
539 [self randomizeMotionY];
567 [
self calcGrowthRate];
575 GLfloat temp = [player hullHeatLevel];
578 discomfort += delta_t * (temp - 0.33) * (temp - 0.33) * 0.05;
589 float mostYummy = 0.0;
590 NSMutableArray *cargopods = [player cargo];
591 NSUInteger i, n_pods = [cargopods count];
592 for (i = 0 ; i < n_pods; i++)
594 ShipEntity *cargopod = [cargopods objectAtIndex:i];
596 float yumminess = (1.0 +
randf()) * [[
UNIVERSE commodityMarket] trumbleOpinionForGood:cargo_type];
597 if (yumminess > mostYummy)
599 selectedCargopod = cargopod;
600 mostYummy = yumminess;
603 if (selectedCargopod)
606 float trumbleAppetiteAccumulator = [player trumbleAppetiteAccumulator];
608 trumbleAppetiteAccumulator +=
hunger;
613 if (trumbleAppetiteAccumulator > 10.0)
616 NSString* ms = [NSString stringWithFormat:DESC(@"trumbles-eat-@"),
617 [UNIVERSE displayNameForCommodity:[selectedCargopod commodityType]]];
619 [UNIVERSE addMessage: ms forCount: 4.5];
620 [cargopods removeObject:selectedCargopod];
621 trumbleAppetiteAccumulator -= 10.0;
629 [player setTrumbleAppetiteAccumulator:trumbleAppetiteAccumulator];
639 [
self updateSnarl: delta_t];
break;
641 [
self updateShudder: delta_t];
break;
643 [
self updateStoned: delta_t];
break;
645 [
self updatePop: delta_t];
break;
647 [
self updateBlink: delta_t];
break;
649 [
self updateProot: delta_t];
break;
651 [
self updateSleep: delta_t];
break;
653 [
self updateSpawn: delta_t];
break;
656 [
self updateIdle: delta_t];
break;
662- (void) updateIdle:(
double) delta_t
672 [
self randomizeMotionX];
674 [
self randomizeMotionY];
690 [
self actionShudder];
703- (void) updateBlink:(
double) delta_t
721- (void) updateSnarl:(
double) delta_t
729 if ((pc >=25)&&(pc < 90))
731 double vibr = (pc & 1)? -1.0 : 1.0;
742 if ((pc >=90)&&(pc < 100))
761- (void) updateProot:(
double) delta_t
775 double vibr = (pc & 2)? -1.0 : 1.0;
799- (void) updateShudder:(
double) delta_t
815 double vibr = (pc & 2)? -0.25 : 0.25;
836- (void) updateStoned:(
double) delta_t
840- (void) updatePop:(
double) delta_t
870 size -= delta_t * (1.0 - pc) *
size;
876 [player removeTrumble:self];
880- (void) updateSleep:(
double) delta_t
891 double vibr = (pc & 2)? -0.0025 : 0.0025;
915- (void) updateSpawn:(
double) delta_t
924 double vibr = (pc & 2)? -0.002 * pc : 0.002 * pc;
937 [
self randomizeMotionX];
938 [player addTrumble:self];
944 return [NSDictionary dictionaryWithObjectsAndKeys:
945 [NSString stringWithCharacters:digram length:2], @"digram",
946 [NSNumber numberWithFloat:hunger], @"hunger",
947 [NSNumber numberWithFloat:discomfort], @"discomfort",
948 [NSNumber numberWithFloat:size], @"size",
949 [NSNumber numberWithFloat:growth_rate], @"growth_rate",
950 [NSNumber numberWithFloat:rotation], @"rotation",
951 [NSNumber numberWithFloat:rotational_velocity], @"rotational_velocity",
952 StringFromPoint(position), @"position",
953 StringFromPoint(movement), @"movement",
957- (void) setFromDictionary:(NSDictionary*) dict
959 NSString* digramString = (NSString*)[dict objectForKey:
@"digram"];
960 [
self setupForPlayer: player digram: digramString];
961 hunger = [[dict objectForKey: @"hunger"] floatValue];
962 discomfort = [[dict objectForKey: @"discomfort"] floatValue];
963 size = [[dict objectForKey: @"size"] floatValue];
964 growth_rate = [[dict objectForKey: @"growth_rate"] floatValue];
965 rotation = [[dict objectForKey: @"rotation"] floatValue];
995 [sTrumbleSoundSource
setPosition:OORandomUnitVector()];
996 [sTrumbleSoundSource
playSound:sTrumbleIdleSound];
1007 [sTrumbleSoundSource
setPosition:OORandomUnitVector()];
1008 [sTrumbleSoundSource
playSound:sTrumbleSqealSound];
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
void OOGLMultModelView(OOMatrix matrix)
OOMatrix OOGLPopModelView(void)
NSPoint PointFromString(NSString *xyString)
#define TRUMBLE_MAX_ROTATION
#define TRUMBLE_GROWTH_RATE
#define TRUMBLE_MAX_ROTATIONAL_VELOCITY
static OOSound * sTrumbleIdleSound
static void PlayTrumbleSqueal(void)
static OOSoundSource * sTrumbleSoundSource
static OOSound * sTrumbleSqealSound
static void InitTrumbleSounds(void)
static void PlayTrumbleIdle(void)
NSString * OOCommodityType
void playSound:(OOSound *inSound)
void setPosition:(Vector inPosition)
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
NSDictionary * dictionary()
enum trumble_animation animation
enum trumble_eyes eyeFrame
GLfloat rotational_velocity
enum trumble_mouth mouthFrame
enum trumble_animation nextAnimation
OOCommodityType commodityType()
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void ranrot_srand(uint32_t seed)