From: Côme Chilliet Date: Mon, 9 Jan 2017 23:52:57 +0000 (+0100) Subject: Added braces to all statements with clang-tidy and ran clang-format again X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=b9a46d8e2b7e7e22c706e7dd3734f31015db4408;p=lugaru.git Added braces to all statements with clang-tidy and ran clang-format again --- diff --git a/Source/Animation/Muscle.cpp b/Source/Animation/Muscle.cpp index da43de4..ab94d3c 100644 --- a/Source/Animation/Muscle.cpp +++ b/Source/Animation/Muscle.cpp @@ -135,27 +135,34 @@ void Muscle::DoConstraint(bool spinny) } // clamp strength - if (strength < 0) + if (strength < 0) { strength = 0; - if (strength > 1) + } + if (strength > 1) { strength = 1; + } length -= (length - relaxlength) * (1 - strength) * multiplier * 10000; length -= (length - targetlength) * strength * multiplier * 10000; - if (strength == 0) + if (strength == 0) { length = relaxlength; + } - if ((relaxlength - length > 0 && relaxlength - oldlength < 0) || (relaxlength - length < 0 && relaxlength - oldlength > 0)) + if ((relaxlength - length > 0 && relaxlength - oldlength < 0) || (relaxlength - length < 0 && relaxlength - oldlength > 0)) { length = relaxlength; + } // clamp length - if (length < minlength) + if (length < minlength) { length = minlength; - if (length > maxlength) + } + if (length > maxlength) { length = maxlength; + } - if (length == relaxlength) + if (length == relaxlength) { return; + } // relax muscle? diff --git a/Source/Animation/Skeleton.cpp b/Source/Animation/Skeleton.cpp index b665625..91fdbd5 100644 --- a/Source/Animation/Skeleton.cpp +++ b/Source/Animation/Skeleton.cpp @@ -166,20 +166,23 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2; while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(righthip), &jointPos(rightankle), &jointPos(rightknee), &r)) { jointPos(rightknee) -= lowforward * .05; - if (spinny) + if (spinny) { jointVel(rightknee) -= lowforward * .05 / multiplier / 4; - else + } else { jointVel(rightknee) -= lowforward * .05; + } jointPos(rightankle) += lowforward * .025; - if (spinny) + if (spinny) { jointVel(rightankle) += lowforward * .025 / multiplier / 4; - else + } else { jointVel(rightankle) += lowforward * .25; + } jointPos(righthip) += lowforward * .025; - if (spinny) + if (spinny) { jointVel(righthip) += lowforward * .025 / multiplier / 4; - else + } else { jointVel(righthip) += lowforward * .025; + } temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2; } } @@ -189,37 +192,44 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2; while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(lefthip), &jointPos(leftankle), &jointPos(leftknee), &r)) { jointPos(leftknee) -= lowforward * .05; - if (spinny) + if (spinny) { jointVel(leftknee) -= lowforward * .05 / multiplier / 4; - else + } else { jointVel(leftknee) -= lowforward * .05; + } jointPos(leftankle) += lowforward * .025; - if (spinny) + if (spinny) { jointVel(leftankle) += lowforward * .025 / multiplier / 4; - else + } else { jointVel(leftankle) += lowforward * .25; + } jointPos(lefthip) += lowforward * .025; - if (spinny) + if (spinny) { jointVel(lefthip) += lowforward * .025 / multiplier / 4; - else + } else { jointVel(lefthip) += lowforward * .025; + } temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2; } } for (i = 0; i < joints.size(); i++) { - if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320) + if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320) { joints[i].locked = 0; - if (spinny && findLengthfast(&joints[i].velocity) > 600) + } + if (spinny && findLengthfast(&joints[i].velocity) > 600) { joints[i].locked = 0; + } if (joints[i].delay > 0) { bool freely = true; for (unsigned j = 0; j < joints.size(); j++) { - if (joints[j].locked) + if (joints[j].locked) { freely = false; + } } - if (freely) + if (freely) { joints[i].delay -= multiplier * 3; + } } } @@ -256,18 +266,21 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) terrainnormal = terrain.getNormal(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z); ReflectVector(&joints[i].velocity, &terrainnormal); bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal))); - if (!joints[i].locked) + if (!joints[i].locked) { damage += findLengthfast(&bounceness) / 4000; - if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness)) + } + if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal)); joints[i].velocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { joints[i].velocity *= 1 - friction * frictionness; - else + } else { joints[i].velocity = 0; + } - if (!Tutorial::active || id == 0) + if (!Tutorial::active || id == 0) { if (findLengthfast(&bounceness) > 8000 && breaking) { // FIXME: this crashes because k is not initialized! // to reproduce, type 'wolfie' in console and play a while @@ -281,6 +294,7 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) addEnvSound(*coords, 64); } + } if (findLengthfast(&bounceness) > 2500) { Normalise(&bounceness); @@ -294,15 +308,18 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) joints[i].velocity = joints[i].oldvelocity; } - if (joints[i].locked == 0) - if (findLengthfast(&joints[i].velocity) < 1) + if (joints[i].locked == 0) { + if (findLengthfast(&joints[i].velocity) < 1) { joints[i].locked = 1; + } + } if (environment == snowyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) { terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z); Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7); - if (detail == 2) + if (detail == 2) { terrain.MakeDecal(bodyprintdecal, joints[i].position * (*scale) + *coords, .4, .4, 0); + } } else if (environment == desertenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) { terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z); Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7); @@ -311,12 +328,14 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) else if (environment == grassyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) { terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z); Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5); - } else if (findLengthfast(&bounceness) > 500) + } else if (findLengthfast(&bounceness) > 500) { Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .2); + } joints[i].position.y = (terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel - coords->y) / (*scale); - if (longdead > 100) + if (longdead > 100) { broken = 1; + } } for (unsigned int m = 0; m < terrain.patchobjects[whichpatchx][whichpatchz].size(); m++) { unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m]; @@ -345,14 +364,15 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) } terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1; - if (terrainnormal.y > .8) + if (terrainnormal.y > .8) { freefall = 0; + } bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal))); if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) { bounceness = 0; joints[i].velocity = joints[i].oldvelocity; } - if (!Tutorial::active || id == 0) + if (!Tutorial::active || id == 0) { if (findLengthfast(&bounceness) > 4000 && breaking) { Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360); Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2); @@ -363,36 +383,42 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) addEnvSound(*coords, 64); } + } if (Object::objects[k]->type == treetrunktype) { Object::objects[k]->rotx += joints[i].velocity.x * multiplier * .4; Object::objects[k]->roty += joints[i].velocity.z * multiplier * .4; Object::objects[k + 1]->rotx += joints[i].velocity.x * multiplier * .4; Object::objects[k + 1]->roty += joints[i].velocity.z * multiplier * .4; } - if (!joints[i].locked) + if (!joints[i].locked) { damage += findLengthfast(&bounceness) / 2500; + } ReflectVector(&joints[i].velocity, &terrainnormal); frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal)); joints[i].velocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { joints[i].velocity *= 1 - friction * frictionness; - else + } else { joints[i].velocity = 0; + } if (findLengthfast(&bounceness) > 2500) { Normalise(&bounceness); bounceness = bounceness * 50; } joints[i].velocity += bounceness * elasticity; - if (!joints[i].locked) + if (!joints[i].locked) { if (findLengthfast(&joints[i].velocity) < 1) { joints[i].locked = 1; } - if (findLengthfast(&bounceness) > 500) + } + if (findLengthfast(&bounceness) > 500) { Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, .5, .2); + } joints[i].position = (temp - *coords) / (*scale) + terrainnormal * .005; - if (longdead > 100) + if (longdead > 100) { broken = 1; + } } } } @@ -413,8 +439,9 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) if (whichhit != -1) { joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale); for (unsigned j = 0; j < muscles.size(); j++) { - if ((muscles[j].parent1->label == whichjointstartarray[i] && muscles[j].parent2->label == whichjointendarray[i]) || (muscles[j].parent2->label == whichjointstartarray[i] && muscles[j].parent1->label == whichjointendarray[i])) + if ((muscles[j].parent1->label == whichjointstartarray[i] && muscles[j].parent2->label == whichjointendarray[i]) || (muscles[j].parent2->label == whichjointstartarray[i] && muscles[j].parent1->label == whichjointendarray[i])) { muscles[j].DoConstraint(spinny); + } } } } @@ -440,8 +467,9 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) } joints[i].position.y += groundlevel; joints[i].mass = 1; - if (joints[i].label == lefthip || joints[i].label == leftknee || joints[i].label == leftankle || joints[i].label == righthip || joints[i].label == rightknee || joints[i].label == rightankle) + if (joints[i].label == lefthip || joints[i].label == leftknee || joints[i].label == leftankle || joints[i].label == righthip || joints[i].label == rightknee || joints[i].label == rightankle) { joints[i].mass = 2; + } if (joints[i].locked) { joints[i].mass = 4; } @@ -452,8 +480,9 @@ float Skeleton::DoConstraints(XYZ* coords, float* scale) if (!free) { for (i = 0; i < muscles.size(); i++) { - if (muscles[i].type == boneconnect) + if (muscles[i].type == boneconnect) { muscles[i].DoConstraint(0); + } } } @@ -496,26 +525,33 @@ void Skeleton::FindRotationMuscle(int which, int animation) p1 = muscles[which].parent1->position; p2 = muscles[which].parent2->position; dist = findDistance(&p1, &p2); - if (p1.y - p2.y <= dist) + if (p1.y - p2.y <= dist) { muscles[which].rotate2 = asin((p1.y - p2.y) / dist); - if (p1.y - p2.y > dist) + } + if (p1.y - p2.y > dist) { muscles[which].rotate2 = asin(1.f); + } muscles[which].rotate2 *= 360.0 / 6.2831853; p1.y = 0; p2.y = 0; dist = findDistance(&p1, &p2); - if (p1.z - p2.z <= dist) + if (p1.z - p2.z <= dist) { muscles[which].rotate1 = acos((p1.z - p2.z) / dist); - if (p1.z - p2.z > dist) + } + if (p1.z - p2.z > dist) { muscles[which].rotate1 = acos(1.f); + } muscles[which].rotate1 *= 360.0 / 6.2831853; - if (p1.x > p2.x) + if (p1.x > p2.x) { muscles[which].rotate1 = 360 - muscles[which].rotate1; - if (!isnormal(muscles[which].rotate1)) + } + if (!isnormal(muscles[which].rotate1)) { muscles[which].rotate1 = 0; - if (!isnormal(muscles[which].rotate2)) + } + if (!isnormal(muscles[which].rotate2)) { muscles[which].rotate2 = 0; + } const int label1 = muscles[which].parent1->label; const int label2 = muscles[which].parent2->label; @@ -548,10 +584,11 @@ void Skeleton::FindRotationMuscle(int which, int animation) fwd = specialforward[4]; break; default: - if (muscles[which].parent1->lower) + if (muscles[which].parent1->lower) { fwd = lowforward; - else + } else { fwd = forward; + } break; } @@ -579,15 +616,18 @@ void Skeleton::FindRotationMuscle(int which, int animation) fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90); fwd.y = 0; fwd /= findLength(&fwd); - if (fwd.z <= 1 && fwd.z >= -1) + if (fwd.z <= 1 && fwd.z >= -1) { muscles[which].rotate3 = acos(0 - fwd.z); - else + } else { muscles[which].rotate3 = acos(-1.f); + } muscles[which].rotate3 *= 360.0 / 6.2831853; - if (0 > fwd.x) + if (0 > fwd.x) { muscles[which].rotate3 = 360 - muscles[which].rotate3; - if (!isnormal(muscles[which].rotate3)) + } + if (!isnormal(muscles[which].rotate3)) { muscles[which].rotate3 = 0; + } } /* EFFECT @@ -646,10 +686,12 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfilename, drawmodellow.Rotate(180, 0, 0); drawmodellow.Scale(.04, .04, .04); drawmodellow.FlipTexCoords(); - if (Tutorial::active && id != 0) + if (Tutorial::active && id != 0) { drawmodellow.UniformTexCoords(); - if (Tutorial::active && id != 0) + } + if (Tutorial::active && id != 0) { drawmodellow.ScaleTexCoords(0.1); + } drawmodellow.CalculateNormals(0); if (clothes) { @@ -872,8 +914,9 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfilename, for (int i = 0; i < num_joints; i++) { for (j = 0; j < num_joints; j++) { - if (joints[i].label == j) + if (joints[i].label == j) { jointlabels[j] = i; + } } } diff --git a/Source/Audio/Sounds.cpp b/Source/Audio/Sounds.cpp index a259864..4d8510a 100644 --- a/Source/Audio/Sounds.cpp +++ b/Source/Audio/Sounds.cpp @@ -70,8 +70,9 @@ void loadAllSounds() footstepsound4 = footstepst2; // Huh? // OPENAL_Sample_SetMode(samp[whooshsound], OPENAL_LOOP_NORMAL); - for (int i = stream_firesound; i <= stream_menutheme; i++) + for (int i = stream_firesound; i <= stream_menutheme; i++) { OPENAL_Stream_SetMode(samp[i], OPENAL_LOOP_NORMAL); + } } void addEnvSound(XYZ coords, float vol, float life) diff --git a/Source/Audio/openal_wrapper.cpp b/Source/Audio/openal_wrapper.cpp index d728e5a..269b868 100644 --- a/Source/Audio/openal_wrapper.cpp +++ b/Source/Audio/openal_wrapper.cpp @@ -65,8 +65,9 @@ static void set_channel_position(const int channel, const float x, chan->position[2] = z; OPENAL_SAMPLE* sptr = chan->sample; - if (sptr == NULL) + if (sptr == NULL) { return; + } const ALuint sid = chan->sid; const bool no_attenuate = sptr->is2d; @@ -82,8 +83,9 @@ static void set_channel_position(const int channel, const float x, AL_API void OPENAL_3D_Listener_SetAttributes(const float* pos, const float*, float fx, float fy, float fz, float tx, float ty, float tz) { - if (!initialized) + if (!initialized) { return; + } if (pos != NULL) { alListener3f(AL_POSITION, pos[0], pos[1], -pos[2]); listener_position[0] = pos[0]; @@ -105,13 +107,16 @@ AL_API void OPENAL_3D_Listener_SetAttributes(const float* pos, const float*, flo AL_API signed char OPENAL_3D_SetAttributes(int channel, const float* pos) { - if (!initialized) + if (!initialized) { return false; - if ((channel < 0) || (channel >= (int)num_channels)) + } + if ((channel < 0) || (channel >= (int)num_channels)) { return false; + } - if (pos != NULL) + if (pos != NULL) { set_channel_position(channel, pos[0], pos[1], -pos[2]); + } // we ignore velocity, since doppler's broken in the Linux AL at the moment... @@ -120,10 +125,12 @@ AL_API signed char OPENAL_3D_SetAttributes(int channel, const float* pos) AL_API signed char OPENAL_3D_SetAttributes_(int channel, const XYZ& pos) { - if (!initialized) + if (!initialized) { return false; - if ((channel < 0) || (channel >= (int)num_channels)) + } + if ((channel < 0) || (channel >= (int)num_channels)) { return false; + } set_channel_position(channel, pos.x, pos.y, -pos.z); @@ -132,17 +139,21 @@ AL_API signed char OPENAL_3D_SetAttributes_(int channel, const XYZ& pos) AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned int flags) { - if (initialized) + if (initialized) { return false; - if (maxsoftwarechannels == 0) + } + if (maxsoftwarechannels == 0) { return false; + } - if (flags != 0) // unsupported. + if (flags != 0) { // unsupported. return false; + } ALCdevice* dev = alcOpenDevice(NULL); - if (!dev) + if (!dev) { return false; + } ALint caps[] = { ALC_FREQUENCY, mixrate, 0 }; ALCcontext* ctx = alcCreateContext(dev, caps); @@ -164,8 +175,9 @@ AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned in num_channels = maxsoftwarechannels; impl_channels = new OPENAL_Channels[maxsoftwarechannels]; memset(impl_channels, '\0', sizeof(OPENAL_Channels) * num_channels); - for (unsigned i = 0; i < num_channels; i++) + for (unsigned i = 0; i < num_channels; i++) { alGenSources(1, &impl_channels[i].sid); // !!! FIXME: verify this didn't fail! + } initialized = true; return true; @@ -173,8 +185,9 @@ AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned in AL_API void OPENAL_Close() { - if (!initialized) + if (!initialized) { return; + } ALCcontext* ctx = alcGetCurrentContext(); if (ctx) { @@ -199,21 +212,26 @@ AL_API void OPENAL_Close() static OPENAL_SAMPLE* OPENAL_GetCurrentSample(int channel) { - if (!initialized) + if (!initialized) { return NULL; - if ((channel < 0) || (channel >= (int)num_channels)) + } + if ((channel < 0) || (channel >= (int)num_channels)) { return NULL; + } return impl_channels[channel].sample; } static signed char OPENAL_GetPaused(int channel) { - if (!initialized) + if (!initialized) { return false; - if ((channel < 0) || (channel >= (int)num_channels)) + } + if ((channel < 0) || (channel >= (int)num_channels)) { return false; - if (impl_channels[channel].startpaused) + } + if (impl_channels[channel].startpaused) { return (true); + } ALint state = 0; alGetSourceiv(impl_channels[channel].sid, AL_SOURCE_STATE, &state); @@ -222,23 +240,28 @@ static signed char OPENAL_GetPaused(int channel) static unsigned int OPENAL_GetLoopMode(int channel) { - if (!initialized) + if (!initialized) { return 0; - if ((channel < 0) || (channel >= (int)num_channels)) + } + if ((channel < 0) || (channel >= (int)num_channels)) { return 0; + } ALint loop = 0; alGetSourceiv(impl_channels[channel].sid, AL_LOOPING, &loop); - if (loop) + if (loop) { return (OPENAL_LOOP_NORMAL); + } return OPENAL_LOOP_OFF; } static signed char OPENAL_IsPlaying(int channel) { - if (!initialized) + if (!initialized) { return false; - if ((channel < 0) || (channel >= (int)num_channels)) + } + if ((channel < 0) || (channel >= (int)num_channels)) { return false; + } ALint state = 0; alGetSourceiv(impl_channels[channel].sid, AL_SOURCE_STATE, &state); return ((state == AL_PLAYING) ? true : false); @@ -246,12 +269,15 @@ static signed char OPENAL_IsPlaying(int channel) static int OPENAL_PlaySoundEx(int channel, OPENAL_SAMPLE* sptr, OPENAL_DSPUNIT* dsp, signed char startpaused) { - if (!initialized) + if (!initialized) { return -1; - if (sptr == NULL) + } + if (sptr == NULL) { return -1; - if (dsp != NULL) + } + if (dsp != NULL) { return -1; + } if (channel == OPENAL_FREE) { for (unsigned i = 0; i < num_channels; i++) { ALint state = 0; @@ -263,8 +289,9 @@ static int OPENAL_PlaySoundEx(int channel, OPENAL_SAMPLE* sptr, OPENAL_DSPUNIT* } } - if ((channel < 0) || (channel >= (int)num_channels)) + if ((channel < 0) || (channel >= (int)num_channels)) { return -1; + } alSourceStop(impl_channels[channel].sid); impl_channels[channel].sample = sptr; alSourcei(impl_channels[channel].sid, AL_BUFFER, sptr->bid); @@ -272,8 +299,9 @@ static int OPENAL_PlaySoundEx(int channel, OPENAL_SAMPLE* sptr, OPENAL_DSPUNIT* set_channel_position(channel, 0.0f, 0.0f, 0.0f); impl_channels[channel].startpaused = ((startpaused) ? true : false); - if (!startpaused) + if (!startpaused) { alSourcePlay(impl_channels[channel].sid); + } return channel; } @@ -289,14 +317,16 @@ static void* decode_to_pcm(const char* _fname, ALenum& format, ALsizei& size, AL char* fname = (char*)alloca(strlen(_fname) + 16); strcpy(fname, _fname); char* ptr = strchr(fname, '.'); - if (ptr) + if (ptr) { *ptr = '\0'; + } strcat(fname, ".ogg"); // just in case... FILE* io = fopen(fname, "rb"); - if (io == NULL) + if (io == NULL) { return NULL; + } ALubyte* retval = NULL; @@ -364,24 +394,30 @@ static void* decode_to_pcm(const char* _fname, ALenum& format, ALsizei& size, AL AL_API OPENAL_SAMPLE* OPENAL_Sample_Load(int index, const char* name_or_data, unsigned int mode, int offset, int length) { - if (!initialized) + if (!initialized) { return NULL; - if (index != OPENAL_FREE) + } + if (index != OPENAL_FREE) { return NULL; // this is all the game does... - if (offset != 0) + } + if (offset != 0) { return NULL; // this is all the game does... - if (length != 0) + } + if (length != 0) { return NULL; // this is all the game does... - if ((mode != OPENAL_HW3D) && (mode != OPENAL_2D)) + } + if ((mode != OPENAL_HW3D) && (mode != OPENAL_2D)) { return NULL; // this is all the game does... + } OPENAL_SAMPLE* retval = NULL; ALenum format = AL_NONE; ALsizei size = 0; ALuint frequency = 0; void* data = decode_to_pcm(name_or_data, format, size, frequency); - if (data == NULL) + if (data == NULL) { return NULL; + } ALuint bid = 0; alGetError(); @@ -393,8 +429,9 @@ AL_API OPENAL_SAMPLE* OPENAL_Sample_Load(int index, const char* name_or_data, un retval->mode = OPENAL_LOOP_OFF; retval->is2d = (mode == OPENAL_2D); retval->name = new char[strlen(name_or_data) + 1]; - if (retval->name) + if (retval->name) { strcpy(retval->name, name_or_data); + } } free(data); @@ -403,8 +440,9 @@ AL_API OPENAL_SAMPLE* OPENAL_Sample_Load(int index, const char* name_or_data, un AL_API void OPENAL_Sample_Free(OPENAL_SAMPLE* sptr) { - if (!initialized) + if (!initialized) { return; + } if (sptr) { for (unsigned i = 0; i < num_channels; i++) { if (impl_channels[i].sample == sptr) { @@ -421,53 +459,64 @@ AL_API void OPENAL_Sample_Free(OPENAL_SAMPLE* sptr) static signed char OPENAL_Sample_SetMode(OPENAL_SAMPLE* sptr, unsigned int mode) { - if (!initialized) + if (!initialized) { return false; - if ((mode != OPENAL_LOOP_NORMAL) && (mode != OPENAL_LOOP_OFF)) + } + if ((mode != OPENAL_LOOP_NORMAL) && (mode != OPENAL_LOOP_OFF)) { return false; - if (!sptr) + } + if (!sptr) { return false; + } sptr->mode = mode; return true; } AL_API signed char OPENAL_SetFrequency(int channel, bool slomo) { - if (!initialized) + if (!initialized) { return false; + } if (channel == OPENAL_ALL) { - for (unsigned i = 0; i < num_channels; i++) + for (unsigned i = 0; i < num_channels; i++) { OPENAL_SetFrequency(i, slomo); + } return true; } - if ((channel < 0) || (channel >= (int)num_channels)) + if ((channel < 0) || (channel >= (int)num_channels)) { return false; - if (slomo) + } + if (slomo) { alSourcef(impl_channels[channel].sid, AL_PITCH, ((ALfloat)slomofreq) / 44100.0f); - else + } else { alSourcef(impl_channels[channel].sid, AL_PITCH, 1.0f); + } return true; } AL_API signed char OPENAL_SetVolume(int channel, int vol) { - if (!initialized) + if (!initialized) { return false; + } if (channel == OPENAL_ALL) { - for (unsigned i = 0; i < num_channels; i++) + for (unsigned i = 0; i < num_channels; i++) { OPENAL_SetVolume(i, vol); + } return true; } - if ((channel < 0) || (channel >= (int)num_channels)) + if ((channel < 0) || (channel >= (int)num_channels)) { return false; + } - if (vol < 0) + if (vol < 0) { vol = 0; - else if (vol > 255) + } else if (vol > 255) { vol = 255; + } ALfloat gain = ((ALfloat)vol) / 255.0f; alSourcef(impl_channels[channel].sid, AL_GAIN, gain); return true; @@ -475,27 +524,31 @@ AL_API signed char OPENAL_SetVolume(int channel, int vol) AL_API signed char OPENAL_SetPaused(int channel, signed char paused) { - if (!initialized) + if (!initialized) { return false; + } if (channel == OPENAL_ALL) { - for (unsigned i = 0; i < num_channels; i++) + for (unsigned i = 0; i < num_channels; i++) { OPENAL_SetPaused(i, paused); + } return true; } - if ((channel < 0) || (channel >= (int)num_channels)) + if ((channel < 0) || (channel >= (int)num_channels)) { return false; + } ALint state = 0; - if (impl_channels[channel].startpaused) + if (impl_channels[channel].startpaused) { state = AL_PAUSED; - else + } else { alGetSourceiv(impl_channels[channel].sid, AL_SOURCE_STATE, &state); + } - if ((paused) && (state == AL_PLAYING)) + if ((paused) && (state == AL_PLAYING)) { alSourcePause(impl_channels[channel].sid); - else if ((!paused) && (state == AL_PAUSED)) { + } else if ((!paused) && (state == AL_PAUSED)) { alSourcePlay(impl_channels[channel].sid); impl_channels[channel].startpaused = false; } @@ -504,25 +557,29 @@ AL_API signed char OPENAL_SetPaused(int channel, signed char paused) AL_API void OPENAL_SetSFXMasterVolume(int volume) { - if (!initialized) + if (!initialized) { return; + } ALfloat gain = ((ALfloat)volume) / 255.0f; alListenerf(AL_GAIN, gain); } AL_API signed char OPENAL_StopSound(int channel) { - if (!initialized) + if (!initialized) { return false; + } if (channel == OPENAL_ALL) { - for (unsigned i = 0; i < num_channels; i++) + for (unsigned i = 0; i < num_channels; i++) { OPENAL_StopSound(i); + } return true; } - if ((channel < 0) || (channel >= (int)num_channels)) + if ((channel < 0) || (channel >= (int)num_channels)) { return false; + } alSourceStop(impl_channels[channel].sid); impl_channels[channel].startpaused = false; return true; @@ -530,8 +587,9 @@ AL_API signed char OPENAL_StopSound(int channel) static OPENAL_SAMPLE* OPENAL_Stream_GetSample(OPENAL_STREAM* stream) { - if (!initialized) + if (!initialized) { return NULL; + } return (OPENAL_SAMPLE*)stream; } @@ -542,8 +600,9 @@ static int OPENAL_Stream_PlayEx(int channel, OPENAL_STREAM* stream, OPENAL_DSPUN static signed char OPENAL_Stream_Stop(OPENAL_STREAM* stream) { - if (!initialized) + if (!initialized) { return false; + } for (unsigned i = 0; i < num_channels; i++) { if (impl_channels[i].sample == (OPENAL_SAMPLE*)stream) { alSourceStop(impl_channels[i].sid); @@ -560,8 +619,9 @@ AL_API signed char OPENAL_Stream_SetMode(OPENAL_STREAM* stream, unsigned int mod AL_API void OPENAL_Update() { - if (!initialized) + if (!initialized) { return; + } alcProcessContext(alcGetCurrentContext()); } diff --git a/Source/Devtools/ConsoleCmds.cpp b/Source/Devtools/ConsoleCmds.cpp index f9a7068..cfb2efd 100644 --- a/Source/Devtools/ConsoleCmds.cpp +++ b/Source/Devtools/ConsoleCmds.cpp @@ -148,8 +148,9 @@ static void set_clothes(int pnum, const char* args) Person::players[pnum]->clothestintb[id] = tintb; Person::players[pnum]->numclothes++; - if (!Person::players[pnum]->addClothes(id)) + if (!Person::players[pnum]->addClothes(id)) { return; + } Person::players[pnum]->DoMipmaps(); } @@ -197,9 +198,11 @@ void ch_save(const char* args) fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb); fpackf(tfile, "Bf Bf Bf Bf Bf Bi", Person::players[0]->coords.x, Person::players[0]->coords.y, Person::players[0]->coords.z, Person::players[0]->yaw, Person::players[0]->targetyaw, Person::players[0]->num_weapons); - if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5) - for (int j = 0; j < Person::players[0]->num_weapons; j++) + if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5) { + for (int j = 0; j < Person::players[0]->num_weapons; j++) { fpackf(tfile, "Bi", weapons[Person::players[0]->weaponids[j]].getType()); + } + } fpackf(tfile, "Bf Bf Bf", Person::players[0]->armorhead, Person::players[0]->armorhigh, Person::players[0]->armorlow); fpackf(tfile, "Bf Bf Bf", Person::players[0]->protectionhead, Person::players[0]->protectionhigh, Person::players[0]->protectionlow); @@ -215,8 +218,9 @@ void ch_save(const char* args) for (int k = 0; k < Person::players[0]->numclothes; k++) { int templength = strlen(Person::players[0]->clothes[k]); fpackf(tfile, "Bi", templength); - for (int l = 0; l < templength; l++) + for (int l = 0; l < templength; l++) { fpackf(tfile, "Bb", Person::players[0]->clothes[k][l]); + } fpackf(tfile, "Bf Bf Bf", Person::players[0]->clothestintr[k], Person::players[0]->clothestintg[k], Person::players[0]->clothestintb[k]); } @@ -234,8 +238,9 @@ void ch_save(const char* args) fpackf(tfile, "Bi Bf Bf Bf Bf", Hotspot::hotspots[i].type, Hotspot::hotspots[i].size, Hotspot::hotspots[i].position.x, Hotspot::hotspots[i].position.y, Hotspot::hotspots[i].position.z); int templength = strlen(Hotspot::hotspots[i].text); fpackf(tfile, "Bi", templength); - for (int l = 0; l < templength; l++) + for (int l = 0; l < templength; l++) { fpackf(tfile, "Bb", Hotspot::hotspots[i].text[l]); + } } fpackf(tfile, "Bi", Person::players.size()); @@ -246,9 +251,11 @@ void ch_save(const char* args) fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", Person::players[j]->whichskin, Person::players[j]->creature, Person::players[j]->coords.x, Person::players[j]->coords.y, Person::players[j]->coords.z, Person::players[j]->num_weapons, Person::players[j]->howactive, Person::players[j]->scale, Person::players[j]->immobile, Person::players[j]->yaw); - if (Person::players[j]->num_weapons < 5) - for (int k = 0; k < Person::players[j]->num_weapons; k++) + if (Person::players[j]->num_weapons < 5) { + for (int k = 0; k < Person::players[j]->num_weapons; k++) { fpackf(tfile, "Bi", weapons[Person::players[j]->weaponids[k]].getType()); + } + } if (Person::players[j]->numwaypoints < 30) { fpackf(tfile, "Bi", Person::players[j]->numwaypoints); for (int k = 0; k < Person::players[j]->numwaypoints; k++) { @@ -286,22 +293,25 @@ void ch_save(const char* args) fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop); fpackf(tfile, "Bi", Person::players[j]->numclothes); - if (Person::players[j]->numclothes) + if (Person::players[j]->numclothes) { for (int k = 0; k < Person::players[j]->numclothes; k++) { int templength; templength = strlen(Person::players[j]->clothes[k]); fpackf(tfile, "Bi", templength); - for (int l = 0; l < templength; l++) + for (int l = 0; l < templength; l++) { fpackf(tfile, "Bb", Person::players[j]->clothes[k][l]); + } fpackf(tfile, "Bf Bf Bf", Person::players[j]->clothestintr[k], Person::players[j]->clothestintg[k], Person::players[j]->clothestintb[k]); } + } } fpackf(tfile, "Bi", numpathpoints); for (int j = 0; j < numpathpoints; j++) { fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]); - for (int k = 0; k < numpathpointconnect[j]; k++) + for (int k = 0; k < numpathpointconnect[j]; k++) { fpackf(tfile, "Bi", pathpointconnect[j][k]); + } } fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius); @@ -357,8 +367,9 @@ void ch_size(const char* args) void ch_sizenear(const char* args) { int closest = findClosestPlayer(); - if (closest >= 0) + if (closest >= 0) { Person::players[closest]->scale = atof(args) * .2; + } } void ch_proportion(const char* args) @@ -369,8 +380,9 @@ void ch_proportion(const char* args) void ch_proportionnear(const char* args) { int closest = findClosestPlayer(); - if (closest >= 0) + if (closest >= 0) { set_proportion(closest, args); + } } void ch_protection(const char* args) @@ -381,8 +393,9 @@ void ch_protection(const char* args) void ch_protectionnear(const char* args) { int closest = findClosestPlayer(); - if (closest >= 0) + if (closest >= 0) { set_protection(closest, args); + } } void ch_armor(const char* args) @@ -393,8 +406,9 @@ void ch_armor(const char* args) void ch_armornear(const char* args) { int closest = findClosestPlayer(); - if (closest >= 0) + if (closest >= 0) { set_armor(closest, args); + } } void ch_protectionreset(const char*) @@ -416,8 +430,9 @@ void ch_noclothes(const char* args) void ch_noclothesnear(const char* args) { int closest = findClosestPlayer(); - if (closest >= 0) + if (closest >= 0) { set_noclothes(closest, args); + } } void ch_clothes(const char* args) @@ -428,8 +443,9 @@ void ch_clothes(const char* args) void ch_clothesnear(const char* args) { int closest = findClosestPlayer(); - if (closest >= 0) + if (closest >= 0) { set_clothes(closest, args); + } } void ch_belt(const char*) @@ -510,9 +526,11 @@ void ch_black(const char*) void ch_sizemin(const char*) { - for (unsigned i = 1; i < Person::players.size(); i++) - if (Person::players[i]->scale < 0.8 * 0.2) + for (unsigned i = 1; i < Person::players.size(); i++) { + if (Person::players[i]->scale < 0.8 * 0.2) { Person::players[i]->scale = 0.8 * 0.2; + } + } } void ch_tutorial(const char* args) @@ -528,21 +546,23 @@ void ch_hostile(const char* args) void ch_type(const char* args) { int n = sizeof(editortypenames) / sizeof(editortypenames[0]); - for (int i = 0; i < n; i++) + for (int i = 0; i < n; i++) { if (stripfx(args, editortypenames[i])) { editoractive = i; break; } + } } void ch_path(const char* args) { unsigned int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]); - for (unsigned int i = 0; i < n; i++) + for (unsigned int i = 0; i < n; i++) { if (stripfx(args, pathtypenames[i])) { editorpathtype = i; break; } + } } void ch_hs(const char* args) @@ -617,8 +637,9 @@ void ch_immobile(const char*) void ch_allimmobile(const char*) { - for (unsigned i = 1; i < Person::players.size(); i++) + for (unsigned i = 1; i < Person::players.size(); i++) { Person::players[i]->immobile = 1; + } } void ch_mobile(const char*) diff --git a/Source/Environment/Skybox.cpp b/Source/Environment/Skybox.cpp index 468329a..51fe466 100644 --- a/Source/Environment/Skybox.cpp +++ b/Source/Environment/Skybox.cpp @@ -66,8 +66,9 @@ void SkyBox::draw() glDisable(GL_CULL_FACE); glEnable(GL_BLEND); glDisable(GL_LIGHTING); - if (skyboxtexture) + if (skyboxtexture) { glEnable(GL_TEXTURE_2D); + } glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); front.bind(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); diff --git a/Source/Environment/Terrain.cpp b/Source/Environment/Terrain.cpp index d3a6f00..9ef4718 100644 --- a/Source/Environment/Terrain.cpp +++ b/Source/Environment/Terrain.cpp @@ -79,28 +79,36 @@ int Terrain::lineTerrain(XYZ p1, XYZ p2, XYZ* p) starty = i; } - if (startx < 0) + if (startx < 0) { startx = 0; - if (starty < 0) + } + if (starty < 0) { starty = 0; - if (endx > size - 1) + } + if (endx > size - 1) { endx = size - 1; - if (endy > size - 1) + } + if (endy > size - 1) { endy = size - 1; + } for (i = startx; i <= endx; i++) { for (j = starty; j <= endy; j++) { highest = -1000; lowest = 1000; for (k = 0; k < 2; k++) { - if (heightmap[i + k][j] > highest) + if (heightmap[i + k][j] > highest) { highest = heightmap[i + k][j]; - if (heightmap[i + k][j] < lowest) + } + if (heightmap[i + k][j] < lowest) { lowest = heightmap[i + k][j]; - if (heightmap[i + k][j + 1] > highest) + } + if (heightmap[i + k][j + 1] > highest) { highest = heightmap[i + k][j + 1]; - if (heightmap[i + k][j + 1] < lowest) + } + if (heightmap[i + k][j + 1] < lowest) { lowest = heightmap[i + k][j + 1]; + } } if ((p1.y <= highest || p2.y <= highest) && (p1.y >= lowest || p2.y >= lowest)) { triangles[0].x = i; @@ -169,8 +177,9 @@ void Terrain::UpdateTransparency(int whichx, int whichy) vertex.z = j * scale; vertex.y = heightmap[i][j] * scale; distance = distsq(&viewer, &vertex); - if (distance > viewdistsquared) + if (distance > viewdistsquared) { distance = viewdistsquared; + } colors[i][j][3] = (viewdistsquared - (distance - (viewdistsquared * fadestart)) * (1 / (1 - fadestart))) / viewdistsquared; } } @@ -246,8 +255,9 @@ void Terrain::UpdateTransparencyotherother(int whichx, int whichy) vertex.z = j * scale; vertex.y = heightmap[i][j] * scale; distance = distsq(&viewer, &vertex); - if (distance > viewdistsquared) + if (distance > viewdistsquared) { distance = viewdistsquared; + } colors[i][j][3] = (viewdistsquared - (distance - (viewdistsquared * fadestart)) * (1 / (1 - fadestart))) / viewdistsquared; } } @@ -354,15 +364,18 @@ void Terrain::UpdateVertexArray(int whichx, int whichy) minypatch[whichx][whichy] = 10000; for (a = 0; a < size / subdivision; a++) { for (b = 0; b < size / subdivision; b++) { - if (heightmap[(size / subdivision) * whichx + a][(size / subdivision) * whichy + b] * scale > maxypatch[whichx][whichy]) + if (heightmap[(size / subdivision) * whichx + a][(size / subdivision) * whichy + b] * scale > maxypatch[whichx][whichy]) { maxypatch[whichx][whichy] = heightmap[(size / subdivision) * whichx + a][(size / subdivision) * whichy + b] * scale; - if (heightmap[(size / subdivision) * whichx + a][(size / subdivision) * whichy + b] * scale < minypatch[whichx][whichy]) + } + if (heightmap[(size / subdivision) * whichx + a][(size / subdivision) * whichy + b] * scale < minypatch[whichx][whichy]) { minypatch[whichx][whichy] = heightmap[(size / subdivision) * whichx + a][(size / subdivision) * whichy + b] * scale; + } } } heightypatch[whichx][whichy] = (maxypatch[whichx][whichy] - minypatch[whichx][whichy]); - if (heightypatch[whichx][whichy] < size / subdivision * scale) + if (heightypatch[whichx][whichy] < size / subdivision * scale) { heightypatch[whichx][whichy] = size / subdivision * scale; + } avgypatch[whichx][whichy] = (minypatch[whichx][whichy] + maxypatch[whichx][whichy]) / 2; for (i = whichx * size / subdivision; i < (whichx + 1) * size / subdivision - 1; i++) { @@ -458,8 +471,9 @@ bool Terrain::load(const std::string& fileName) slopeness = heightmap[i][j] - heightmap[i][j - 1]; } opacityother[i][j] = slopeness * slopeness * 2; - if (opacityother[i][j] > 1) + if (opacityother[i][j] > 1) { opacityother[i][j] = 1; + } opacityother[i][j] -= (float)abs(Random() % 100) / 300; } if (environment == desertenvironment) { @@ -467,8 +481,9 @@ bool Terrain::load(const std::string& fileName) slopeness = heightmap[i][j] - heightmap[i][j - 1]; } opacityother[i][j] = slopeness * slopeness * 2; - if (opacityother[i][j] > 1) + if (opacityother[i][j] > 1) { opacityother[i][j] = 1; + } opacityother[i][j] -= (float)abs(Random() % 100) / 300; } if (environment == grassyenvironment) { @@ -485,8 +500,9 @@ bool Terrain::load(const std::string& fileName) slopeness = heightmap[i][j] - heightmap[i][j + 1]; } opacityother[i][j] = slopeness * slopeness * 10; - if (opacityother[i][j] > 1) + if (opacityother[i][j] > 1) { opacityother[i][j] = 1; + } opacityother[i][j] -= (float)abs(Random() % 100) / 100; } } @@ -507,55 +523,72 @@ bool Terrain::load(const std::string& fileName) for (i = 0; i < size; i++) { for (j = 0; j < size; j++) { - if (opacityother[i][j] < .1) + if (opacityother[i][j] < .1) { opacityother[i][j] = 0; + } if (textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == -1) { - if (!opacityother[i][j]) + if (!opacityother[i][j]) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = allfirst; - if (opacityother[i][j] == 1) + } + if (opacityother[i][j] == 1) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = allsecond; + } } - if (opacityother[i][j] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[i][j] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; + } x = i; y = j; if (i > 0) { i--; - if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) + } + if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; + } if (j > 0) { j--; - if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) + } + if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; + } j++; } if (j < size - 1) { j++; - if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) + } + if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; + } j--; } i++; @@ -563,38 +596,50 @@ bool Terrain::load(const std::string& fileName) if (i < size - 1) { i++; - if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) + } + if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; + } if (j > 0) { j--; - if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) + } + if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; + } j++; } if (j < size - 1) { j++; - if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) + } + if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; + } j--; } i--; @@ -602,27 +647,35 @@ bool Terrain::load(const std::string& fileName) if (j > 0) { j--; - if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) + } + if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; + } j++; } if (j < size - 1) { j++; - if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) + if (opacityother[x][y] && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allfirst) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) + } + if (opacityother[x][y] != 1 && textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] == allsecond) { textureness[(int)(i * subdivision / size)][(int)(j * subdivision / size)] = mixed; - if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) + } + if (opacityother[i][j] && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allfirst) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; - if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) + } + if (opacityother[i][j] != 1 && textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] == allsecond) { textureness[(int)(x * subdivision / size)][(int)(y * subdivision / size)] = mixed; + } j--; } } @@ -713,8 +766,9 @@ void Terrain::CalculateNormals() void Terrain::drawpatch(int whichx, int whichy, float opacity) { - if (opacity >= 1) + if (opacity >= 1) { glDisable(GL_BLEND); + } if (opacity < 1) { glEnable(GL_BLEND); UpdateTransparency(whichx, whichy); @@ -802,8 +856,9 @@ float Terrain::getHeight(float pointx, float pointz) pointx /= scale; pointz /= scale; - if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) + if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) { return 0; + } startpoint.x = pointx; startpoint.y = -1000; @@ -852,8 +907,9 @@ float Terrain::getOpacity(float pointx, float pointz) pointx /= scale; pointz /= scale; - if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) + if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) { return 0; + } tilex = pointx; tiley = pointz; @@ -873,8 +929,9 @@ XYZ Terrain::getNormal(float pointx, float pointz) pointz /= scale; height1 = 0; - if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) + if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) { return height1; + } tilex = pointx; tiley = pointz; @@ -894,8 +951,9 @@ XYZ Terrain::getLighting(float pointx, float pointz) pointz /= scale; height1 = 0; - if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) + if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0) { return height1; + } tilex = pointx; tiley = pointz; @@ -926,18 +984,22 @@ void Terrain::draw(int layer) //Only nearby blocks beginx = ((viewer.x - viewdistance) / patch_size) - 1; - if (beginx < 0) + if (beginx < 0) { beginx = 0; + } beginz = ((viewer.z - viewdistance) / patch_size) - 1; - if (beginz < 0) + if (beginz < 0) { beginz = 0; + } endx = ((viewer.x + viewdistance) / patch_size) + 1; - if (endx > subdivision) + if (endx > subdivision) { endx = subdivision; + } endz = ((viewer.z + viewdistance) / patch_size) + 1; - if (endz > subdivision) + if (endz > subdivision) { endz = subdivision; + } if (!layer) { for (i = beginx; i < endx; i++) { @@ -953,37 +1015,49 @@ void Terrain::draw(int layer) for (j = beginz; j < endz; j++) { if (distance[i][j] < (viewdistance + patch_size) * (viewdistance + patch_size)) { opacity = 1; - if (distance[i][j] > viewdistsquared * fadestart - viewdistsquared) + if (distance[i][j] > viewdistsquared * fadestart - viewdistsquared) { opacity = 0; - if (opacity == 1 && i != subdivision) - if (distance[i + 1][j] > viewdistsquared * fadestart - viewdistsquared) + } + if (opacity == 1 && i != subdivision) { + if (distance[i + 1][j] > viewdistsquared * fadestart - viewdistsquared) { opacity = 0; - if (opacity == 1 && j != subdivision) - if (distance[i][j + 1] > viewdistsquared * fadestart - viewdistsquared) + } + } + if (opacity == 1 && j != subdivision) { + if (distance[i][j + 1] > viewdistsquared * fadestart - viewdistsquared) { opacity = 0; - if (opacity == 1 && j != subdivision && i != subdivision) - if (distance[i + 1][j + 1] > viewdistsquared * fadestart - viewdistsquared) + } + } + if (opacity == 1 && j != subdivision && i != subdivision) { + if (distance[i + 1][j + 1] > viewdistsquared * fadestart - viewdistsquared) { opacity = 0; + } + } glMatrixMode(GL_MODELVIEW); glPushMatrix(); if (frustum.CubeInFrustum(i * patch_size + patch_size * .5, avgypatch[i][j], j * patch_size + patch_size * .5, heightypatch[i][j] / 2)) { - if (environment == desertenvironment && distance[i][j] > viewdistsquared / 4) + if (environment == desertenvironment && distance[i][j] > viewdistsquared / 4) { glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness); - else if (environment == desertenvironment) + } else if (environment == desertenvironment) { glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0); - if (!layer && textureness[i][j] != allsecond) + } + if (!layer && textureness[i][j] != allsecond) { drawpatch(i, j, opacity); - if (layer == 1 && textureness[i][j] != allfirst) + } + if (layer == 1 && textureness[i][j] != allfirst) { drawpatchother(i, j, opacity); - if (layer == 2 && textureness[i][j] != allfirst) + } + if (layer == 2 && textureness[i][j] != allfirst) { drawpatchotherother(i, j); + } } glPopMatrix(); } } } - if (environment == desertenvironment) + if (environment == desertenvironment) { glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0); + } } void Terrain::drawdecals() @@ -1005,8 +1079,9 @@ void Terrain::drawdecals() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthMask(0); for (unsigned int i = 0; i < decals.size(); i++) { - if (decals[i].type == blooddecalfast && decals[i].alivetime < 2) + if (decals[i].type == blooddecalfast && decals[i].alivetime < 2) { decals[i].alivetime = 2; + } if (decals[i].type != lasttype) { if (decals[i].type == shadowdecal || decals[i].type == shadowdecalpermanent) { shadowtexture.bind(); @@ -1051,39 +1126,47 @@ void Terrain::drawdecals() } if (decals[i].type == shadowdecal || decals[i].type == shadowdecalpermanent) { distancemult = (viewdistsquared - (distsq(&viewer, &decals[i].position) - (viewdistsquared * fadestart)) * (1 / (1 - fadestart))) / viewdistsquared; - if (distancemult >= 1) + if (distancemult >= 1) { glColor4f(1, 1, 1, decals[i].opacity); - if (distancemult < 1) + } + if (distancemult < 1) { glColor4f(1, 1, 1, decals[i].opacity * distancemult); + } } if (decals[i].type == footprintdecal || decals[i].type == bodyprintdecal) { distancemult = (viewdistsquared - (distsq(&viewer, &decals[i].position) - (viewdistsquared * fadestart)) * (1 / (1 - fadestart))) / viewdistsquared; if (distancemult >= 1) { glColor4f(1, 1, 1, decals[i].opacity); - if (decals[i].alivetime > 3) + if (decals[i].alivetime > 3) { glColor4f(1, 1, 1, decals[i].opacity * (5 - decals[i].alivetime) / 2); + } } if (distancemult < 1) { glColor4f(1, 1, 1, decals[i].opacity * distancemult); - if (decals[i].alivetime > 3) + if (decals[i].alivetime > 3) { glColor4f(1, 1, 1, decals[i].opacity * (5 - decals[i].alivetime) / 2 * distancemult); + } } } if ((decals[i].type == blooddecal || decals[i].type == blooddecalfast || decals[i].type == blooddecalslow)) { distancemult = (viewdistsquared - (distsq(&viewer, &decals[i].position) - (viewdistsquared * fadestart)) * (1 / (1 - fadestart))) / viewdistsquared; if (distancemult >= 1) { glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity); - if (decals[i].alivetime < 4) + if (decals[i].alivetime < 4) { glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * decals[i].alivetime * .25); - if (decals[i].alivetime > 58) + } + if (decals[i].alivetime > 58) { glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * (60 - decals[i].alivetime) / 2); + } } if (distancemult < 1) { glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * distancemult); - if (decals[i].alivetime < 4) + if (decals[i].alivetime < 4) { glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * decals[i].alivetime * distancemult * .25); - if (decals[i].alivetime > 58) + } + if (decals[i].alivetime > 58) { glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * (60 - decals[i].alivetime) / 2 * distancemult); + } } } lasttype = decals[i].type; @@ -1102,18 +1185,24 @@ void Terrain::drawdecals() } for (int i = decals.size() - 1; i >= 0; i--) { decals[i].alivetime += multiplier; - if (decals[i].type == blooddecalslow) + if (decals[i].type == blooddecalslow) { decals[i].alivetime -= multiplier * 2 / 3; - if (decals[i].type == blooddecalfast) + } + if (decals[i].type == blooddecalfast) { decals[i].alivetime += multiplier * 4; - if (decals[i].type == shadowdecal) + } + if (decals[i].type == shadowdecal) { DeleteDecal(i); - if (decals[i].type == footprintdecal && decals[i].alivetime >= 5) + } + if (decals[i].type == footprintdecal && decals[i].alivetime >= 5) { DeleteDecal(i); - if (decals[i].type == bodyprintdecal && decals[i].alivetime >= 5) + } + if (decals[i].type == bodyprintdecal && decals[i].alivetime >= 5) { DeleteDecal(i); - if ((decals[i].type == blooddecal || decals[i].type == blooddecalfast || decals[i].type == blooddecalslow) && decals[i].alivetime >= 60) + } + if ((decals[i].type == blooddecal || decals[i].type == blooddecalfast || decals[i].type == blooddecalslow) && decals[i].alivetime >= 60) { DeleteDecal(i); + } } glAlphaFunc(GL_GREATER, 0.0001); } @@ -1199,8 +1288,9 @@ void Terrain::MakeDecalLock(decal_type type, XYZ where, int whichx, int whichy, XYZ rot = getLighting(where.x, where.z); float decalbright = (rot.x + rot.y + rot.z) / 3; - if (decalbright < .4) + if (decalbright < .4) { decalbright = .4; + } if (environment == grassyenvironment) { decalbright *= .6; @@ -1212,21 +1302,31 @@ void Terrain::MakeDecalLock(decal_type type, XYZ where, int whichx, int whichy, Decal decal(where, type, opacity, rotation, decalbright, whichx, whichy, size, *this, true); - if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) - if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) - if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) - if (!(decal.texcoords[0][1] > 1 && decal.texcoords[1][1] > 1 && decal.texcoords[2][1] > 1)) - if (decals.size() < max_decals - 1) + if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) { + if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) { + if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) { + if (!(decal.texcoords[0][1] > 1 && decal.texcoords[1][1] > 1 && decal.texcoords[2][1] > 1)) { + if (decals.size() < max_decals - 1) { decals.push_back(decal); + } + } + } + } + } Decal decal2(where, type, opacity, rotation, decalbright, whichx, whichy, size, *this, false); - if (!(decal2.texcoords[0][0] < 0 && decal2.texcoords[1][0] < 0 && decal2.texcoords[2][0] < 0)) - if (!(decal2.texcoords[0][1] < 0 && decal2.texcoords[1][1] < 0 && decal2.texcoords[2][1] < 0)) - if (!(decal2.texcoords[0][0] > 1 && decal2.texcoords[1][0] > 1 && decal2.texcoords[2][0] > 1)) - if (!(decal2.texcoords[0][1] > 1 && decal2.texcoords[1][1] > 1 && decal2.texcoords[2][1] > 1)) - if (decals.size() < max_decals - 1) + if (!(decal2.texcoords[0][0] < 0 && decal2.texcoords[1][0] < 0 && decal2.texcoords[2][0] < 0)) { + if (!(decal2.texcoords[0][1] < 0 && decal2.texcoords[1][1] < 0 && decal2.texcoords[2][1] < 0)) { + if (!(decal2.texcoords[0][0] > 1 && decal2.texcoords[1][0] > 1 && decal2.texcoords[2][0] > 1)) { + if (!(decal2.texcoords[0][1] > 1 && decal2.texcoords[1][1] > 1 && decal2.texcoords[2][1] > 1)) { + if (decals.size() < max_decals - 1) { decals.push_back(decal2); + } + } + } + } + } } } @@ -1269,30 +1369,39 @@ void Terrain::DoShadows() Game::LoadingScreen(); } float brightness = dotproduct(&lightloc, &normals[i][j]); - if (shadowed) + if (shadowed) { brightness *= 1 - shadowed; + } - if (brightness > 1) + if (brightness > 1) { brightness = 1; - if (brightness < 0) + } + if (brightness < 0) { brightness = 0; + } colors[i][j][0] = light.color[0] * brightness + light.ambient[0]; colors[i][j][1] = light.color[1] * brightness + light.ambient[1]; colors[i][j][2] = light.color[2] * brightness + light.ambient[2]; - if (colors[i][j][0] > 1) + if (colors[i][j][0] > 1) { colors[i][j][0] = 1; - if (colors[i][j][1] > 1) + } + if (colors[i][j][1] > 1) { colors[i][j][1] = 1; - if (colors[i][j][2] > 1) + } + if (colors[i][j][2] > 1) { colors[i][j][2] = 1; - if (colors[i][j][0] < 0) + } + if (colors[i][j][0] < 0) { colors[i][j][0] = 0; - if (colors[i][j][1] < 0) + } + if (colors[i][j][1] < 0) { colors[i][j][1] = 0; - if (colors[i][j][2] < 0) + } + if (colors[i][j][2] < 0) { colors[i][j][2] = 0; + } } } diff --git a/Source/Game.cpp b/Source/Game.cpp index 54b4f2f..d362a54 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -175,11 +175,13 @@ void Game::inputText(string& str, unsigned* charselected) } else if (evenement.key.keysym.sym == SDLK_END) { (*charselected) = str.size(); } else if (evenement.key.keysym.sym == SDLK_LEFT) { - if ((*charselected) != 0) + if ((*charselected) != 0) { (*charselected)--; + } } else if (evenement.key.keysym.sym == SDLK_RIGHT) { - if ((*charselected) < str.size()) + if ((*charselected) < str.size()) { (*charselected)++; + } } else if (evenement.key.keysym.sym == SDLK_RETURN) { waiting = false; } diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 2e15dcd..a24df69 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -149,8 +149,9 @@ int Game::DrawGLScene(StereoSide side) if (!mainmenu) { if (editorenabled) { numboundaries = mapradius * 2; - if (numboundaries > 360) + if (numboundaries > 360) { numboundaries = 360; + } for (int i = 0; i < numboundaries; i++) { boundary[i] = 0; boundary[i].z = 1; @@ -177,54 +178,66 @@ int Game::DrawGLScene(StereoSide side) } if (slomo && !loading) { - if (ismotionblur) + if (ismotionblur) { drawmode = motionblurmode; + } motionbluramount = .2; slomodelay -= multiplier; - if (slomodelay < 0) + if (slomodelay < 0) { slomo = 0; + } camerashake = 0; changed = 1; } if ((!changed && !slomo) || loading) { drawmode = normalmode; if (ismotionblur && (/*fps>100||*/ alwaysblur)) { - if (olddrawmode != realmotionblurmode) + if (olddrawmode != realmotionblurmode) { change = 1; - else + } else { change = 0; + } drawmode = realmotionblurmode; - } else if (olddrawmode == realmotionblurmode) + } else if (olddrawmode == realmotionblurmode) { change = 2; - else + } else { change = 0; + } } - if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) + if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) { drawmode = normalmode; - if ((freeze || winfreeze) && ismotionblur && !mainmenu) + } + if ((freeze || winfreeze) && ismotionblur && !mainmenu) { drawmode = radialzoommode; + } - if (winfreeze || mainmenu) + if (winfreeze || mainmenu) { drawmode = normalmode; + } - if (drawtoggle != 2) + if (drawtoggle != 2) { drawtoggle = 1 - drawtoggle; + } if (!texcoordwidth) { texviewwidth = kTextureSize; - if (texviewwidth > screenwidth) + if (texviewwidth > screenwidth) { texviewwidth = screenwidth; + } texviewheight = kTextureSize; - if (texviewheight > screenheight) + if (texviewheight > screenheight) { texviewheight = screenheight; + } texcoordwidth = screenwidth / kTextureSize; texcoordheight = screenheight / kTextureSize; - if (texcoordwidth > 1) + if (texcoordwidth > 1) { texcoordwidth = 1; - if (texcoordheight > 1) + } + if (texcoordheight > 1) { texcoordheight = 1; + } } glDrawBuffer(GL_BACK); @@ -277,10 +290,11 @@ int Game::DrawGLScene(StereoSide side) blurness = targetblurness; targetblurness = (float)(abs(Random() % 100)) / 40; } - if (blurness < targetblurness) + if (blurness < targetblurness) { blurness += multiplier * 5; - else + } else { blurness -= multiplier * 5; + } if (environment == desertenvironment) { if (detail == 2) { @@ -300,8 +314,8 @@ int Game::DrawGLScene(StereoSide side) static float size, opacity, rotation; rotation = 0; for (unsigned int k = 0; k < Person::players.size(); k++) { - if (!Person::players[k]->skeleton.free && Person::players[k]->playerdetail && Person::players[k]->howactive < typesleeping) - if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y + Person::players[k]->scale * 3, Person::players[k]->coords.z, Person::players[k]->scale * 7) && Person::players[k]->occluded < 25) + if (!Person::players[k]->skeleton.free && Person::players[k]->playerdetail && Person::players[k]->howactive < typesleeping) { + if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y + Person::players[k]->scale * 3, Person::players[k]->coords.z, Person::players[k]->scale * 7) && Person::players[k]->occluded < 25) { for (unsigned int i = 0; i < Person::players[k]->skeleton.joints.size(); i++) { if (Person::players[k]->skeleton.joints[i].label == leftknee || Person::players[k]->skeleton.joints[i].label == rightknee || Person::players[k]->skeleton.joints[i].label == groin) { point = DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords; @@ -325,14 +339,17 @@ int Game::DrawGLScene(StereoSide side) } } } - if ((Person::players[k]->skeleton.free || Person::players[k]->howactive >= typesleeping) && Person::players[k]->playerdetail) - if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y, Person::players[k]->coords.z, Person::players[k]->scale * 5) && Person::players[k]->occluded < 25) + } + } + if ((Person::players[k]->skeleton.free || Person::players[k]->howactive >= typesleeping) && Person::players[k]->playerdetail) { + if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y, Person::players[k]->coords.z, Person::players[k]->scale * 5) && Person::players[k]->occluded < 25) { for (unsigned i = 0; i < Person::players[k]->skeleton.joints.size(); i++) { if (Person::players[k]->skeleton.joints[i].label == leftknee || Person::players[k]->skeleton.joints[i].label == rightknee || Person::players[k]->skeleton.joints[i].label == groin || Person::players[k]->skeleton.joints[i].label == leftelbow || Person::players[k]->skeleton.joints[i].label == rightelbow || Person::players[k]->skeleton.joints[i].label == neck) { - if (Person::players[k]->skeleton.free) + if (Person::players[k]->skeleton.free) { point = Person::players[k]->skeleton.joints[i].position * Person::players[k]->scale + Person::players[k]->coords; - else + } else { point = DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords; + } size = .4f; opacity = .4 - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 5; if (k != 0 && Tutorial::active) { @@ -342,10 +359,11 @@ int Game::DrawGLScene(StereoSide side) for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) { unsigned int j = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l]; if (Object::objects[j]->position.y < Person::players[k]->coords.y || Object::objects[j]->type == tunneltype || Object::objects[j]->type == weirdtype) { - if (Person::players[k]->skeleton.free) + if (Person::players[k]->skeleton.free) { point = DoRotation(Person::players[k]->skeleton.joints[i].position * Person::players[k]->scale + Person::players[k]->coords - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0); - else + } else { point = DoRotation(DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0); + } size = .4f; opacity = .4f; if (k != 0 && Tutorial::active) { @@ -356,8 +374,10 @@ int Game::DrawGLScene(StereoSide side) } } } + } + } - if (!Person::players[k]->playerdetail) + if (!Person::players[k]->playerdetail) { if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y, Person::players[k]->coords.z, Person::players[k]->scale * 5)) { point = Person::players[k]->coords; size = .7; @@ -371,6 +391,7 @@ int Game::DrawGLScene(StereoSide side) Object::objects[j]->model.MakeDecal(shadowdecal, &point, &size, &opacity, &rotation); } } + } } //Terrain @@ -410,33 +431,38 @@ int Game::DrawGLScene(StereoSide side) distance = distsq(&viewer, &Person::players[k]->coords); distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance; glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance); - if (distance >= 1) + if (distance >= 1) { glDisable(GL_BLEND); + } if (distance >= .5) { checkpoint = DoRotation(Person::players[k]->skeleton.joints[fabs(Random() % Person::players[k]->skeleton.joints.size())].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords; checkpoint.y += 1; int i = -1; - if (Person::players[k]->occluded != 0) + if (Person::players[k]->occluded != 0) { i = Object::checkcollide(viewer, checkpoint, Person::players[k]->lastoccluded); - if (i == -1) + } + if (i == -1) { i = Object::checkcollide(viewer, checkpoint); + } if (i != -1) { Person::players[k]->occluded += 1; Person::players[k]->lastoccluded = i; } else { Person::players[k]->occluded = 0; } - if (Person::players[k]->occluded < 25) + if (Person::players[k]->occluded < 25) { Person::players[k]->DrawSkeleton(); + } } } } } - if (!cameramode && musictype == stream_fighttheme) + if (!cameramode && musictype == stream_fighttheme) { playerdist = distsqflat(&Person::players[0]->coords, &viewer); - else + } else { playerdist = -100; + } glPushMatrix(); glCullFace(GL_BACK); glEnable(GL_TEXTURE_2D); @@ -456,10 +482,12 @@ int Game::DrawGLScene(StereoSide side) glTranslatef(25, 0, 0); distance = distsq(&viewer, &realhawkcoords) * 1.2; glColor4f(light.color[0], light.color[1], light.color[2], (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance); - if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 1) + if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 1) { glColor4f(light.color[0], light.color[1], light.color[2], 1); - if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 0) + } + if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 0) { hawk.drawdifftex(hawktexture); + } } glPopMatrix(); @@ -475,8 +503,9 @@ int Game::DrawGLScene(StereoSide side) distance = distsq(&viewer, &Person::players[k]->coords); distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance; glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance); - if (distance >= 1) + if (distance >= 1) { glDisable(GL_BLEND); + } if (distance >= .5) { checkpoint = DoRotation(Person::players[k]->skeleton.joints[fabs(Random() % Person::players[k]->skeleton.joints.size())].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords; checkpoint.y += 1; @@ -558,14 +587,14 @@ int Game::DrawGLScene(StereoSide side) glEnable(GL_TEXTURE_2D); glColor4f(.5, .5, .5, 1); if (!console) { - if (!Tutorial::active) + if (!Tutorial::active) { if (bonus > 0 && bonustime < 1 && !winfreeze && !Dialog::inDialog()) { const char* bonus_name; - if (bonus < bonus_count) + if (bonus < bonus_count) { bonus_name = bonus_names[bonus]; - else + } else { bonus_name = "Excellent!"; // When does this happen? - + } text->glPrintOutlined(1, 0, 0, 1 - bonustime, 1024 / 2 - 10 * strlen(bonus_name), 768 / 16 + 768 * 4 / 5, bonus_name, 1, 2, 1024, 768); string = to_string((int)bonusvalue); @@ -573,6 +602,7 @@ int Game::DrawGLScene(StereoSide side) glColor4f(.5, .5, .5, 1); } + } if (Tutorial::active) { Tutorial::DrawTextInfo(); @@ -594,14 +624,17 @@ int Game::DrawGLScene(StereoSide side) if (closest != -1) { Hotspot::current = closest; if (Hotspot::hotspots[closest].type <= 10) { - if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[closest].position) < Hotspot::hotspots[closest].size) + if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[closest].position) < Hotspot::hotspots[closest].size) { Tutorial::stagetime = 0; + } Tutorial::maxtime = 1; tutorialopac = Tutorial::maxtime - Tutorial::stagetime; - if (tutorialopac > 1) + if (tutorialopac > 1) { tutorialopac = 1; - if (tutorialopac < 0) + } + if (tutorialopac < 0) { tutorialopac = 0; + } string = Hotspot::hotspots[closest].text; @@ -614,11 +647,13 @@ int Game::DrawGLScene(StereoSide side) text->glPrintOutlined(1, 1, 1, tutorialopac, screenwidth / 2 - 7.6 * (i - lastline) * screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); lastline = i + 1; line++; - if (string[i] == '\0') + if (string[i] == '\0') { done = 1; + } } - if (i >= 255) + if (i >= 255) { done = 1; + } i++; } } else if ((Hotspot::hotspots[closest].type >= 20) && (Dialog::dialogs[Hotspot::hotspots[closest].type - 20].gonethrough == 0)) { @@ -642,8 +677,9 @@ int Game::DrawGLScene(StereoSide side) glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - if (Dialog::currentScene().location == 1) + if (Dialog::currentScene().location == 1) { glTranslatef(0, screenheight * 3 / 4, 0); + } glScalef(screenwidth, screenheight / 4, 1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); @@ -686,10 +722,11 @@ int Game::DrawGLScene(StereoSide side) for (unsigned i = 0; i < Dialog::currentScene().name.size(); i++) { tempname[tempnum] = Dialog::currentScene().name[i]; - if (tempname[tempnum] == '#' || tempname[tempnum] == '\0') + if (tempname[tempnum] == '#' || tempname[tempnum] == '\0') { tempname[tempnum] = '\0'; - else + } else { tempnum++; + } } string = std::string(tempname) + ": "; @@ -704,8 +741,9 @@ int Game::DrawGLScene(StereoSide side) tempnum = 0; for (unsigned i = 0; i < Dialog::currentScene().text.size() + 1; i++) { tempname[tempnum] = Dialog::currentScene().text[i]; - if (Dialog::currentScene().text[i] != '#') + if (Dialog::currentScene().text[i] != '#') { tempnum++; + } } string = tempname; @@ -724,11 +762,13 @@ int Game::DrawGLScene(StereoSide side) } lastline = i + 1; line++; - if (string[i] == '\0') + if (string[i] == '\0') { done = 1; + } } - if (i >= 255) + if (i >= 255) { done = 1; + } i++; } } @@ -955,12 +995,15 @@ int Game::DrawGLScene(StereoSide side) glScalef(screenwidth, screenheight, 1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - if (Person::players[0]->dead) + if (Person::players[0]->dead) { blackout += multiplier * 3; - if (Person::players[0]->dead == 1) + } + if (Person::players[0]->dead == 1) { blackout = .4f; - if (Person::players[0]->dead == 2 && blackout > .6) + } + if (Person::players[0]->dead == 2 && blackout > .6) { blackout = .6; + } glColor4f(0, 0, 0, blackout); if (!Person::players[0]->dead) { if ((Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5)) * .3 < .3) { @@ -971,8 +1014,9 @@ int Game::DrawGLScene(StereoSide side) blackout = Person::players[0]->blooddimamount * .3; } } - if (console) + if (console) { glColor4f(.7, 0, 0, .2); + } glBegin(GL_QUADS); glVertex3f(0, 0, 0.0f); glVertex3f(256, 0, 0.0f); @@ -990,13 +1034,16 @@ int Game::DrawGLScene(StereoSide side) } if (flashamount > 0 && damageeffects) { - if (flashamount > 1) + if (flashamount > 1) { flashamount = 1; - if (flashdelay <= 0) + } + if (flashdelay <= 0) { flashamount -= multiplier; + } flashdelay--; - if (flashamount < 0) + if (flashamount < 0) { flashamount = 0; + } glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -1140,18 +1187,19 @@ int Game::DrawGLScene(StereoSide side) if (distcheck < mapviewdist) { glPushMatrix(); Maparrowtexture.bind(); - if (i == 0) + if (i == 0) { glColor4f(1, 1, 1, opac); - else if (Person::players[i]->dead == 2 || Person::players[i]->howactive > typesleeping) + } else if (Person::players[i]->dead == 2 || Person::players[i]->howactive > typesleeping) { glColor4f(0, 0, 0, opac * (1 - distcheck / mapviewdist)); - else if (Person::players[i]->dead) + } else if (Person::players[i]->dead) { glColor4f(.3, .3, .3, opac * (1 - distcheck / mapviewdist)); - else if (Person::players[i]->aitype == attacktypecutoff) + } else if (Person::players[i]->aitype == attacktypecutoff) { glColor4f(1, 0, 0, opac * (1 - distcheck / mapviewdist)); - else if (Person::players[i]->aitype == passivetype) + } else if (Person::players[i]->aitype == passivetype) { glColor4f(0, 1, 0, opac * (1 - distcheck / mapviewdist)); - else + } else { glColor4f(1, 1, 0, 1); + } glTranslatef(Person::players[i]->coords.x / terrain.scale / 256 * -2 + 1, Person::players[i]->coords.z / terrain.scale / 256 * 2 - 1, 0); glRotatef(Person::players[i]->yaw + 180, 0, 0, 1); glScalef(.005, .005, .005); @@ -1293,8 +1341,9 @@ int Game::DrawGLScene(StereoSide side) int awards[award_count]; int numawards = award_awards(awards); - for (int i = 0; i < numawards && i < 6; i++) + for (int i = 0; i < numawards && i < 6; i++) { text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 90 - 40 * i, award_names[awards[i]], 1, 2, 1024, 768); + } } if (drawmode != normalmode) { @@ -1367,8 +1416,9 @@ int Game::DrawGLScene(StereoSide side) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); if (drawmode == motionblurmode) { - if (motionbluramount < .2) + if (motionbluramount < .2) { motionbluramount = .2; + } glColor4f(1, 1, 1, motionbluramount); glPushMatrix(); glBegin(GL_QUADS); @@ -1420,10 +1470,12 @@ int Game::DrawGLScene(StereoSide side) if (drawmode == doublevisionmode) { static float crosseyedness; crosseyedness = abs(Person::players[0]->damage - Person::players[0]->superpermanentdamage - (Person::players[0]->damagetolerance - Person::players[0]->superpermanentdamage) * 1 / 2) / 30; - if (crosseyedness > 1) + if (crosseyedness > 1) { crosseyedness = 1; - if (crosseyedness < 0) + } + if (crosseyedness < 0) { crosseyedness = 0; + } glColor4f(1, 1, 1, 1); glDisable(GL_BLEND); glPushMatrix(); @@ -1548,8 +1600,9 @@ int Game::DrawGLScene(StereoSide side) glEnable(GL_TEXTURE_2D); glColor4f(1, 1, 1, 1); int offset = 0; - if (consoleselected >= 60) + if (consoleselected >= 60) { offset = consoleselected - 60; + } textmono->glPrint(10, 30, " ]", 0, 1, 1024, 768); if (consoleblink) { textmono->glPrint(30 + (float)consoleselected * 10 - offset * 10, 30, "_", 0, 1, 1024, 768); @@ -1584,8 +1637,9 @@ int Game::DrawGLScene(StereoSide side) weapons.DoStuff(); - if (drawtoggle == 2) + if (drawtoggle == 2) { drawtoggle = 0; + } if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) { multiplier = tempmult; @@ -1719,13 +1773,16 @@ void DrawMenu() //draw screen flash if (flashamount > 0) { - if (flashamount > 1) + if (flashamount > 1) { flashamount = 1; - if (flashdelay <= 0) + } + if (flashdelay <= 0) { flashamount -= multiplier; + } flashdelay--; - if (flashamount < 0) + if (flashamount < 0) { flashamount = 0; + } glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index b082ef1..57f6958 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -179,16 +179,19 @@ void Game::LoadingScreen() AbsoluteTime currTime = UpTime(); double deltaTime = (float)AbsoluteDeltaToDuration(currTime, frametime); - if (0 > deltaTime) // if negative microseconds + if (0 > deltaTime) { // if negative microseconds deltaTime /= -1000000.0; - else // else milliseconds + } else { // else milliseconds deltaTime /= 1000.0; + } multiplier = deltaTime; - if (multiplier < .001) + if (multiplier < .001) { multiplier = .001; - if (multiplier > 10) + } + if (multiplier > 10) { multiplier = 10; + } if (multiplier > .05) { frametime = currTime; // reset for next time interval @@ -200,8 +203,9 @@ void Game::LoadingScreen() loadtime += multiplier * 4; loadprogress = loadtime; - if (loadprogress > 100) + if (loadprogress > 100) { loadprogress = 100; + } //Background @@ -341,13 +345,16 @@ void Game::LoadingScreen() //Text if (flashamount > 0) { - if (flashamount > 1) + if (flashamount > 1) { flashamount = 1; - if (flashdelay <= 0) + } + if (flashdelay <= 0) { flashamount -= multiplier; + } flashdelay--; - if (flashamount < 0) + if (flashamount < 0) { flashamount = 0; + } glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -556,8 +563,9 @@ void Game::InitGame() OPENAL_SetSFXMasterVolume((int)(volume * 255)); loadAllSounds(); - if (musictoggle) + if (musictoggle) { emit_stream_np(stream_menutheme); + } cursortexture.load("Textures/Cursor.png", 0); @@ -566,8 +574,9 @@ void Game::InitGame() Maparrowtexture.load("Textures/MapArrow.png", 0); temptexdetail = texdetail; - if (texdetail > 2) + if (texdetail > 2) { texdetail = 2; + } Mainmenuitems[0].load("Textures/Lugaru.png", 0); Mainmenuitems[1].load("Textures/NewGame.png", 0); Mainmenuitems[2].load("Textures/Options.png", 0); @@ -599,8 +608,9 @@ void Game::LoadScreenTexture() { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (!Game::screentexture) + if (!Game::screentexture) { glGenTextures(1, &Game::screentexture); + } glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 7e50cc0..9844ff0 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -179,8 +179,9 @@ float roughDirection(XYZ vec) { Normalise(&vec); float angle = -asin(-vec.x) * 180 / M_PI; - if (vec.z < 0) + if (vec.z < 0) { angle = 180 - angle; + } return angle; } float roughDirectionTo(XYZ start, XYZ end) @@ -202,12 +203,13 @@ float sq(float n) } inline float stepTowardf(float from, float to, float by) { - if (fabs(from - to) < by) + if (fabs(from - to) < by) { return to; - else if (from > to) + } else if (from > to) { return from - by; - else + } else { return from + by; + } } void Game::playdialoguescenesound() @@ -286,8 +288,9 @@ void Game::playdialoguescenesound() default: break; } - if (sound != -1) + if (sound != -1) { emit_sound_at(sound, temppos); + } } // ================================================================ @@ -327,12 +330,13 @@ static void cmd_dispatch(const string cmd) { int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]); - for (i = 0; i < n_cmds; i++) + for (i = 0; i < n_cmds; i++) { if (cmd.substr(0, cmd.find(' ')) == string(cmd_names[i])) { cout << "|" << cmd.substr(cmd.find(' ') + 1) << "|" << endl; cmd_handlers[i](cmd.substr(cmd.find(' ') + 1).c_str()); break; } + } emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound); } @@ -351,14 +355,18 @@ void Screenshot(void) void Game::SetUpLighting() { - if (environment == snowyenvironment) + if (environment == snowyenvironment) { light.setColors(.65, .65, .7, .4, .4, .44); - if (environment == desertenvironment) + } + if (environment == desertenvironment) { light.setColors(.95, .95, .95, .4, .35, .3); - if (environment == grassyenvironment) + } + if (environment == grassyenvironment) { light.setColors(.95, .95, 1, .4, .4, .44); - if (!skyboxtexture) + } + if (!skyboxtexture) { light.setColors(1, 1, 1, .4, .4, .4); + } float average; average = (skyboxlightr + skyboxlightg + skyboxlightb) / 3; light.color[0] *= (skyboxlightr + average) / 2; @@ -387,8 +395,9 @@ void Setenvironment(int which) if (environment == snowyenvironment) { windvector = 0; windvector.z = 3; - if (ambientsound) + if (ambientsound) { emit_stream_np(stream_wind); + } Object::treetextureptr.load("Textures/SnowTree.png", 0); Object::bushtextureptr.load("Textures/BushSnow.png", 0); @@ -404,8 +413,9 @@ void Setenvironment(int which) terraintexture2.load("Textures/Rock.jpg", 1); temptexdetail = texdetail; - if (texdetail > 1) + if (texdetail > 1) { texdetail = 4; + } skybox->load("Textures/Skybox(snow)/Front.jpg", "Textures/Skybox(snow)/Left.jpg", "Textures/Skybox(snow)/Back.jpg", @@ -422,8 +432,9 @@ void Setenvironment(int which) Object::rocktextureptr.load("Textures/BoulderDesert.jpg", 1); Object::boxtextureptr.load("Textures/DesertBox.jpg", 1); - if (ambientsound) + if (ambientsound) { emit_stream_np(stream_desertambient); + } footstepsound = footstepsn1; footstepsound2 = footstepsn2; @@ -434,8 +445,9 @@ void Setenvironment(int which) terraintexture2.load("Textures/SandSlope.jpg", 1); temptexdetail = texdetail; - if (texdetail > 1) + if (texdetail > 1) { texdetail = 4; + } skybox->load("Textures/Skybox(sand)/Front.jpg", "Textures/Skybox(sand)/Left.jpg", "Textures/Skybox(sand)/Back.jpg", @@ -452,8 +464,9 @@ void Setenvironment(int which) Object::rocktextureptr.load("Textures/Boulder.jpg", 1); Object::boxtextureptr.load("Textures/GrassBox.jpg", 1); - if (ambientsound) + if (ambientsound) { emit_stream_np(stream_wind, 100.); + } footstepsound = footstepgr1; footstepsound2 = footstepgr2; @@ -464,8 +477,9 @@ void Setenvironment(int which) terraintexture2.load("Textures/MossRock.jpg", 1); temptexdetail = texdetail; - if (texdetail > 1) + if (texdetail > 1) { texdetail = 4; + } skybox->load("Textures/Skybox(grass)/Front.jpg", "Textures/Skybox(grass)/Left.jpg", "Textures/Skybox(grass)/Back.jpg", @@ -514,12 +528,15 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) LOG(std::string("Loading level...") + name); - if (!gameon) + if (!gameon) { visibleloading = true; - if (stealthloading) + } + if (stealthloading) { visibleloading = false; - if (!stillloading) + } + if (!stillloading) { loadtime = 0; + } gamestarted = 1; numenvsounds = 0; @@ -573,8 +590,9 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) freeze = 0; winfreeze = 0; - for (unsigned char i = 0; i < 100; i++) + for (unsigned char i = 0; i < 100; i++) { bonusnum[i] = 0; + } numfalls = 0; numflipfail = 0; @@ -622,35 +640,38 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) if (mapvers < 12) { cerr << name << " has obsolete map version " << mapvers << endl; } - if (mapvers >= 15) + if (mapvers >= 15) { funpackf(tfile, "Bi", &indemo); - else + } else { indemo = 0; - if (mapvers >= 5) + } + if (mapvers >= 5) { funpackf(tfile, "Bi", &maptype); - else + } else { maptype = mapkilleveryone; - if (mapvers >= 6) + } + if (mapvers >= 6) { funpackf(tfile, "Bi", &hostile); - else + } else { hostile = 1; - if (mapvers >= 4) + } + if (mapvers >= 4) { funpackf(tfile, "Bf Bf", &viewdistance, &fadestart); - else { + } else { viewdistance = 100; fadestart = .6; } - if (mapvers >= 2) + if (mapvers >= 2) { funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb); - else { + } else { skyboxtexture = 1; skyboxr = 1; skyboxg = 1; skyboxb = 1; } - if (mapvers >= 10) + if (mapvers >= 10) { funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb); - else { + } else { skyboxlightr = skyboxr; skyboxlightg = skyboxg; skyboxlightb = skyboxb; @@ -661,13 +682,14 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) } else { funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &Person::players[0]->coords.x, &Person::players[0]->coords.y, &Person::players[0]->coords.z, &Person::players[0]->yaw, &Person::players[0]->targetyaw, &Person::players[0]->num_weapons); } - if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5) + if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5) { for (int j = 0; j < Person::players[0]->num_weapons; j++) { Person::players[0]->weaponids[j] = weapons.size(); int type; funpackf(tfile, "Bi", &type); weapons.push_back(Weapon(type, 0)); } + } Game::LoadingScreen(); @@ -678,9 +700,9 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) funpackf(tfile, "Bi", &Person::players[0]->numclothes); - if (mapvers >= 9) + if (mapvers >= 9) { funpackf(tfile, "Bi Bi", &Person::players[0]->whichskin, &Person::players[0]->creature); - else { + } else { Person::players[0]->whichskin = 0; Person::players[0]->creature = rabbittype; } @@ -696,16 +718,18 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) for (int k = 0; k < Person::players[0]->numclothes; k++) { funpackf(tfile, "Bi", &templength); - for (int l = 0; l < templength; l++) + for (int l = 0; l < templength; l++) { funpackf(tfile, "Bb", &Person::players[0]->clothes[k][l]); + } Person::players[0]->clothes[k][templength] = '\0'; funpackf(tfile, "Bf Bf Bf", &Person::players[0]->clothestintr[k], &Person::players[0]->clothestintg[k], &Person::players[0]->clothestintb[k]); } funpackf(tfile, "Bi", &environment); - if (environment != oldenvironment) + if (environment != oldenvironment) { Setenvironment(environment); + } oldenvironment = environment; Object::LoadObjectsFromFile(tfile, stealthloading); @@ -721,12 +745,15 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) { funpackf(tfile, "Bi Bf Bf Bf Bf", &Hotspot::hotspots[i].type, &Hotspot::hotspots[i].size, &Hotspot::hotspots[i].position.x, &Hotspot::hotspots[i].position.y, &Hotspot::hotspots[i].position.z); funpackf(tfile, "Bi", &templength); - if (templength) - for (int l = 0; l < templength; l++) + if (templength) { + for (int l = 0; l < templength; l++) { funpackf(tfile, "Bb", &Hotspot::hotspots[i].text[l]); + } + } Hotspot::hotspots[i].text[templength] = '\0'; - if (Hotspot::hotspots[i].type == -111) + if (Hotspot::hotspots[i].type == -111) { indemo = 1; + } } } else { Hotspot::hotspots.clear(); @@ -758,8 +785,9 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) Game::LoadingScreen(); funpackf(tfile, "Bi", &numpathpoints); - if (numpathpoints > 30 || numpathpoints < 0) + if (numpathpoints > 30 || numpathpoints < 0) { numpathpoints = 0; + } for (int j = 0; j < numpathpoints; j++) { funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x, &pathpoint[j].y, &pathpoint[j].z, &numpathpointconnect[j]); for (int k = 0; k < numpathpointconnect[j]; k++) { @@ -807,10 +835,12 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) Person::players[i]->target = 0; } Person::players[i]->speed = 1 + (float)(Random() % 100) / 1000; - if (difficulty == 0) + if (difficulty == 0) { Person::players[i]->speed -= .2; - if (difficulty == 1) + } + if (difficulty == 1) { Person::players[i]->speed -= .1; + } if (i == 0) { Person::players[i]->velocity = 0; @@ -949,8 +979,9 @@ void doDevKeys() /* Change environment */ if (Input::isKeyPressed(SDL_SCANCODE_J)) { environment++; - if (environment > 2) + if (environment > 2) { environment = 0; + } Setenvironment(environment); } @@ -990,12 +1021,13 @@ void doDevKeys() if (closest >= 0) { if (Person::players[closest]->num_weapons > 0) { - if (weapons[Person::players[closest]->weaponids[0]].getType() == sword) + if (weapons[Person::players[closest]->weaponids[0]].getType() == sword) { weapons[Person::players[closest]->weaponids[0]].setType(staff); - else if (weapons[Person::players[closest]->weaponids[0]].getType() == staff) + } else if (weapons[Person::players[closest]->weaponids[0]].getType() == staff) { weapons[Person::players[closest]->weaponids[0]].setType(knife); - else + } else { weapons[Person::players[closest]->weaponids[0]].setType(sword); + } } else { Person::players[closest]->weaponids[0] = weapons.size(); @@ -1040,10 +1072,12 @@ void doDevKeys() if (closest >= 0) { Person::players[closest]->whichskin++; - if (Person::players[closest]->whichskin > 9) + if (Person::players[closest]->whichskin > 9) { Person::players[closest]->whichskin = 0; - if (Person::players[closest]->whichskin > 2 && Person::players[closest]->creature == wolftype) + } + if (Person::players[closest]->whichskin > 2 && Person::players[closest]->creature == wolftype) { Person::players[closest]->whichskin = 0; + } Person::players[closest]->skeleton.drawmodel.textureptr.load(creatureskin[Person::players[closest]->creature][Person::players[closest]->whichskin], 1, &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize); @@ -1125,11 +1159,12 @@ void doDevKeys() for (unsigned i = 1; i < Person::players.size(); i++) { float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords); - if (!Person::players[i]->headless) + if (!Person::players[i]->headless) { if (distance < closestdist) { closestdist = distance; closest = i; } + } } XYZ flatfacing2, flatvelocity2; @@ -1140,14 +1175,18 @@ void doDevKeys() //int i = Person::players[closest]->skeleton.jointlabels[head]; Joint& headjoint = Person::players[closest]->joint(head); for (unsigned k = 0; k < Person::players[closest]->skeleton.joints.size(); k++) { - if (!Person::players[closest]->skeleton.free) + if (!Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatvelocity2 = headjoint.velocity; - if (!Person::players[closest]->skeleton.free) + } + if (!Person::players[closest]->skeleton.free) { flatfacing2 = DoRotation(DoRotation(DoRotation(headjoint.position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatfacing2 = headjoint.position * Person::players[closest]->scale + Person::players[closest]->coords; + } flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; @@ -1162,8 +1201,9 @@ void doDevKeys() emit_sound_at(splattersound, blah); emit_sound_at(breaksound2, blah, 100.); - if (Person::players[closest]->skeleton.free == 2) + if (Person::players[closest]->skeleton.free == 2) { Person::players[closest]->skeleton.free = 0; + } Person::players[closest]->RagDoll(0); Person::players[closest]->dead = 2; Person::players[closest]->headless = 1; @@ -1184,14 +1224,18 @@ void doDevKeys() emit_sound_at(breaksound2, blah); for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { - if (!Person::players[closest]->skeleton.free) + if (!Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity; - if (!Person::players[closest]->skeleton.free) + } + if (!Person::players[closest]->skeleton.free) { flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords; + } flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; @@ -1201,14 +1245,18 @@ void doDevKeys() } for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { - if (!Person::players[closest]->skeleton.free) + if (!Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity; - if (!Person::players[closest]->skeleton.free) + } + if (!Person::players[closest]->skeleton.free) { flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords; + } flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; @@ -1217,14 +1265,18 @@ void doDevKeys() } for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { - if (!Person::players[closest]->skeleton.free) + if (!Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity; - if (!Person::players[closest]->skeleton.free) + } + if (!Person::players[closest]->skeleton.free) { flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords; + } flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; @@ -1233,14 +1285,18 @@ void doDevKeys() } for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { - if (!Person::players[closest]->skeleton.free) + if (!Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity; - if (!Person::players[closest]->skeleton.free) + } + if (!Person::players[closest]->skeleton.free) { flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords; - if (Person::players[closest]->skeleton.free) + } + if (Person::players[closest]->skeleton.free) { flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords; + } flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; @@ -1253,8 +1309,9 @@ void doDevKeys() if (int(j) != closest) { if (distsq(&Person::players[j]->coords, &Person::players[closest]->coords) < 25) { Person::players[j]->DoDamage((25 - distsq(&Person::players[j]->coords, &Person::players[closest]->coords)) * 60); - if (Person::players[j]->skeleton.free == 2) + if (Person::players[j]->skeleton.free == 2) { Person::players[j]->skeleton.free = 1; + } Person::players[j]->skeleton.longdead = 0; Person::players[j]->RagDoll(0); for (unsigned i = 0; i < Person::players[j]->skeleton.joints.size(); i++) { @@ -1298,8 +1355,9 @@ void doDevKeys() //skip level if (whichlevel != -2 && Input::isKeyPressed(SDL_SCANCODE_K) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !editorenabled) { targetlevel++; - if (targetlevel > numchallengelevels - 1) + if (targetlevel > numchallengelevels - 1) { targetlevel = 0; + } loading = 1; leveltime = 5; } @@ -1325,21 +1383,26 @@ void doDevKeys() scenecoords.x = Person::players[0]->coords.x; scenecoords.z = Person::players[0]->coords.z; scenecoords.y = Person::players[0]->coords.y - 3; - if (editortype == bushtype) + if (editortype == bushtype) { scenecoords.y = Person::players[0]->coords.y - .5; - if (editortype == firetype) + } + if (editortype == firetype) { scenecoords.y = Person::players[0]->coords.y - .5; + } float temprotat, temprotat2; temprotat = editoryaw; temprotat2 = editorpitch; - if (temprotat < 0 || editortype == bushtype) + if (temprotat < 0 || editortype == bushtype) { temprotat = Random() % 360; - if (temprotat2 < 0) + } + if (temprotat2 < 0) { temprotat2 = Random() % 360; + } Object::MakeObject(editortype, scenecoords, (int)temprotat - ((int)temprotat) % 30, (int)temprotat2, editorsize); - if (editortype == treetrunktype) + if (editortype == treetrunktype) { Object::MakeObject(treeleavestype, scenecoords, Random() % 360 * (temprotat2 < 2) + (int)editoryaw - ((int)editoryaw) % 30, editorpitch, editorsize); + } } } @@ -1451,13 +1514,14 @@ void doDevKeys() if (numpathpoints < 30) { bool connected, alreadyconnected; connected = 0; - if (numpathpoints > 1) + if (numpathpoints > 1) { for (int i = 0; i < numpathpoints; i++) { if (distsq(&pathpoint[i], &Person::players[0]->coords) < .5 && i != pathpointselected && !connected) { alreadyconnected = 0; for (int j = 0; j < numpathpointconnect[pathpointselected]; j++) { - if (pathpointconnect[pathpointselected][j] == i) + if (pathpointconnect[pathpointselected][j] == i) { alreadyconnected = 1; + } } if (!alreadyconnected) { numpathpointconnect[pathpointselected]++; @@ -1466,6 +1530,7 @@ void doDevKeys() } } } + } if (!connected) { numpathpoints++; pathpoint[numpathpoints - 1] = Person::players[0]->coords; @@ -1481,14 +1546,16 @@ void doDevKeys() if (Input::isKeyPressed(SDL_SCANCODE_PERIOD)) { pathpointselected++; - if (pathpointselected >= numpathpoints) + if (pathpointselected >= numpathpoints) { pathpointselected = -1; + } } if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { pathpointselected--; - if (pathpointselected <= -2) + if (pathpointselected <= -2) { pathpointselected = numpathpoints - 1; + } } if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { @@ -1516,24 +1583,29 @@ void doDevKeys() if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editortype--; - if (editortype == treeleavestype || editortype == 10) + if (editortype == treeleavestype || editortype == 10) { editortype--; - if (editortype < 0) + } + if (editortype < 0) { editortype = firetype; + } } if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editortype++; - if (editortype == treeleavestype || editortype == 10) + if (editortype == treeleavestype || editortype == 10) { editortype++; - if (editortype > firetype) + } + if (editortype > firetype) { editortype = 0; + } } if (Input::isKeyDown(SDL_SCANCODE_LEFT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editoryaw -= multiplier * 100; - if (editoryaw < -.01) + if (editoryaw < -.01) { editoryaw = -.01; + } } if (Input::isKeyDown(SDL_SCANCODE_RIGHT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { @@ -1546,8 +1618,9 @@ void doDevKeys() if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editorsize -= multiplier; - if (editorsize < .1) + if (editorsize < .1) { editorsize = .1; + } } if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { @@ -1564,8 +1637,9 @@ void doDevKeys() if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editorpitch -= multiplier * 100; - if (editorpitch < -.01) + if (editorpitch < -.01) { editorpitch = -.01; + } } if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Object::objects.size() && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { @@ -1628,8 +1702,9 @@ void doJumpReversals() Person::players[i]->coords = Person::players[k]->coords; Person::players[k]->targetyaw = Person::players[i]->targetyaw; Person::players[k]->yaw = Person::players[i]->targetyaw; - if (Person::players[k]->aitype == attacktypecutoff) + if (Person::players[k]->aitype == attacktypecutoff) { Person::players[k]->stunned = .5; + } } if (Person::players[k]->animTarget == jumpupanim && Person::players[i]->animTarget != getupfrombackanim && @@ -1667,8 +1742,9 @@ void doJumpReversals() Person::players[k]->coords = Person::players[i]->coords; Person::players[i]->targetyaw = Person::players[k]->targetyaw; Person::players[i]->yaw = Person::players[k]->targetyaw; - if (Person::players[i]->aitype == attacktypecutoff) + if (Person::players[i]->aitype == attacktypecutoff) { Person::players[i]->stunned = .5; + } } } } @@ -1714,8 +1790,9 @@ void doAerialAcrobatics() } Person::players[k]->DoStuff(); - if (Person::players[k]->immobile && k != 0) + if (Person::players[k]->immobile && k != 0) { Person::players[k]->coords = Person::players[k]->realoldcoords; + } //if player's position has changed (?) if (distsq(&Person::players[k]->coords, &Person::players[k]->realoldcoords) > 0 && @@ -1726,10 +1803,12 @@ void doAerialAcrobatics() int whichhit; bool tempcollide = 0; - if (Person::players[k]->collide < -.3) + if (Person::players[k]->collide < -.3) { Person::players[k]->collide = -.3; - if (Person::players[k]->collide > 1) + } + if (Person::players[k]->collide > 1) { Person::players[k]->collide = 1; + } Person::players[k]->collide -= multiplier * 30; //clip to terrain @@ -1743,13 +1822,15 @@ void doAerialAcrobatics() lowpoint = Person::players[k]->coords; if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim && - !Person::players[k]->isFlip()) + !Person::players[k]->isFlip()) { lowpoint.y += 1.25; - else + } else { lowpoint.y += 1.3; + } if (Person::players[k]->coords.y < terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) && - Person::players[k]->coords.y > terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) - .1) + Person::players[k]->coords.y > terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) - .1) { Person::players[k]->coords.y = terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z); + } if (Person::players[k]->SphereCheck(&lowpoint, 1.3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) { flatfacing = lowpoint - Person::players[k]->coords; Person::players[k]->coords = lowpoint; @@ -1770,17 +1851,20 @@ void doAerialAcrobatics() if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) { Person::players[k]->setTargetAnimation(walljumpleftanim); emit_sound_at(movewhooshsound, Person::players[k]->coords); - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; - if (k == 0) + if (k == 0) { numwallflipped++; + } } else { lowpoint = tempcoords1; lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, 90, 0) * 1.5; @@ -1788,17 +1872,20 @@ void doAerialAcrobatics() if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) { Person::players[k]->setTargetAnimation(walljumprightanim); emit_sound_at(movewhooshsound, Person::players[k]->coords); - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; - if (k == 0) + if (k == 0) { numwallflipped++; + } } else { lowpoint = tempcoords1; lowpointtarget = lowpoint + Person::players[k]->facing * 2; @@ -1806,17 +1893,20 @@ void doAerialAcrobatics() if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) { Person::players[k]->setTargetAnimation(walljumpbackanim); emit_sound_at(movewhooshsound, Person::players[k]->coords); - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; - if (k == 0) + if (k == 0) { numwallflipped++; + } } else { lowpoint = tempcoords1; lowpointtarget = lowpoint - Person::players[k]->facing * 2; @@ -1824,18 +1914,21 @@ void doAerialAcrobatics() if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) { Person::players[k]->setTargetAnimation(walljumpfrontanim); emit_sound_at(movewhooshsound, Person::players[k]->coords); - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->yaw += 180; Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; - if (k == 0) + if (k == 0) { numwallflipped++; + } } } } @@ -1853,8 +1946,9 @@ void doAerialAcrobatics() if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) { //flipped into a rock - if (Person::players[k]->isFlip() && Person::players[k]->targetFrame().label == 7) + if (Person::players[k]->isFlip() && Person::players[k]->targetFrame().label == 7) { Person::players[k]->RagDoll(0); + } if (Person::players[k]->animTarget == jumpupanim) { Person::players[k]->jumppower = -4; @@ -1871,8 +1965,9 @@ void doAerialAcrobatics() //landing if ((Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) && !Person::players[k]->wasLanding()) { - if (Person::players[k]->isFlip()) + if (Person::players[k]->isFlip()) { Person::players[k]->jumppower = -4; + } Person::players[k]->animTarget = Person::players[k]->getLanding(); emit_sound_at(landsound, Person::players[k]->coords, 128.); if (k == 0) { @@ -1884,17 +1979,18 @@ void doAerialAcrobatics() } } - if (tempcollide) + if (tempcollide) { for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) { int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l]; lowpoint = Person::players[k]->coords; lowpoint.y += 1.35; - if (Object::objects[i]->type != rocktype) + if (Object::objects[i]->type != rocktype) { if (Person::players[k]->SphereCheck(&lowpoint, 1.33, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) { if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim && - Person::players[k]->onterrain) + Person::players[k]->onterrain) { Person::players[k]->avoidcollided = 1; + } Person::players[k]->coords = lowpoint; Person::players[k]->coords.y -= 1.35; Person::players[k]->collide = 1; @@ -1943,12 +2039,13 @@ void doAerialAcrobatics() lowpointtarget6 += facing * .6; lowpointtarget7.y += 90 / 13; whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw); - if (Object::objects[i]->friction > .5) + if (Object::objects[i]->friction > .5) { if (whichhit != -1) { - if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim) + if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim) { Person::players[k]->collided = 1; - if (Object::checkcollide(lowpoint7, lowpointtarget7) == -1) - if (Object::checkcollide(lowpoint6, lowpointtarget6) == -1) + } + if (Object::checkcollide(lowpoint7, lowpointtarget7) == -1) { + if (Object::checkcollide(lowpoint6, lowpointtarget6) == -1) { if (Object::objects[i]->model.LineCheckPossible(&lowpoint2, &lowpointtarget2, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 && Object::objects[i]->model.LineCheckPossible(&lowpoint3, &lowpointtarget3, @@ -1956,15 +2053,16 @@ void doAerialAcrobatics() Object::objects[i]->model.LineCheckPossible(&lowpoint4, &lowpointtarget4, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 && Object::objects[i]->model.LineCheckPossible(&lowpoint5, &lowpointtarget5, - &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) + &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) { for (int j = 0; j < 45; j++) { lowpoint = Person::players[k]->coords; lowpoint.y += (float)j / 13; lowpointtarget = lowpoint + facing * 1.4; if (Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint2, &Object::objects[i]->position, &Object::objects[i]->yaw) == -1) { - if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) + if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) { break; + } if (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim) { lowpoint = Person::players[k]->coords; lowpoint.y += (float)j / 13; @@ -1976,15 +2074,17 @@ void doAerialAcrobatics() if (j > 10 || !Person::players[k]->isRun()) { if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->animTarget == jumpupanim) { - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } } emit_sound_at(jumpsound, Person::players[k]->coords, 128.); lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; @@ -2010,11 +2110,17 @@ void doAerialAcrobatics() } } } + } + } + } } + } } } } + } } + } if (Person::players[k]->collide <= 0) { //in the air if (!Person::players[k]->onterrain && @@ -2031,12 +2137,14 @@ void doAerialAcrobatics() Person::players[k]->frameTarget < 2 || Person::players[k]->frameTarget > 6)) { //stagger off ledge (?) - if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim) + if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim) { Person::players[k]->RagDoll(0); + } Person::players[k]->setTargetAnimation(jumpdownanim); - if (!k) + if (!k) { emit_sound_at(whooshsound, Person::players[k]->coords, 128.); + } } //gravity Person::players[k]->velocity.y += gravity; @@ -2052,14 +2160,18 @@ void doAttacks() static int randattack; static bool playerrealattackkeydown = 0; - if (!Input::isKeyDown(attackkey)) + if (!Input::isKeyDown(attackkey)) { oldattackkey = 0; - if (oldattackkey) + } + if (oldattackkey) { Person::players[0]->attackkeydown = 0; - if (oldattackkey) + } + if (oldattackkey) { playerrealattackkeydown = 0; - if (!oldattackkey) + } + if (!oldattackkey) { playerrealattackkeydown = Input::isKeyDown(attackkey); + } if ((Person::players[0]->parriedrecently <= 0 || Person::players[0]->weaponactive == -1) && (!oldattackkey || @@ -2067,8 +2179,9 @@ void doAttacks() Person::players[0]->lastattack != swordslashanim && Person::players[0]->lastattack != knifeslashstartanim && Person::players[0]->lastattack != staffhitanim && - Person::players[0]->lastattack != staffspinhitanim))) + Person::players[0]->lastattack != staffspinhitanim))) { Person::players[0]->attackkeydown = Input::isKeyDown(attackkey); + } if (Input::isKeyDown(attackkey) && !oldattackkey && !Person::players[0]->backkeydown) { @@ -2077,20 +2190,24 @@ void doAttacks() Person::players[k]->animTarget == staffhitanim || Person::players[k]->animTarget == staffspinhitanim) && Person::players[0]->animCurrent != dodgebackanim && - !Person::players[k]->skeleton.free) + !Person::players[k]->skeleton.free) { Person::players[k]->Reverse(); + } } } - if (!hostile || Dialog::inDialog()) + if (!hostile || Dialog::inDialog()) { Person::players[0]->attackkeydown = 0; + } for (unsigned k = 0; k < Person::players.size(); k++) { - if (Dialog::inDialog()) + if (Dialog::inDialog()) { Person::players[k]->attackkeydown = 0; + } if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) { - if (Person::players[k]->aitype != playercontrolled) + if (Person::players[k]->aitype != playercontrolled) { Person::players[k]->victim = Person::players[0]; + } //attack key pressed if (Person::players[k]->attackkeydown) { //dodge backward @@ -2104,27 +2221,32 @@ void doAttacks() Person::players[k]->jumppower -= 2; } else { for (unsigned i = 0; i < Person::players.size(); i++) { - if (i == k) + if (i == k) { continue; + } if (Person::players[i]->animTarget == swordslashanim || Person::players[i]->animTarget == knifeslashstartanim || Person::players[i]->animTarget == staffhitanim || - Person::players[i]->animTarget == staffspinhitanim) + Person::players[i]->animTarget == staffspinhitanim) { if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < 6.5 && !Person::players[i]->skeleton.free) { Person::players[k]->setTargetAnimation(dodgebackanim); Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords); Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords); } + } } if (Person::players[k]->animTarget != dodgebackanim) { - if (k == 0) + if (k == 0) { numflipped++; + } Person::players[k]->setTargetAnimation(backhandspringanim); Person::players[k]->targetyaw = -yaw + 180; - if (Person::players[k]->leftkeydown) + if (Person::players[k]->leftkeydown) { Person::players[k]->targetyaw -= 45; - if (Person::players[k]->rightkeydown) + } + if (Person::players[k]->rightkeydown) { Person::players[k]->targetyaw += 45; + } Person::players[k]->yaw = Person::players[k]->targetyaw; Person::players[k]->jumppower -= 2; } @@ -2141,11 +2263,12 @@ void doAttacks() const int attackweapon = Person::players[k]->weaponactive == -1 ? 0 : weapons[Person::players[k]->weaponids[Person::players[k]->weaponactive]].getType(); //normal attacks (?) Person::players[k]->hasvictim = 0; - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned i = 0; i < Person::players.size(); i++) { - if (i == k || !(k == 0 || i == 0)) + if (i == k || !(k == 0 || i == 0)) { continue; - if (!Person::players[k]->hasvictim) + } + if (!Person::players[k]->hasvictim) { if (Animation::animations[Person::players[k]->animTarget].attack != reversal) { //choose an attack const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords); @@ -2168,146 +2291,150 @@ void doAttacks() //sweep if (distance < 2.5 * sq(Person::players[k]->scale * 5) && Person::players[k]->crouchkeydown && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = sweepanim; - //winduppunch - else if (distance < 1.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->forwardkeydown && - !Person::players[k]->leftkeydown && - !Person::players[k]->rightkeydown && - !Person::players[k]->crouchkeydown && - !attackweapon && - !reversaltrain) + //winduppunch + } else if (distance < 1.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->forwardkeydown && + !Person::players[k]->leftkeydown && + !Person::players[k]->rightkeydown && + !Person::players[k]->crouchkeydown && + !attackweapon && + !reversaltrain) { Person::players[k]->animTarget = winduppunchanim; - //upunch - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->forwardkeydown && - !Person::players[k]->leftkeydown && - !Person::players[k]->rightkeydown && - !Person::players[k]->crouchkeydown && - !attackweapon) + //upunch + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->forwardkeydown && + !Person::players[k]->leftkeydown && + !Person::players[k]->rightkeydown && + !Person::players[k]->crouchkeydown && + !attackweapon) { Person::players[k]->animTarget = upunchanim; - //knifefollow - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Person::players[i]->staggerdelay > 0 && - attackweapon == knife && - Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) + //knifefollow + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Person::players[i]->staggerdelay > 0 && + attackweapon == knife && + Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) { Person::players[k]->animTarget = knifefollowanim; - //knifeslashstart - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->forwardkeydown && - !Person::players[k]->leftkeydown && - !Person::players[k]->rightkeydown && - !Person::players[k]->crouchkeydown && - attackweapon == knife && - Person::players[k]->weaponmissdelay <= 0) + //knifeslashstart + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->forwardkeydown && + !Person::players[k]->leftkeydown && + !Person::players[k]->rightkeydown && + !Person::players[k]->crouchkeydown && + attackweapon == knife && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = knifeslashstartanim; - //swordslash - else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->crouchkeydown && - attackweapon == sword && - Person::players[k]->weaponmissdelay <= 0) + //swordslash + } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->crouchkeydown && + attackweapon == sword && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = swordslashanim; - //staffhit - else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->crouchkeydown && - attackweapon == staff && - Person::players[k]->weaponmissdelay <= 0 && - !Person::players[k]->leftkeydown && - !Person::players[k]->rightkeydown && - !Person::players[k]->forwardkeydown) + //staffhit + } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->crouchkeydown && + attackweapon == staff && + Person::players[k]->weaponmissdelay <= 0 && + !Person::players[k]->leftkeydown && + !Person::players[k]->rightkeydown && + !Person::players[k]->forwardkeydown) { Person::players[k]->animTarget = staffhitanim; - //staffspinhit - else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->crouchkeydown && - attackweapon == staff && - Person::players[k]->weaponmissdelay <= 0) + //staffspinhit + } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->crouchkeydown && + attackweapon == staff && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = staffspinhitanim; - //spinkick - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + //spinkick + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = spinkickanim; - //lowkick - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height == lowheight && - Animation::animations[Person::players[k]->animTarget].attack != normalattack) + //lowkick + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height == lowheight && + Animation::animations[Person::players[k]->animTarget].attack != normalattack) { Person::players[k]->animTarget = lowkickanim; + } } else { //AI player if (distance < 4.5 * sq(Person::players[k]->scale * 5)) { randattack = abs(Random() % 5); if (!attackweapon && distance < 2.5 * sq(Person::players[k]->scale * 5)) { //sweep - if (randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight) + if (randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = sweepanim; - //upunch - else if (randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight && - !attackweapon) + //upunch + } else if (randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight && + !attackweapon) { Person::players[k]->animTarget = upunchanim; - //spinkick - else if (randattack == 2 && Animation::animations[Person::players[i]->animTarget].height != lowheight) + //spinkick + } else if (randattack == 2 && Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = spinkickanim; - //lowkick - else if (Animation::animations[Person::players[i]->animTarget].height == lowheight) + //lowkick + } else if (Animation::animations[Person::players[i]->animTarget].height == lowheight) { Person::players[k]->animTarget = lowkickanim; + } } if (attackweapon) { //sweep if ((!Tutorial::active || !attackweapon) && distance < 2.5 * sq(Person::players[k]->scale * 5) && randattack == 0 && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = sweepanim; - //knifeslashstart - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - attackweapon == knife && - Person::players[k]->weaponmissdelay <= 0) + //knifeslashstart + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + attackweapon == knife && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = knifeslashstartanim; - //swordslash - else if (!(Person::players[0]->victim == Person::players[i] && - Person::players[0]->hasvictim && - Person::players[0]->animTarget == swordslashanim) && - attackweapon == sword && - Person::players[k]->weaponmissdelay <= 0) + //swordslash + } else if (!(Person::players[0]->victim == Person::players[i] && + Person::players[0]->hasvictim && + Person::players[0]->animTarget == swordslashanim) && + attackweapon == sword && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = swordslashanim; - //staffhit - else if (!(Person::players[0]->victim == Person::players[i] && - Person::players[0]->hasvictim && - Person::players[0]->animTarget == swordslashanim) && - attackweapon == staff && - Person::players[k]->weaponmissdelay <= 0 && - randattack < 3) + //staffhit + } else if (!(Person::players[0]->victim == Person::players[i] && + Person::players[0]->hasvictim && + Person::players[0]->animTarget == swordslashanim) && + attackweapon == staff && + Person::players[k]->weaponmissdelay <= 0 && + randattack < 3) { Person::players[k]->animTarget = staffhitanim; - //staffspinhit - else if (!(Person::players[0]->victim == Person::players[i] && - Person::players[0]->hasvictim && - Person::players[0]->animTarget == swordslashanim) && - attackweapon == staff && - Person::players[k]->weaponmissdelay <= 0 && - randattack >= 3) + //staffspinhit + } else if (!(Person::players[0]->victim == Person::players[i] && + Person::players[0]->hasvictim && + Person::players[0]->animTarget == swordslashanim) && + attackweapon == staff && + Person::players[k]->weaponmissdelay <= 0 && + randattack >= 3) { Person::players[k]->animTarget = staffspinhitanim; - //spinkick - else if ((!Tutorial::active || !attackweapon) && - distance < 2.5 * sq(Person::players[k]->scale * 5) && - randattack == 1 && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + //spinkick + } else if ((!Tutorial::active || !attackweapon) && + distance < 2.5 * sq(Person::players[k]->scale * 5) && + randattack == 1 && + Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = spinkickanim; - //lowkick - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height == lowheight && - Animation::animations[Person::players[k]->animTarget].attack != normalattack) + //lowkick + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height == lowheight && + Animation::animations[Person::players[k]->animTarget].attack != normalattack) { Person::players[k]->animTarget = lowkickanim; + } } } } //upunch becomes wolfslap - if (Person::players[k]->animTarget == upunchanim && Person::players[k]->creature == wolftype) + if (Person::players[k]->animTarget == upunchanim && Person::players[k]->creature == wolftype) { Person::players[k]->animTarget = wolfslapanim; + } } //sneak attacks if ((k == 0) && (!Tutorial::active || Tutorial::stage == 22) && @@ -2408,17 +2535,20 @@ void doAttacks() Person::players[i]->yaw = Person::players[k]->targetyaw; } } + } } + } const bool hasstaff = attackweapon == staff; - if (k == 0 && Person::players.size() > 1) + if (k == 0 && Person::players.size() > 1) { for (unsigned i = 0; i < Person::players.size(); i++) { - if (i == k) + if (i == k) { continue; + } if ((playerrealattackkeydown || Person::players[i]->dead || !hasstaff) && Animation::animations[Person::players[k]->animTarget].attack == neutral) { const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords); - if (!Person::players[i]->dead || !realthreat || (!attackweapon && Person::players[k]->crouchkeydown)) - if (Person::players[i]->skeleton.free) + if (!Person::players[i]->dead || !realthreat || (!attackweapon && Person::players[k]->crouchkeydown)) { + if (Person::players[i]->skeleton.free) { if (distance < 3.5 * sq(Person::players[k]->scale * 5) && (Person::players[i]->dead || Person::players[i]->skeleton.longdead > 1000 || @@ -2433,14 +2563,17 @@ void doAttacks() Person::players[k]->hasvictim = 1; if (attackweapon && !Tutorial::active) { //crouchstab - if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5)) + if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5)) { Person::players[k]->animTarget = crouchstabanim; + } //swordgroundstab - if (Person::players[k]->crouchkeydown && distance < 1.5 * sq(Person::players[k]->scale * 5) && attackweapon == sword) + if (Person::players[k]->crouchkeydown && distance < 1.5 * sq(Person::players[k]->scale * 5) && attackweapon == sword) { Person::players[k]->animTarget = swordgroundstabanim; + } //staffgroundsmash - if (distance < 3.5 * sq(Person::players[k]->scale * 5) && attackweapon == staff) + if (distance < 3.5 * sq(Person::players[k]->scale * 5) && attackweapon == staff) { Person::players[k]->animTarget = staffgroundsmashanim; + } } if (distance < 2.5 && Person::players[k]->crouchkeydown && @@ -2457,7 +2590,7 @@ void doAttacks() } } } - if (!Person::players[i]->dead || musictype != 2) + if (!Person::players[i]->dead || musictype != 2) { if (distance < 3.5 && (Person::players[k]->isRun() || Person::players[k]->isIdle() && Person::players[k]->attackkeydown) && Person::players[k]->staggerdelay <= 0 && @@ -2474,7 +2607,10 @@ void doAttacks() } } } + } } + } + } if (Animation::animations[Person::players[k]->animTarget].attack == normalattack && Person::players[k]->victim == Person::players[i] && (!Person::players[i]->skeleton.free || @@ -2503,8 +2639,9 @@ void doAttacks() Person::players[k]->targetyaw += (float)(abs(Random() % 100) - 50) / 4; } - if (Person::players[k]->animTarget == staffgroundsmashanim) + if (Person::players[k]->animTarget == staffgroundsmashanim) { Person::players[k]->targettilt2 += 10; + } Person::players[k]->lastattack3 = Person::players[k]->lastattack2; Person::players[k]->lastattack2 = Person::players[k]->lastattack; @@ -2516,16 +2653,19 @@ void doAttacks() } } } + } if (!Person::players[k]->hasvictim) { //find victim for (unsigned i = 0; i < Person::players.size(); i++) { - if (i == k || !(i == 0 || k == 0)) + if (i == k || !(i == 0 || k == 0)) { continue; + } if (!Person::players[i]->skeleton.free) { if (Person::players[k]->hasvictim) { if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < - distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords)) + distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords)) { Person::players[k]->victim = Person::players[i]; + } } else { Person::players[k]->victim = Person::players[i]; Person::players[k]->hasvictim = 1; @@ -2533,7 +2673,7 @@ void doAttacks() } } } - if (Person::players[k]->aitype == playercontrolled) + if (Person::players[k]->aitype == playercontrolled) { //rabbit kick if (Person::players[k]->attackkeydown && Person::players[k]->isRun() && @@ -2552,6 +2692,7 @@ void doAttacks() oldattackkey = 1; Person::players[k]->setTargetAnimation(rabbitkickanim); } + } //update counts if (Animation::animations[Person::players[k]->animTarget].attack && k == 0) { numattacks++; @@ -2580,23 +2721,23 @@ void doPlayerCollisions() { static XYZ rotatetarget; static float collisionradius; - if (Person::players.size() > 1) - for (unsigned k = 0; k < Person::players.size(); k++) + if (Person::players.size() > 1) { + for (unsigned k = 0; k < Person::players.size(); k++) { for (unsigned i = k + 1; i < Person::players.size(); i++) { //neither player is part of a reversal if ((Animation::animations[Person::players[i]->animTarget].attack != reversed && Animation::animations[Person::players[i]->animTarget].attack != reversal && Animation::animations[Person::players[k]->animTarget].attack != reversed && Animation::animations[Person::players[k]->animTarget].attack != reversal) || - (i != 0 && k != 0)) + (i != 0 && k != 0)) { if ((Animation::animations[Person::players[i]->animCurrent].attack != reversed && Animation::animations[Person::players[i]->animCurrent].attack != reversal && Animation::animations[Person::players[k]->animCurrent].attack != reversed && Animation::animations[Person::players[k]->animCurrent].attack != reversal) || - (i != 0 && k != 0)) + (i != 0 && k != 0)) { //neither is sleeping - if (Person::players[i]->howactive <= typesleeping && Person::players[k]->howactive <= typesleeping) - if (Person::players[i]->howactive != typesittingwall && Person::players[k]->howactive != typesittingwall) + if (Person::players[i]->howactive <= typesleeping && Person::players[k]->howactive <= typesleeping) { + if (Person::players[i]->howactive != typesittingwall && Person::players[k]->howactive != typesittingwall) { //in same patch, neither is climbing if (Person::players[i]->whichpatchx == Person::players[k]->whichpatchx && Person::players[i]->whichpatchz == Person::players[k]->whichpatchz && @@ -2605,34 +2746,40 @@ void doPlayerCollisions() Person::players[i]->animTarget != climbanim && Person::players[i]->animTarget != hanganim && Person::players[k]->animTarget != climbanim && - Person::players[k]->animTarget != hanganim) + Person::players[k]->animTarget != hanganim) { //players are close (bounding box test) - if (Person::players[i]->coords.y > Person::players[k]->coords.y - 3) - if (Person::players[i]->coords.y < Person::players[k]->coords.y + 3) - if (Person::players[i]->coords.x > Person::players[k]->coords.x - 3) - if (Person::players[i]->coords.x < Person::players[k]->coords.x + 3) - if (Person::players[i]->coords.z > Person::players[k]->coords.z - 3) + if (Person::players[i]->coords.y > Person::players[k]->coords.y - 3) { + if (Person::players[i]->coords.y < Person::players[k]->coords.y + 3) { + if (Person::players[i]->coords.x > Person::players[k]->coords.x - 3) { + if (Person::players[i]->coords.x < Person::players[k]->coords.x + 3) { + if (Person::players[i]->coords.z > Person::players[k]->coords.z - 3) { if (Person::players[i]->coords.z < Person::players[k]->coords.z + 3) { //spread fire from player to player if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 3 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) { if (Person::players[i]->onfire || Person::players[k]->onfire) { - if (!Person::players[i]->onfire) + if (!Person::players[i]->onfire) { Person::players[i]->CatchFire(); - if (!Person::players[k]->onfire) + } + if (!Person::players[k]->onfire) { Person::players[k]->CatchFire(); + } } } XYZ tempcoords1 = Person::players[i]->coords; XYZ tempcoords2 = Person::players[k]->coords; - if (!Person::players[i]->skeleton.oldfree) + if (!Person::players[i]->skeleton.oldfree) { tempcoords1.y += Person::players[i]->jointPos(abdomen).y * Person::players[i]->scale; - if (!Person::players[k]->skeleton.oldfree) + } + if (!Person::players[k]->skeleton.oldfree) { tempcoords2.y += Person::players[k]->jointPos(abdomen).y * Person::players[k]->scale; + } collisionradius = 1.2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5); - if (Person::players[0]->hasvictim) - if (Person::players[0]->animTarget == rabbitkickanim && (k == 0 || i == 0) && !Person::players[0]->victim->skeleton.free) + if (Person::players[0]->hasvictim) { + if (Person::players[0]->animTarget == rabbitkickanim && (k == 0 || i == 0) && !Person::players[0]->victim->skeleton.free) { collisionradius = 3; + } + } if ((!Person::players[i]->skeleton.oldfree || !Person::players[k]->skeleton.oldfree) && (distsq(&tempcoords1, &tempcoords2) < collisionradius || distsq(&Person::players[i]->coords, &Person::players[k]->coords) < collisionradius)) { @@ -2667,7 +2814,7 @@ void doPlayerCollisions() if ((Person::players[i]->animTarget != getupfrombackanim && Person::players[i]->animTarget != getupfromfrontanim || Person::players[i]->skeleton.free) && (Person::players[k]->animTarget != getupfrombackanim && Person::players[k]->animTarget != getupfromfrontanim || - Person::players[k]->skeleton.free)) + Person::players[k]->skeleton.free)) { if ((((k != 0 && findLengthfast(&rotatetarget) > 150 || k == 0 && findLengthfast(&rotatetarget) > 50 && Person::players[0]->rabbitkickragdoll) && normaldotproduct(rotatetarget, Person::players[k]->coords - Person::players[i]->coords) > 0) && @@ -2705,6 +2852,7 @@ void doPlayerCollisions() } } } + } if ((Animation::animations[Person::players[i]->animTarget].attack == neutral || Animation::animations[Person::players[i]->animTarget].attack == normalattack) && (Animation::animations[Person::players[k]->animTarget].attack == neutral || @@ -2717,24 +2865,30 @@ void doPlayerCollisions() Person::players[k]->coords = (Person::players[k]->coords + Person::players[i]->coords) / 2; Person::players[i]->coords = Person::players[k]->coords - rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5); Person::players[k]->coords += rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5); - if (Person::players[k]->howactive == typeactive || hostile) + if (Person::players[k]->howactive == typeactive || hostile) { if (Person::players[k]->isIdle()) { - if (Person::players[k]->howactive < typesleeping) + if (Person::players[k]->howactive < typesleeping) { Person::players[k]->setTargetAnimation(Person::players[k]->getStop()); - else if (Person::players[k]->howactive == typesleeping) + } else if (Person::players[k]->howactive == typesleeping) { Person::players[k]->setTargetAnimation(getupfromfrontanim); - if (!editorenabled) + } + if (!editorenabled) { Person::players[k]->howactive = typeactive; + } } - if (Person::players[i]->howactive == typeactive || hostile) + } + if (Person::players[i]->howactive == typeactive || hostile) { if (Person::players[i]->isIdle()) { - if (Person::players[i]->howactive < typesleeping) + if (Person::players[i]->howactive < typesleeping) { Person::players[i]->setTargetAnimation(Person::players[k]->getStop()); - else + } else { Person::players[i]->setTargetAnimation(getupfromfrontanim); - if (!editorenabled) + } + if (!editorenabled) { Person::players[i]->howactive = typeactive; + } } + } } //jump down on player if (hostile) { @@ -2775,7 +2929,19 @@ void doPlayerCollisions() Person::players[k]->CheckKick(); } } + } + } + } + } + } + } + } + } + } + } } + } + } } void Game::Tick() @@ -2786,30 +2952,34 @@ void Game::Tick() Input::Tick(); if (Input::isKeyPressed(SDL_SCANCODE_F6)) { - if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) + if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { stereoreverse = true; - else + } else { stereoreverse = false; + } - if (stereoreverse) + if (stereoreverse) { printf("Stereo reversed\n"); - else + } else { printf("Stereo unreversed\n"); + } } if (Input::isKeyDown(SDL_SCANCODE_F7)) { - if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) + if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { stereoseparation -= 0.001; - else + } else { stereoseparation -= 0.010; + } printf("Stereo decreased increased to %f\n", stereoseparation); } if (Input::isKeyDown(SDL_SCANCODE_F8)) { - if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) + if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { stereoseparation += 0.001; - else + } else { stereoseparation += 0.010; + } printf("Stereo separation increased to %f\n", stereoseparation); } @@ -2838,8 +3008,9 @@ void Game::Tick() if (!console) { //campaign over? - if (mainmenu && endgame == 1) + if (mainmenu && endgame == 1) { mainmenu = 10; + } //go to level select after completing a campaign level if (campaign && winfreeze && mainmenu == 0 && campaignlevels[actuallevel].choosenext == 1) { mainmenu = 5; @@ -2858,9 +3029,9 @@ void Game::Tick() if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) && (gameon || mainmenu == 0)) { selected = -1; - if (mainmenu == 0 && !winfreeze) + if (mainmenu == 0 && !winfreeze) { mainmenu = 2; //pause - else if (mainmenu == 1 || mainmenu == 2) { + } else if (mainmenu == 1 || mainmenu == 2) { mainmenu = 0; //unpause } //play menu theme @@ -2882,12 +3053,14 @@ void Game::Tick() } if (!mainmenu) { - if (hostile == 1) + if (hostile == 1) { hostiletime += multiplier; - else + } else { hostiletime = 0; - if (!winfreeze) + } + if (!winfreeze) { leveltime += multiplier; + } //keys if (Input::isKeyDown(SDL_SCANCODE_LALT) && Input::isKeyPressed(SDL_SCANCODE_V) && devtools) { @@ -2907,8 +3080,9 @@ void Game::Tick() } } - if (console) + if (console) { freeze = 1; + } if (console && !Input::isKeyDown(SDL_SCANCODE_LGUI)) { inputText(consoletext[0], &consoleselected); if (!waiting) { @@ -2934,14 +3108,17 @@ void Game::Tick() OPENAL_SetFrequency(OPENAL_ALL); emit_sound_np(consolesuccesssound); } - if (winfreeze == 0) + if (winfreeze == 0) { oldwinfreeze = winfreeze; - else + } else { oldwinfreeze++; + } - if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE)) && !campaign) - if (winfreeze) + if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE)) && !campaign) { + if (winfreeze) { winfreeze = 0; + } + } if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && !campaign && gameon) { if (console) { console = false; @@ -2957,8 +3134,9 @@ void Game::Tick() //dialogues static float talkdelay = 0; - if (Dialog::inDialog()) + if (Dialog::inDialog()) { talkdelay = 1; + } talkdelay -= multiplier; if (talkdelay <= 0 && !Dialog::inDialog() && Animation::animations[Person::players[0]->animTarget].height != highheight) { @@ -3023,12 +3201,14 @@ void Game::Tick() bonus != twoxcombo && bonus != threexcombo && bonus != fourxcombo && - bonus != megacombo) + bonus != megacombo) { bonusnum[bonus]++; - else + } else { bonusnum[bonus] += 0.15; - if (Tutorial::active) + } + if (Tutorial::active) { bonusvalue = 0; + } bonusvalue /= bonusnum[bonus]; bonustotal += bonusvalue; } @@ -3039,8 +3219,9 @@ void Game::Tick() precipdelay -= multiplier; while (precipdelay < 0) { precipdelay += .04; - if (!detail) + if (!detail) { precipdelay += .04; + } XYZ footvel, footpoint; footvel = 0; @@ -3077,8 +3258,9 @@ void Game::Tick() Person::players[0]->throwkeydown = 0; } - if (!Person::players[0]->jumpkeydown) + if (!Person::players[0]->jumpkeydown) { Person::players[0]->jumpclimb = 0; + } if (Dialog::inDialog()) { cameramode = 1; @@ -3094,18 +3276,24 @@ void Game::Tick() flatfacing = DoRotation(flatfacing, 0, -yaw, 0); - if (Input::isKeyDown(forwardkey)) + if (Input::isKeyDown(forwardkey)) { viewer += facing * multiplier * 4; - if (Input::isKeyDown(backkey)) + } + if (Input::isKeyDown(backkey)) { viewer -= facing * multiplier * 4; - if (Input::isKeyDown(leftkey)) + } + if (Input::isKeyDown(leftkey)) { viewer += DoRotation(flatfacing * multiplier, 0, 90, 0) * 4; - if (Input::isKeyDown(rightkey)) + } + if (Input::isKeyDown(rightkey)) { viewer += DoRotation(flatfacing * multiplier, 0, -90, 0) * 4; - if (Input::isKeyDown(jumpkey)) + } + if (Input::isKeyDown(jumpkey)) { viewer.y += multiplier * 4; - if (Input::isKeyDown(crouchkey)) + } + if (Input::isKeyDown(crouchkey)) { viewer.y -= multiplier * 4; + } if (Input::isKeyPressed(SDL_SCANCODE_1) || Input::isKeyPressed(SDL_SCANCODE_2) || Input::isKeyPressed(SDL_SCANCODE_3) || @@ -3118,28 +3306,39 @@ void Game::Tick() Input::isKeyPressed(SDL_SCANCODE_0) || Input::isKeyPressed(SDL_SCANCODE_MINUS)) { int whichend; - if (Input::isKeyPressed(SDL_SCANCODE_1)) + if (Input::isKeyPressed(SDL_SCANCODE_1)) { whichend = 1; - if (Input::isKeyPressed(SDL_SCANCODE_2)) + } + if (Input::isKeyPressed(SDL_SCANCODE_2)) { whichend = 2; - if (Input::isKeyPressed(SDL_SCANCODE_3)) + } + if (Input::isKeyPressed(SDL_SCANCODE_3)) { whichend = 3; - if (Input::isKeyPressed(SDL_SCANCODE_4)) + } + if (Input::isKeyPressed(SDL_SCANCODE_4)) { whichend = 4; - if (Input::isKeyPressed(SDL_SCANCODE_5)) + } + if (Input::isKeyPressed(SDL_SCANCODE_5)) { whichend = 5; - if (Input::isKeyPressed(SDL_SCANCODE_6)) + } + if (Input::isKeyPressed(SDL_SCANCODE_6)) { whichend = 6; - if (Input::isKeyPressed(SDL_SCANCODE_7)) + } + if (Input::isKeyPressed(SDL_SCANCODE_7)) { whichend = 7; - if (Input::isKeyPressed(SDL_SCANCODE_8)) + } + if (Input::isKeyPressed(SDL_SCANCODE_8)) { whichend = 8; - if (Input::isKeyPressed(SDL_SCANCODE_9)) + } + if (Input::isKeyPressed(SDL_SCANCODE_9)) { whichend = 9; - if (Input::isKeyPressed(SDL_SCANCODE_0)) + } + if (Input::isKeyPressed(SDL_SCANCODE_0)) { whichend = 0; - if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) + } + if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) { whichend = -1; + } if (whichend != -1) { Dialog::currentScene().participantfocus = whichend; Dialog::currentDialog().participantlocation[whichend] = Person::players[whichend]->coords; @@ -3180,26 +3379,36 @@ void Game::Tick() Input::isKeyDown(SDL_SCANCODE_KP_9) || Input::isKeyDown(SDL_SCANCODE_KP_0)) { int whichend; - if (Input::isKeyDown(SDL_SCANCODE_KP_1)) + if (Input::isKeyDown(SDL_SCANCODE_KP_1)) { whichend = 1; - if (Input::isKeyDown(SDL_SCANCODE_KP_2)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_2)) { whichend = 2; - if (Input::isKeyDown(SDL_SCANCODE_KP_3)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_3)) { whichend = 3; - if (Input::isKeyDown(SDL_SCANCODE_KP_4)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_4)) { whichend = 4; - if (Input::isKeyDown(SDL_SCANCODE_KP_5)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_5)) { whichend = 5; - if (Input::isKeyDown(SDL_SCANCODE_KP_6)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_6)) { whichend = 6; - if (Input::isKeyDown(SDL_SCANCODE_KP_7)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_7)) { whichend = 7; - if (Input::isKeyDown(SDL_SCANCODE_KP_8)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_8)) { whichend = 8; - if (Input::isKeyDown(SDL_SCANCODE_KP_9)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_9)) { whichend = 9; - if (Input::isKeyDown(SDL_SCANCODE_KP_0)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_0)) { whichend = 0; + } Dialog::currentScene().participantfacing[whichend] = facing; } if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) { @@ -3262,8 +3471,9 @@ void Game::Tick() if (Person::players[0]->jumpkeydown && Person::players[0]->animTarget != jumpupanim && Person::players[0]->animTarget != jumpdownanim && - !Person::players[0]->isFlip()) + !Person::players[0]->isFlip()) { Person::players[0]->jumptogglekeydown = 1; + } Dialog::dialoguetime += multiplier; hawkyaw += multiplier * 25; @@ -3286,9 +3496,11 @@ void Game::Tick() doJumpReversals(); - for (unsigned k = 0; k < Person::players.size(); k++) - if (k != 0 && Person::players[k]->immobile) + for (unsigned k = 0; k < Person::players.size(); k++) { + if (k != 0 && Person::players[k]->immobile) { Person::players[k]->coords = Person::players[k]->realoldcoords; + } + } for (unsigned k = 0; k < Person::players.size(); k++) { if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) { @@ -3333,10 +3545,11 @@ void Game::Tick() Person::players[0]->animTarget != dodgebackanim && Person::players[0]->animTarget != walljumprightkickanim && Person::players[0]->animTarget != walljumpleftkickanim) { - if (cameramode) + if (cameramode) { Person::players[0]->targetyaw = 0; - else + } else { Person::players[0]->targetyaw = -yaw + 180; + } } facing = 0; @@ -3384,15 +3597,16 @@ void Game::Tick() Person::players[i]->targetheadpitch = pitchOf(Dialog::currentScene().participantfacing[i]); } - if (leveltime < .5) + if (leveltime < .5) { numenvsounds = 0; + } Person::players[i]->avoidsomething = 0; //avoid flaming things - for (unsigned int j = 0; j < Object::objects.size(); j++) - if (Object::objects[j]->onfire) - if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < sq(Object::objects[j]->scale) * 200) + for (unsigned int j = 0; j < Object::objects.size(); j++) { + if (Object::objects[j]->onfire) { + if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < sq(Object::objects[j]->scale) * 200) { if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < distsq(&Person::players[i]->coords, &Person::players[0]->coords)) { Person::players[i]->collided = 0; @@ -3404,11 +3618,14 @@ void Game::Tick() Person::players[i]->avoidsomething = 1; } } + } + } + } //avoid flaming players - for (unsigned j = 0; j < Person::players.size(); j++) - if (Person::players[j]->onfire) - if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < sq(0.3) * 200) + for (unsigned j = 0; j < Person::players.size(); j++) { + if (Person::players[j]->onfire) { + if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < sq(0.3) * 200) { if (distsq(&Person::players[i]->coords, &Person::players[j]->coords) < distsq(&Person::players[i]->coords, &Person::players[0]->coords)) { Person::players[i]->collided = 0; @@ -3420,9 +3637,13 @@ void Game::Tick() Person::players[i]->avoidsomething = 1; } } + } + } + } - if (Person::players[i]->collided > .8) + if (Person::players[i]->collided > .8) { Person::players[i]->avoidcollided = 0; + } Person::players[i]->doAI(); @@ -3449,10 +3670,12 @@ void Game::Tick() Person::players[i]->throwkeydown = 0; } - if (Person::players[i]->collided < -.3) + if (Person::players[i]->collided < -.3) { Person::players[i]->collided = -.3; - if (Person::players[i]->collided > 1) + } + if (Person::players[i]->collided > 1) { Person::players[i]->collided = 1; + } Person::players[i]->collided -= multiplier * 4; Person::players[i]->whichdirectiondelay -= multiplier; if (Person::players[i]->avoidcollided < -.3 || Person::players[i]->whichdirectiondelay <= 0) { @@ -3460,8 +3683,9 @@ void Game::Tick() Person::players[i]->whichdirection = abs(Random() % 2); Person::players[i]->whichdirectiondelay = .4; } - if (Person::players[i]->avoidcollided > 1) + if (Person::players[i]->avoidcollided > 1) { Person::players[i]->avoidcollided = 1; + } Person::players[i]->avoidcollided -= multiplier / 4; if (!Person::players[i]->skeleton.free) { Person::players[i]->stunned -= multiplier; @@ -3471,11 +3695,13 @@ void Game::Tick() Person::players[i]->aitype == attacktypecutoff && !Person::players[i]->dead && !Person::players[i]->skeleton.free && - Animation::animations[Person::players[i]->animTarget].attack == neutral) + Animation::animations[Person::players[i]->animTarget].attack == neutral) { numresponded = 1; + } - if (!Person::players[i]->throwkeydown) + if (!Person::players[i]->throwkeydown) { Person::players[i]->throwtogglekeydown = 0; + } //pick up weapon if (Person::players[i]->throwkeydown && !Person::players[i]->throwtogglekeydown) { @@ -3492,7 +3718,7 @@ void Game::Tick() if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 || Person::players[i]->aitype == playercontrolled) && weapons[j].owner == -1 && - Person::players[i]->weaponactive == -1) + Person::players[i]->weaponactive == -1) { if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2) { if (distsq(&Person::players[i]->coords, &weapons[j].position) < 2) { if (Person::players[i]->isCrouch() || @@ -3513,14 +3739,17 @@ void Game::Tick() Person::players[i]->aitype == playercontrolled) && weapons[j].owner == -1 || Person::players[i]->victim && - weapons[j].owner == int(Person::players[i]->victim->id)) - if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && Person::players[i]->weaponactive == -1) + weapons[j].owner == int(Person::players[i]->victim->id)) { + if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && Person::players[i]->weaponactive == -1) { if (distsq(&Person::players[i]->coords, &weapons[j].position) < 1 || Person::players[i]->victim) { - if (weapons[j].getType() != staff) + if (weapons[j].getType() != staff) { emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); + } Person::players[i]->takeWeapon(j); } + } + } } } else if ((Person::players[i]->isIdle() || Person::players[i]->isFlip() || @@ -3537,33 +3766,37 @@ void Game::Tick() Person::players[i]->hasvictim = 0; for (unsigned k = 0; k < weapons.size(); k++) { - if (Person::players[i]->weaponactive == -1) + if (Person::players[i]->weaponactive == -1) { if ((weapons[k].velocity.x == 0 && weapons[k].velocity.y == 0 && weapons[k].velocity.z == 0 || Person::players[i]->aitype == playercontrolled) && weapons[k].owner == -1 || Person::players[i]->victim && - weapons[k].owner == int(Person::players[i]->victim->id)) + weapons[k].owner == int(Person::players[i]->victim->id)) { if (distsqflat(&Person::players[i]->coords, &weapons[k].position) < 3 && Person::players[i]->weaponactive == -1) { - if (weapons[k].getType() != staff) + if (weapons[k].getType() != staff) { emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); + } Person::players[i]->takeWeapon(k); } + } + } } } } } + } } if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim || Person::players[i]->isRun() || Person::players[i]->isIdle() || Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) { - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { - if (Person::players[i]->weaponactive == -1) - if (j != i) + if (Person::players[i]->weaponactive == -1) { + if (j != i) { if (Person::players[j]->num_weapons && Person::players[j]->skeleton.free && distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 2 /*&&Person::players[j]->dead*/ && @@ -3594,17 +3827,20 @@ void Game::Tick() } } if (!fleshstuck) { - if (weapons[k].getType() != staff) + if (weapons[k].getType() != staff) { emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); + } } - if (fleshstuck) + if (fleshstuck) { emit_sound_at(fleshstabremovesound, Person::players[i]->coords, 128.); + } if (weapons[k].owner != -1) { - if (Person::players[i]->victim->num_weapons == 1) + if (Person::players[i]->victim->num_weapons == 1) { Person::players[i]->victim->num_weapons = 0; - else + } else { Person::players[i]->victim->num_weapons = 1; + } Person::players[i]->victim->skeleton.longdead = 0; Person::players[i]->victim->skeleton.free = 1; @@ -3624,8 +3860,9 @@ void Game::Tick() footpoint = weapons[k].position; if (Person::players[i]->victim->weaponstuck != -1) { if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) { - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3); + } weapons[k].bloody = 2; weapons[k].blooddrip = 5; Person::players[i]->victim->weaponstuck = -1; @@ -3634,10 +3871,12 @@ void Game::Tick() } } if (Person::players[i]->victim->num_weapons > 0) { - if (Person::players[i]->victim->weaponstuck != 0 && Person::players[i]->victim->weaponstuck != -1) + if (Person::players[i]->victim->weaponstuck != 0 && Person::players[i]->victim->weaponstuck != -1) { Person::players[i]->victim->weaponstuck = 0; - if (Person::players[i]->victim->weaponids[0] == k) + } + if (Person::players[i]->victim->weaponids[0] == k) { Person::players[i]->victim->weaponids[0] = Person::players[i]->victim->weaponids[Person::players[i]->victim->num_weapons]; + } } Person::players[i]->victim->weaponactive = -1; @@ -3651,7 +3890,10 @@ void Game::Tick() } } } + } + } } + } } } if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) { @@ -3660,12 +3902,12 @@ void Game::Tick() Person::players[i]->isRun() || Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim || - Person::players[i]->isFlip()) - if (Person::players.size() > 1) + Person::players[i]->isFlip()) { + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { - if (i != j) - if (!Tutorial::active || Tutorial::stage == 49) - if (hostile) + if (i != j) { + if (!Tutorial::active || Tutorial::stage == 49) { + if (hostile) { if (normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[j]->coords) < 0 && distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 100 && distsq(&Person::players[i]->coords, &Person::players[j]->coords) > 1.5 && @@ -3697,21 +3939,28 @@ void Game::Tick() } } } + } + } + } } + } + } } } if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) { if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim) { Person::players[i]->throwtogglekeydown = 1; XYZ tempVelocity = Person::players[i]->velocity * .2; - if (tempVelocity.x == 0) + if (tempVelocity.x == 0) { tempVelocity.x = .1; + } weapons[Person::players[i]->weaponids[0]].drop(tempVelocity, tempVelocity, false); Person::players[i]->num_weapons--; if (Person::players[i]->num_weapons) { Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons]; - if (Person::players[i]->weaponstuck == Person::players[i]->num_weapons) + if (Person::players[i]->weaponstuck == Person::players[i]->num_weapons) { Person::players[i]->weaponstuck = 0; + } } Person::players[i]->weaponactive = -1; @@ -3732,9 +3981,11 @@ void Game::Tick() (Person::players[i]->weaponactive != -1) && i != 0) { bool isgood = true; - if (Person::players[i]->weaponactive != -1) - if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff) + if (Person::players[i]->weaponactive != -1) { + if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff) { isgood = false; + } + } if (isgood && Person::players[i]->creature != wolftype) { if (Person::players[i]->isIdle() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) { Person::players[i]->setTargetAnimation(drawrightanim); @@ -3766,16 +4017,19 @@ void Game::Tick() Person::players[i]->num_weapons && Person::players[i]->attackkeydown && musictype != stream_fighttheme) { - if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == knife) + if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == knife) { Person::players[i]->setTargetAnimation(crouchstabanim); - if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == sword) + } + if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == sword) { Person::players[i]->setTargetAnimation(swordgroundstabanim); + } Person::players[i]->hasvictim = 0; } } - if (!Person::players[i]->drawkeydown) + if (!Person::players[i]->drawkeydown) { Person::players[i]->drawtogglekeydown = 0; + } XYZ absflatfacing; if (i == 0) { @@ -3783,8 +4037,9 @@ void Game::Tick() absflatfacing.z = -1; absflatfacing = DoRotation(absflatfacing, 0, -yaw, 0); - } else + } else { absflatfacing = flatfacing; + } if (Dialog::inDialog()) { Person::players[i]->forwardkeydown = 0; @@ -3803,21 +4058,26 @@ void Game::Tick() Person::players[i]->animTarget != staggerbackhardanim && Person::players[i]->animTarget != backhandspringanim && Person::players[i]->animTarget != dodgebackanim) { - if (!Person::players[i]->forwardkeydown) + if (!Person::players[i]->forwardkeydown) { Person::players[i]->forwardstogglekeydown = 0; + } if (Person::players[i]->crouchkeydown) { //Crouch target = -2; if (i == 0) { Person::players[i]->superruntoggle = 1; - if (Person::players.size() > 1) - for (unsigned j = 0; j < Person::players.size(); j++) - if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->aitype == passivetype) - if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 16) + if (Person::players.size() > 1) { + for (unsigned j = 0; j < Person::players.size(); j++) { + if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->aitype == passivetype) { + if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 16) { Person::players[i]->superruntoggle = 0; + } + } + } + } } - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim && Person::players[i]->lowreversaldelay <= 0) { if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 && @@ -3830,15 +4090,18 @@ void Game::Tick() Person::players[j]->animTarget == staffhitanim || Person::players[j]->animTarget == staffspinhitanim) && distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2))) { - if (target >= 0) + if (target >= 0) { target = -1; - else + } else { target = j; + } } } } - if (target >= 0) + } + if (target >= 0) { Person::players[target]->Reverse(); + } Person::players[i]->lowreversaldelay = .5; if (Person::players[i]->isIdle()) { @@ -3857,11 +4120,12 @@ void Game::Tick() } if (!Person::players[i]->crouchkeydown) { //Uncrouch - if (!Person::players[i]->isRun() && Person::players[i]->animTarget != sneakanim && i == 0) + if (!Person::players[i]->isRun() && Person::players[i]->animTarget != sneakanim && i == 0) { Person::players[i]->superruntoggle = 0; + } target = -2; if (Person::players[i]->isCrouch()) { - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { if (j != i && !Person::players[j]->skeleton.free && @@ -3871,15 +4135,18 @@ void Game::Tick() Person::players[j]->victim == Person::players[i] && (Person::players[j]->animTarget == spinkickanim) && Person::players[i]->isCrouch()) { - if (target >= 0) + if (target >= 0) { target = -1; - else + } else { target = j; + } } } } - if (target >= 0) + } + if (target >= 0) { Person::players[target]->Reverse(); + } Person::players[i]->highreversaldelay = .5; if (Person::players[i]->isCrouch()) { @@ -3907,15 +4174,17 @@ void Game::Tick() Person::players[i]->frameTarget > 0 && !Person::players[i]->jumpkeydown && Person::players[i]->crouchkeydown)) { - if (Person::players[i]->aitype == passivetype) + if (Person::players[i]->aitype == passivetype) { Person::players[i]->setTargetAnimation(walkanim); - else + } else { Person::players[i]->setTargetAnimation(Person::players[i]->getRun()); + } } if (Person::players[i]->isCrouch()) { Person::players[i]->animTarget = sneakanim; - if (Person::players[i]->wasCrouch()) + if (Person::players[i]->wasCrouch()) { Person::players[i]->target = 0; + } Person::players[i]->frameTarget = 0; } if (Person::players[i]->animTarget == hanganim /*&&(!Person::players[i]->forwardstogglekeydown||Person::players[i]->aitype!=playercontrolled)*/) { @@ -3944,18 +4213,21 @@ void Game::Tick() } if (Person::players[i]->isCrouch()) { Person::players[i]->animTarget = sneakanim; - if (Person::players[i]->wasCrouch()) + if (Person::players[i]->wasCrouch()) { Person::players[i]->target = 0; + } Person::players[i]->frameTarget = 0; } if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) { Person::players[i]->velocity += DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0); } Person::players[i]->targetyaw -= 90; - if (Person::players[i]->forwardkeydown) + if (Person::players[i]->forwardkeydown) { Person::players[i]->targetyaw += 45; - if (Person::players[i]->backkeydown) + } + if (Person::players[i]->backkeydown) { Person::players[i]->targetyaw -= 45; + } movekey = 1; } if (Person::players[i]->leftkeydown) { @@ -3973,18 +4245,21 @@ void Game::Tick() } if (Person::players[i]->isCrouch()) { Person::players[i]->animTarget = sneakanim; - if (Person::players[i]->wasCrouch()) + if (Person::players[i]->wasCrouch()) { Person::players[i]->target = 0; + } Person::players[i]->frameTarget = 0; } if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) { Person::players[i]->velocity -= DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0); } Person::players[i]->targetyaw += 90; - if (Person::players[i]->forwardkeydown) + if (Person::players[i]->forwardkeydown) { Person::players[i]->targetyaw -= 45; - if (Person::players[i]->backkeydown) + } + if (Person::players[i]->backkeydown) { Person::players[i]->targetyaw += 45; + } movekey = 1; } if (Person::players[i]->backkeydown) { @@ -4002,8 +4277,9 @@ void Game::Tick() } if (Person::players[i]->isCrouch()) { Person::players[i]->animTarget = sneakanim; - if (Person::players[i]->wasCrouch()) + if (Person::players[i]->wasCrouch()) { Person::players[i]->target = 0; + } Person::players[i]->frameTarget = 0; } if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) { @@ -4020,8 +4296,9 @@ void Game::Tick() Person::players[i]->coords.y -= 1.4; Person::players[i]->grabdelay = 1; } - if (!Person::players[i]->leftkeydown && !Person::players[i]->rightkeydown) + if (!Person::players[i]->leftkeydown && !Person::players[i]->rightkeydown) { Person::players[i]->targetyaw += 180; + } movekey = 1; } if ((Person::players[i]->jumpkeydown && !Person::players[i]->jumpclimb) || Person::players[i]->jumpstart) { @@ -4045,46 +4322,54 @@ void Game::Tick() facing.z = -1; flatfacing = DoRotation(facing, 0, Person::players[i]->targetyaw + 180, 0); - if (movekey) + if (movekey) { Person::players[i]->velocity = flatfacing * Person::players[i]->speed * 45 * Person::players[i]->scale; - if (!movekey) + } + if (!movekey) { Person::players[i]->velocity = 0; + } //Dodge sweep? target = -2; - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim) { if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 && (Person::players[j]->victim == Person::players[i]) && (Person::players[j]->animTarget == sweepanim)) { - if (target >= 0) + if (target >= 0) { target = -1; - else + } else { target = j; + } } } } - if (target >= 0) + } + if (target >= 0) { Person::players[i]->velocity.y = 1; - else if (Person::players[i]->crouchkeydown || Person::players[i]->aitype != playercontrolled) { + } else if (Person::players[i]->crouchkeydown || Person::players[i]->aitype != playercontrolled) { Person::players[i]->velocity.y = 7; Person::players[i]->crouchtogglekeydown = 1; - } else + } else { Person::players[i]->velocity.y = 5; + } if (mousejump && i == 0 && devtools) { - if (!Person::players[i]->isLanding()) + if (!Person::players[i]->isLanding()) { Person::players[i]->tempdeltav = deltav; - if (Person::players[i]->tempdeltav < 0) + } + if (Person::players[i]->tempdeltav < 0) { Person::players[i]->velocity.y -= (float)(Person::players[i]->tempdeltav) / multiplier / 1000; + } } Person::players[i]->coords.y += .2; Person::players[i]->jumppower -= 1; - if (!i) + if (!i) { emit_sound_at(whooshsound, Person::players[i]->coords, 128.); + } emit_sound_at(jumpsound, Person::players[i]->coords, 128.); } @@ -4109,8 +4394,9 @@ void Game::Tick() Person::players[i]->jumppower = 0; } } - if (((floatjump || editorenabled) && devtools) && i == 0) + if (((floatjump || editorenabled) && devtools) && i == 0) { Person::players[i]->velocity.y += multiplier * 30; + } } if (!movekey) { @@ -4129,48 +4415,58 @@ void Game::Tick() (Person::players[i]->aitype == attacktypecutoff || Person::players[i]->aitype == searchtype || (Person::players[i]->aitype == passivetype && - Person::players[i]->numwaypoints <= 1))) + Person::players[i]->numwaypoints <= 1))) { Person::players[i]->setTargetAnimation(Person::players[i]->getStop()); - if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype)) + } + if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype)) { Person::players[i]->setTargetAnimation(Person::players[i]->getStop()); + } } } - if (Person::players[i]->animTarget == rollanim) + if (Person::players[i]->animTarget == rollanim) { Person::players[i]->targetyaw = oldtargetyaw; + } } //Rotation for (unsigned k = 0; k < Person::players.size(); k++) { if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 180) { - if (Person::players[k]->yaw > Person::players[k]->targetyaw) + if (Person::players[k]->yaw > Person::players[k]->targetyaw) { Person::players[k]->yaw -= 360; - else + } else { Person::players[k]->yaw += 360; + } } //stop to turn in right direction - if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 90 && (Person::players[k]->isRun() || Person::players[k]->animTarget == walkanim)) + if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 90 && (Person::players[k]->isRun() || Person::players[k]->animTarget == walkanim)) { Person::players[k]->setTargetAnimation(Person::players[k]->getStop()); + } - if (Person::players[k]->animTarget == backhandspringanim || Person::players[k]->animTarget == dodgebackanim) + if (Person::players[k]->animTarget == backhandspringanim || Person::players[k]->animTarget == dodgebackanim) { Person::players[k]->targettilt = 0; + } if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != backhandspringanim && Person::players[k]->animTarget != jumpdownanim && !Person::players[k]->isFlip()) { Person::players[k]->targettilt = 0; - if (Person::players[k]->jumppower < 0 && !Person::players[k]->jumpkeydown) + if (Person::players[k]->jumppower < 0 && !Person::players[k]->jumpkeydown) { Person::players[k]->jumppower = 0; + } Person::players[k]->jumppower += multiplier * 7; - if (Person::players[k]->isCrouch()) + if (Person::players[k]->isCrouch()) { Person::players[k]->jumppower += multiplier * 7; - if (Person::players[k]->jumppower > 5) + } + if (Person::players[k]->jumppower > 5) { Person::players[k]->jumppower = 5; + } } - if (Person::players[k]->isRun()) + if (Person::players[k]->isRun()) { Person::players[k]->targettilt = (Person::players[k]->yaw - Person::players[k]->targetyaw) / 4; + } Person::players[k]->tilt = stepTowardf(Person::players[k]->tilt, Person::players[k]->targettilt, multiplier * 150); Person::players[k]->grabdelay -= multiplier; @@ -4239,8 +4535,9 @@ void Game::Tick() } } - if (Input::isKeyPressed(SDL_SCANCODE_F1)) + if (Input::isKeyPressed(SDL_SCANCODE_F1)) { Screenshot(); + } } void Game::TickOnce() @@ -4254,10 +4551,12 @@ void Game::TickOnce() } else { pitch += deltav * .7; } - if (pitch > 90) + if (pitch > 90) { pitch = 90; - if (pitch < -70) + } + if (pitch < -70) { pitch = -70; + } } } @@ -4276,12 +4575,15 @@ void Game::TickOnceAfter() if (!mainmenu) { static int oldmusictype = musictype; - if (environment == snowyenvironment) + if (environment == snowyenvironment) { leveltheme = stream_snowtheme; - if (environment == grassyenvironment) + } + if (environment == grassyenvironment) { leveltheme = stream_grasstheme; - if (environment == desertenvironment) + } + if (environment == desertenvironment) { leveltheme = stream_deserttheme; + } realthreat = 0; @@ -4299,16 +4601,19 @@ void Game::TickOnceAfter() realthreat = 1; } } - if (Person::players[0]->dead) + if (Person::players[0]->dead) { musictype = stream_menutheme; + } - if (musictype == stream_fighttheme) + if (musictype == stream_fighttheme) { unseendelay = 1; + } if (oldmusictype == stream_fighttheme && musictype != stream_fighttheme) { unseendelay -= multiplier; - if (unseendelay > 0) + if (unseendelay > 0) { musictype = stream_fighttheme; + } } if (loading == 2) { @@ -4319,57 +4624,75 @@ void Game::TickOnceAfter() musicvolume[3] = 0; } - if (musictoggle) - if (musictype != oldmusictype && musictype == stream_fighttheme) + if (musictoggle) { + if (musictype != oldmusictype && musictype == stream_fighttheme) { emit_sound_np(alarmsound); + } + } musicselected = musictype; - if (musicselected == leveltheme) + if (musicselected == leveltheme) { musicvolume[0] += multiplier * 450; - else + } else { musicvolume[0] -= multiplier * 450; - if (musicselected == stream_fighttheme) + } + if (musicselected == stream_fighttheme) { musicvolume[1] += multiplier * 450; - else + } else { musicvolume[1] -= multiplier * 450; - if (musicselected == stream_menutheme) + } + if (musicselected == stream_menutheme) { musicvolume[2] += multiplier * 450; - else + } else { musicvolume[2] -= multiplier * 450; + } for (int i = 0; i < 3; i++) { - if (musicvolume[i] < 0) + if (musicvolume[i] < 0) { musicvolume[i] = 0; - if (musicvolume[i] > 512) + } + if (musicvolume[i] > 512) { musicvolume[i] = 512; + } } - if (musicvolume[2] > 128 && !loading && !mainmenu) + if (musicvolume[2] > 128 && !loading && !mainmenu) { musicvolume[2] = 128; + } if (musictoggle) { - if (musicvolume[0] > 0 && oldmusicvolume[0] <= 0) + if (musicvolume[0] > 0 && oldmusicvolume[0] <= 0) { emit_stream_np(leveltheme, musicvolume[0]); - if (musicvolume[1] > 0 && oldmusicvolume[1] <= 0) + } + if (musicvolume[1] > 0 && oldmusicvolume[1] <= 0) { emit_stream_np(stream_fighttheme, musicvolume[1]); - if (musicvolume[2] > 0 && oldmusicvolume[2] <= 0) + } + if (musicvolume[2] > 0 && oldmusicvolume[2] <= 0) { emit_stream_np(stream_menutheme, musicvolume[2]); - if (musicvolume[0] <= 0 && oldmusicvolume[0] > 0) + } + if (musicvolume[0] <= 0 && oldmusicvolume[0] > 0) { pause_sound(leveltheme); - if (musicvolume[1] <= 0 && oldmusicvolume[1] > 0) + } + if (musicvolume[1] <= 0 && oldmusicvolume[1] > 0) { pause_sound(stream_fighttheme); - if (musicvolume[2] <= 0 && oldmusicvolume[2] > 0) + } + if (musicvolume[2] <= 0 && oldmusicvolume[2] > 0) { pause_sound(stream_menutheme); + } - if (musicvolume[0] != oldmusicvolume[0]) + if (musicvolume[0] != oldmusicvolume[0]) { OPENAL_SetVolume(channels[leveltheme], musicvolume[0]); - if (musicvolume[1] != oldmusicvolume[1]) + } + if (musicvolume[1] != oldmusicvolume[1]) { OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]); - if (musicvolume[2] != oldmusicvolume[2]) + } + if (musicvolume[2] != oldmusicvolume[2]) { OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]); + } - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { oldmusicvolume[i] = musicvolume[i]; + } } else { pause_sound(leveltheme); pause_sound(stream_fighttheme); @@ -4384,14 +4707,16 @@ void Game::TickOnceAfter() Hotspot::killhotspot = 2; for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) { if (Hotspot::hotspots[i].type > 10 && Hotspot::hotspots[i].type < 20) { - if (Person::players[Hotspot::hotspots[i].type - 10]->dead == 0) + if (Person::players[Hotspot::hotspots[i].type - 10]->dead == 0) { Hotspot::killhotspot = 0; - else if (Hotspot::killhotspot == 2) + } else if (Hotspot::killhotspot == 2) { Hotspot::killhotspot = 1; + } } } - if (Hotspot::killhotspot == 2) + if (Hotspot::killhotspot == 2) { Hotspot::killhotspot = 0; + } winhotspot = false; for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) { @@ -4428,21 +4753,24 @@ void Game::TickOnceAfter() if (alldead && !Person::players[0]->dead && maptype == mapkilleveryone) { changedelay = 1; targetlevel = whichlevel + 1; - if (targetlevel > numchallengelevels - 1) + if (targetlevel > numchallengelevels - 1) { targetlevel = 0; + } } if (winhotspot || windialogue) { changedelay = 0.1; targetlevel = whichlevel + 1; - if (targetlevel > numchallengelevels - 1) + if (targetlevel > numchallengelevels - 1) { targetlevel = 0; + } } if (Hotspot::killhotspot) { changedelay = 1; targetlevel = whichlevel + 1; - if (targetlevel > numchallengelevels - 1) + if (targetlevel > numchallengelevels - 1) { targetlevel = 0; + } } if (changedelay > 0 && !Person::players[0]->dead && !won) { @@ -4470,17 +4798,20 @@ void Game::TickOnceAfter() } if (!editorenabled && gameon && !mainmenu) { - if (changedelay != -999) + if (changedelay != -999) { changedelay -= multiplier / 7; - if (Person::players[0]->dead) + } + if (Person::players[0]->dead) { targetlevel = whichlevel; + } if (loading == 2 && !campaign) { flash(); fireSound(firestartsound); - if (!Person::players[0]->dead && targetlevel != whichlevel) + if (!Person::players[0]->dead && targetlevel != whichlevel) { startbonustotal = bonustotal; + } LoadLevel(targetlevel); fireSound(); @@ -4505,8 +4836,9 @@ void Game::TickOnceAfter() (Person::players[0]->dead || (alldead && maptype == mapkilleveryone) || (winhotspot) || - (Hotspot::killhotspot))) + (Hotspot::killhotspot))) { loading = 1; + } if ((Person::players[0]->dead || (alldead && maptype == mapkilleveryone) || (winhotspot) || @@ -4517,8 +4849,9 @@ void Game::TickOnceAfter() winfreeze = true; changedelay = -999; } - if (Person::players[0]->dead) + if (Person::players[0]->dead) { loading = 1; + } } } @@ -4528,8 +4861,9 @@ void Game::TickOnceAfter() // 1 = go back to level select screen // 2 = stealthload next level if (mainmenu == 0 && winfreeze && (campaignlevels[actuallevel].choosenext) == 1) { - if (campaignlevels[actuallevel].nextlevel.empty()) + if (campaignlevels[actuallevel].nextlevel.empty()) { endgame = 1; + } } else if (mainmenu == 0 && winfreeze) { stealthloading = (campaignlevels[actuallevel].choosenext == 2); @@ -4563,8 +4897,9 @@ void Game::TickOnceAfter() } } - if (loading == 3) + if (loading == 3) { loading = 0; + } } oldmusictype = musictype; @@ -4578,15 +4913,17 @@ void Game::TickOnceAfter() viewerfacing = facing; if (!cameramode) { - if ((Animation::animations[Person::players[0]->animTarget].attack != 3 && Animation::animations[Person::players[0]->animCurrent].attack != 3) || Person::players[0]->skeleton.free) + if ((Animation::animations[Person::players[0]->animTarget].attack != 3 && Animation::animations[Person::players[0]->animCurrent].attack != 3) || Person::players[0]->skeleton.free) { target = Person::players[0]->coords + Person::players[0]->currentoffset * (1 - Person::players[0]->target) * Person::players[0]->scale + Person::players[0]->targetoffset * Person::players[0]->target * Person::players[0]->scale - Person::players[0]->facing * .05; - else + } else { target = Person::players[0]->oldcoords + Person::players[0]->currentoffset * (1 - Person::players[0]->target) * Person::players[0]->scale + Person::players[0]->targetoffset * Person::players[0]->target * Person::players[0]->scale - Person::players[0]->facing * .05; + } target.y += .1; if (Person::players[0]->skeleton.free) { for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) { - if (Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y > target.y) + if (Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y > target.y) { target.y = Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y; + } } target.y += .1; } @@ -4595,23 +4932,27 @@ void Game::TickOnceAfter() if (findLengthfast(&Person::players[0]->velocity) > 400) { cameraspeed = 20 + (findLength(&Person::players[0]->velocity) - 20) * .96; } - if (Person::players[0]->skeleton.free == 0 && Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim) + if (Person::players[0]->skeleton.free == 0 && Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim) { target.y += 1.4; + } coltarget = target - cameraloc; - if (findLengthfast(&coltarget) < multiplier * multiplier * 400) + if (findLengthfast(&coltarget) < multiplier * multiplier * 400) { cameraloc = target; - else { + } else { Normalise(&coltarget); - if (Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim && Person::players[0]->animCurrent != climbanim && Person::players[0]->currentoffset.x == 0) + if (Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim && Person::players[0]->animCurrent != climbanim && Person::players[0]->currentoffset.x == 0) { cameraloc = cameraloc + coltarget * multiplier * cameraspeed; - else + } else { cameraloc = cameraloc + coltarget * multiplier * 8; + } } - if (editorenabled) + if (editorenabled) { cameraloc = target; + } cameradist += multiplier * 5; - if (cameradist > 2.3) + if (cameradist > 2.3) { cameradist = 2.3; + } viewer = cameraloc - facing * cameradist; colviewer = viewer; coltarget = cameraloc; @@ -4637,19 +4978,24 @@ void Game::TickOnceAfter() cameraloc.y = terrain.getHeight(cameraloc.x, cameraloc.z); } } - if (camerashake > .8) + if (camerashake > .8) { camerashake = .8; + } woozy += multiplier; - if (Person::players[0]->dead) + if (Person::players[0]->dead) { camerashake = 0; - if (Person::players[0]->dead) + } + if (Person::players[0]->dead) { woozy = 0; + } camerashake -= multiplier * 2; blackout -= multiplier * 2; - if (camerashake < 0) + if (camerashake < 0) { camerashake = 0; - if (blackout < 0) + } + if (blackout < 0) { blackout = 0; + } if (camerashake) { viewer.x += (float)(Random() % 100) * .0005 * camerashake; viewer.y += (float)(Random() % 100) * .0005 * camerashake; diff --git a/Source/Graphic/Models.cpp b/Source/Graphic/Models.cpp index 860957d..eedaea0 100644 --- a/Source/Graphic/Models.cpp +++ b/Source/Graphic/Models.cpp @@ -40,12 +40,15 @@ int Model::LineCheck(XYZ* p1, XYZ* p2, XYZ* p, XYZ* move, float* rotate) *p1 = *p1 - *move; *p2 = *p2 - *move; - if (*rotate) + if (*rotate) { *p1 = DoRotation(*p1, 0, -*rotate, 0); - if (*rotate) + } + if (*rotate) { *p2 = DoRotation(*p2, 0, -*rotate, 0); - if (!sphere_line_intersection(p1, p2, &boundingspherecenter, &boundingsphereradius)) + } + if (!sphere_line_intersection(p1, p2, &boundingspherecenter, &boundingsphereradius)) { return -1; + } firstintersecting = -1; for (unsigned int j = 0; j < Triangles.size(); j++) { @@ -58,8 +61,9 @@ int Model::LineCheck(XYZ* p1, XYZ* p2, XYZ* p, XYZ* move, float* rotate) } } - if (*rotate) + if (*rotate) { *p = DoRotation(*p, 0, *rotate, 0); + } *p = *p + *move; return firstintersecting; } @@ -74,13 +78,16 @@ int Model::LineCheckPossible(XYZ* p1, XYZ* p2, XYZ* p, XYZ* move, float* rotate) *p1 = *p1 - *move; *p2 = *p2 - *move; - if (!sphere_line_intersection(p1, p2, &boundingspherecenter, &boundingsphereradius)) + if (!sphere_line_intersection(p1, p2, &boundingspherecenter, &boundingsphereradius)) { return -1; + } firstintersecting = -1; - if (*rotate) + if (*rotate) { *p1 = DoRotation(*p1, 0, -*rotate, 0); - if (*rotate) + } + if (*rotate) { *p2 = DoRotation(*p2, 0, -*rotate, 0); + } for (unsigned int j = 0; j < possible.size(); j++) { if (possible[j] < Triangles.size()) { @@ -94,8 +101,9 @@ int Model::LineCheckPossible(XYZ* p1, XYZ* p2, XYZ* p, XYZ* move, float* rotate) } } - if (*rotate) + if (*rotate) { *p = DoRotation(*p, 0, *rotate, 0); + } *p = *p + *move; return firstintersecting; } @@ -110,13 +118,16 @@ int Model::LineCheckSlidePossible(XYZ* p1, XYZ* p2, XYZ* move, float* rotate) *p1 = *p1 - *move; *p2 = *p2 - *move; - if (!sphere_line_intersection(p1, p2, &boundingspherecenter, &boundingsphereradius)) + if (!sphere_line_intersection(p1, p2, &boundingspherecenter, &boundingsphereradius)) { return -1; + } firstintersecting = -1; - if (*rotate) + if (*rotate) { *p1 = DoRotation(*p1, 0, -*rotate, 0); - if (*rotate) + } + if (*rotate) { *p2 = DoRotation(*p2, 0, -*rotate, 0); + } for (unsigned int j = 0; j < possible.size(); j++) { if (possible[j] < Triangles.size()) { @@ -134,8 +145,9 @@ int Model::LineCheckSlidePossible(XYZ* p1, XYZ* p2, XYZ* move, float* rotate) *p2 -= Triangles[firstintersecting].facenormal * distance; } - if (*rotate) + if (*rotate) { *p2 = DoRotation(*p2, 0, *rotate, 0); + } *p2 = *p2 + *move; return firstintersecting; } @@ -154,10 +166,12 @@ int Model::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate) oldp1 = *p1; *p1 = *p1 - *move; - if (*rotate) + if (*rotate) { *p1 = DoRotation(*p1, 0, -*rotate, 0); - if (distsq(p1, &boundingspherecenter) > radius * radius + boundingsphereradius * boundingsphereradius) + } + if (distsq(p1, &boundingspherecenter) > radius * radius + boundingsphereradius * boundingsphereradius) { return -1; + } for (i = 0; i < 4; i++) { for (unsigned int j = 0; j < Triangles.size(); j++) { @@ -165,14 +179,18 @@ int Model::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate) distance = abs((Triangles[j].facenormal.x * p1->x) + (Triangles[j].facenormal.y * p1->y) + (Triangles[j].facenormal.z * p1->z) - ((Triangles[j].facenormal.x * vertex[Triangles[j].vertex[0]].x) + (Triangles[j].facenormal.y * vertex[Triangles[j].vertex[0]].y) + (Triangles[j].facenormal.z * vertex[Triangles[j].vertex[0]].z))); if (distance < radius) { point = *p1 - Triangles[j].facenormal * distance; - if (PointInTriangle(&point, Triangles[j].facenormal, &vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], &vertex[Triangles[j].vertex[2]])) + if (PointInTriangle(&point, Triangles[j].facenormal, &vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], &vertex[Triangles[j].vertex[2]])) { intersecting = 1; - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], p1, &radius); - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[1]], &vertex[Triangles[j].vertex[2]], p1, &radius); - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[2]], p1, &radius); + } if (intersecting) { *p1 += Triangles[j].facenormal * (distance - radius); } @@ -184,11 +202,13 @@ int Model::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate) } } } - if (*rotate) + if (*rotate) { *p = DoRotation(*p, 0, *rotate, 0); + } *p = *p + *move; - if (*rotate) + if (*rotate) { *p1 = DoRotation(*p1, 0, *rotate, 0); + } *p1 += *move; return firstintersecting; } @@ -209,8 +229,9 @@ int Model::SphereCheckPossible(XYZ* p1, float radius, XYZ* move, float* rotate) possible.clear(); - if (*rotate) + if (*rotate) { *p1 = DoRotation(*p1, 0, -*rotate, 0); + } if (distsq(p1, &boundingspherecenter) > radius * radius + boundingsphereradius * boundingsphereradius) { *p1 = oldp1; return -1; @@ -221,14 +242,18 @@ int Model::SphereCheckPossible(XYZ* p1, float radius, XYZ* move, float* rotate) distance = abs((Triangles[j].facenormal.x * p1->x) + (Triangles[j].facenormal.y * p1->y) + (Triangles[j].facenormal.z * p1->z) - ((Triangles[j].facenormal.x * vertex[Triangles[j].vertex[0]].x) + (Triangles[j].facenormal.y * vertex[Triangles[j].vertex[0]].y) + (Triangles[j].facenormal.z * vertex[Triangles[j].vertex[0]].z))); if (distance < radius) { point = *p1 - Triangles[j].facenormal * distance; - if (PointInTriangle(&point, Triangles[j].facenormal, &vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], &vertex[Triangles[j].vertex[2]])) + if (PointInTriangle(&point, Triangles[j].facenormal, &vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], &vertex[Triangles[j].vertex[2]])) { intersecting = 1; - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], p1, &radius); - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[1]], &vertex[Triangles[j].vertex[2]], p1, &radius); - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[2]], p1, &radius); + } if (intersecting) { possible.push_back(j); } @@ -238,8 +263,9 @@ int Model::SphereCheckPossible(XYZ* p1, float radius, XYZ* move, float* rotate) firstintersecting = j; } } - if (*rotate) + if (*rotate) { *p1 = DoRotation(*p1, 0, *rotate, 0); + } *p1 += *move; return firstintersecting; @@ -247,8 +273,9 @@ int Model::SphereCheckPossible(XYZ* p1, float radius, XYZ* move, float* rotate) void Model::UpdateVertexArray() { - if (type != normaltype && type != decalstype) + if (type != normaltype && type != decalstype) { return; + } if (flat) { for (unsigned int i = 0; i < Triangles.size(); i++) { @@ -315,8 +342,9 @@ void Model::UpdateVertexArray() void Model::UpdateVertexArrayNoTex() { - if (type != normaltype && type != decalstype) + if (type != normaltype && type != decalstype) { return; + } if (flat) { for (unsigned int i = 0; i < Triangles.size(); i++) { @@ -371,8 +399,9 @@ void Model::UpdateVertexArrayNoTex() void Model::UpdateVertexArrayNoTexNoNorm() { - if (type != normaltype && type != decalstype) + if (type != normaltype && type != decalstype) { return; + } for (unsigned int i = 0; i < Triangles.size(); i++) { unsigned int j = i * 24; @@ -709,8 +738,9 @@ void Model::Scale(float xscale, float yscale, float zscale) void Model::ScaleNormals(float xscale, float yscale, float zscale) { - if (type != normaltype && type != decalstype) + if (type != normaltype && type != decalstype) { return; + } for (int i = 0; i < vertexNum; i++) { normals[i].x *= xscale; @@ -773,8 +803,9 @@ void Model::CalculateNormals(bool facenormalise) { Game::LoadingScreen(); - if (type != normaltype && type != decalstype) + if (type != normaltype && type != decalstype) { return; + } for (int i = 0; i < vertexNum; i++) { normals[i].x = 0; @@ -796,8 +827,9 @@ void Model::CalculateNormals(bool facenormalise) normals[Triangles[i].vertex[2]].x += Triangles[i].facenormal.x; normals[Triangles[i].vertex[2]].y += Triangles[i].facenormal.y; normals[Triangles[i].vertex[2]].z += Triangles[i].facenormal.z; - if (facenormalise) + if (facenormalise) { Normalise(&Triangles[i].facenormal); + } } for (int i = 0; i < vertexNum; i++) { Normalise(&normals[i]); @@ -846,8 +878,9 @@ void Model::drawimmediate() void Model::draw() { - if (type != normaltype && type != decalstype) + if (type != normaltype && type != decalstype) { return; + } glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); @@ -913,8 +946,9 @@ void Model::drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloo glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthMask(0); for (unsigned int i = 0; i < decals.size(); i++) { - if (decals[i].type == blooddecalfast && decals[i].alivetime < 2) + if (decals[i].type == blooddecalfast && decals[i].alivetime < 2) { decals[i].alivetime = 2; + } if (decals[i].type != lasttype) { if (decals[i].type == shadowdecal) { @@ -955,15 +989,18 @@ void Model::drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloo } if (decals[i].type == breakdecal) { glColor4f(1, 1, 1, decals[i].opacity); - if (decals[i].alivetime > 58) + if (decals[i].alivetime > 58) { glColor4f(1, 1, 1, decals[i].opacity * (60 - decals[i].alivetime) / 2); + } } if ((decals[i].type == blooddecal || decals[i].type == blooddecalfast || decals[i].type == blooddecalslow)) { glColor4f(1, 1, 1, decals[i].opacity); - if (decals[i].alivetime < 4) + if (decals[i].alivetime < 4) { glColor4f(1, 1, 1, decals[i].opacity * decals[i].alivetime * .25); - if (decals[i].alivetime > 58) + } + if (decals[i].alivetime > 58) { glColor4f(1, 1, 1, decals[i].opacity * (60 - decals[i].alivetime) / 2); + } } lasttype = decals[i].type; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); @@ -981,14 +1018,18 @@ void Model::drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloo } for (int i = decals.size() - 1; i >= 0; i--) { decals[i].alivetime += multiplier; - if (decals[i].type == blooddecalslow) + if (decals[i].type == blooddecalslow) { decals[i].alivetime -= multiplier * 2 / 3; - if (decals[i].type == blooddecalfast) + } + if (decals[i].type == blooddecalfast) { decals[i].alivetime += multiplier * 4; - if (decals[i].type == shadowdecal) + } + if (decals[i].type == shadowdecal) { DeleteDecal(i); - if ((decals[i].type == blooddecal || decals[i].type == blooddecalfast || decals[i].type == blooddecalslow) && decals[i].alivetime >= 60) + } + if ((decals[i].type == blooddecal || decals[i].type == blooddecalfast || decals[i].type == blooddecalslow) && decals[i].alivetime >= 60) { DeleteDecal(i); + } } glAlphaFunc(GL_GREATER, 0.0001); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -998,8 +1039,9 @@ void Model::drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloo void Model::DeleteDecal(int which) { if (decalstoggle) { - if (type != decalstype) + if (type != decalstype) { return; + } decals.erase(decals.begin() + which); } } @@ -1007,14 +1049,15 @@ void Model::DeleteDecal(int which) void Model::MakeDecal(decal_type atype, XYZ* where, float* size, float* opacity, float* rotation) { if (decalstoggle) { - if (type != decalstype) + if (type != decalstype) { return; + } static XYZ rot; static float distance; - if (*opacity > 0) - if (distsq(where, &boundingspherecenter) < (boundingsphereradius + *size) * (boundingsphereradius + *size)) + if (*opacity > 0) { + if (distsq(where, &boundingspherecenter) < (boundingsphereradius + *size) * (boundingsphereradius + *size)) { for (unsigned int i = 0; i < Triangles.size(); i++) { if (Triangles[i].facenormal.y < -.1 && (vertex[Triangles[i].vertex[0]].y < where->y || vertex[Triangles[i].vertex[1]].y < where->y || vertex[Triangles[i].vertex[2]].y < where->y)) { distance = abs(((Triangles[i].facenormal.x * where->x) + (Triangles[i].facenormal.y * where->y) + (Triangles[i].facenormal.z * where->z) - ((Triangles[i].facenormal.x * vertex[Triangles[i].vertex[0]].x) + (Triangles[i].facenormal.y * vertex[Triangles[i].vertex[0]].y) + (Triangles[i].facenormal.z * vertex[Triangles[i].vertex[0]].z))) / Triangles[i].facenormal.y); @@ -1022,9 +1065,9 @@ void Model::MakeDecal(decal_type atype, XYZ* where, float* size, float* opacity, if ((*opacity - distance / 10) > 0) { Decal decal(*where, atype, *opacity - distance / 10, *rotation, *size, *this, i, 0); - if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) - if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) - if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) + if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) { + if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) { + if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) { if (!(decal.texcoords[0][1] > 1 && decal.texcoords[1][1] > 1 && decal.texcoords[2][1] > 1)) { if (decal.rotation) { for (int j = 0; j < 3; j++) { @@ -1040,32 +1083,38 @@ void Model::MakeDecal(decal_type atype, XYZ* where, float* size, float* opacity, decals.push_back(decal); } } + } + } + } } } } + } + } } } void Model::MakeDecal(decal_type atype, XYZ where, float size, float opacity, float rotation) { if (decalstoggle) { - if (type != decalstype) + if (type != decalstype) { return; + } static XYZ rot; static float distance; - if (opacity > 0) - if (distsq(&where, &boundingspherecenter) < (boundingsphereradius + size) * (boundingsphereradius + size)) + if (opacity > 0) { + if (distsq(&where, &boundingspherecenter) < (boundingsphereradius + size) * (boundingsphereradius + size)) { for (unsigned int i = 0; i < Triangles.size(); i++) { distance = abs(((Triangles[i].facenormal.x * where.x) + (Triangles[i].facenormal.y * where.y) + (Triangles[i].facenormal.z * where.z) - ((Triangles[i].facenormal.x * vertex[Triangles[i].vertex[0]].x) + (Triangles[i].facenormal.y * vertex[Triangles[i].vertex[0]].y) + (Triangles[i].facenormal.z * vertex[Triangles[i].vertex[0]].z)))); if (distance < .02 && abs(Triangles[i].facenormal.y) > abs(Triangles[i].facenormal.x) && abs(Triangles[i].facenormal.y) > abs(Triangles[i].facenormal.z)) { if ((opacity - distance / 10) > 0) { Decal decal(where, atype, opacity - distance / 10, rotation, size, *this, i, 0); - if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) - if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) - if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) + if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) { + if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) { + if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) { if (!(decal.texcoords[0][1] > 1 && decal.texcoords[1][1] > 1 && decal.texcoords[2][1] > 1)) { if (decal.rotation) { for (int j = 0; j < 3; j++) { @@ -1081,14 +1130,17 @@ void Model::MakeDecal(decal_type atype, XYZ where, float size, float opacity, fl decals.push_back(decal); } } + } + } + } } } else if (distance < .02 && abs(Triangles[i].facenormal.x) > abs(Triangles[i].facenormal.y) && abs(Triangles[i].facenormal.x) > abs(Triangles[i].facenormal.z)) { if ((opacity - distance / 10) > 0) { Decal decal(where, atype, opacity - distance / 10, rotation, size, *this, i, 1); - if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) - if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) - if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) + if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) { + if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) { + if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) { if (!(decal.texcoords[0][1] > 1 && decal.texcoords[1][1] > 1 && decal.texcoords[2][1] > 1)) { if (decal.rotation) { for (int j = 0; j < 3; j++) { @@ -1104,14 +1156,17 @@ void Model::MakeDecal(decal_type atype, XYZ where, float size, float opacity, fl decals.push_back(decal); } } + } + } + } } } else if (distance < .02 && abs(Triangles[i].facenormal.z) > abs(Triangles[i].facenormal.y) && abs(Triangles[i].facenormal.z) > abs(Triangles[i].facenormal.x)) { if ((opacity - distance / 10) > 0) { Decal decal(where, atype, opacity - distance / 10, rotation, size, *this, i, 2); - if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) - if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) - if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) + if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0)) { + if (!(decal.texcoords[0][1] < 0 && decal.texcoords[1][1] < 0 && decal.texcoords[2][1] < 0)) { + if (!(decal.texcoords[0][0] > 1 && decal.texcoords[1][0] > 1 && decal.texcoords[2][0] > 1)) { if (!(decal.texcoords[0][1] > 1 && decal.texcoords[1][1] > 1 && decal.texcoords[2][1] > 1)) { if (decal.rotation) { for (int j = 0; j < 3; j++) { @@ -1127,9 +1182,14 @@ void Model::MakeDecal(decal_type atype, XYZ where, float size, float opacity, fl decals.push_back(decal); } } + } + } + } } } } + } + } } } @@ -1154,20 +1214,24 @@ Model::~Model() void Model::deallocate() { - if (owner) + if (owner) { free(owner); + } owner = 0; - if (vertex) + if (vertex) { free(vertex); + } vertex = 0; - if (normals) + if (normals) { free(normals); + } normals = 0; - if (vArray) + if (vArray) { free(vArray); + } vArray = 0; decals.clear(); diff --git a/Source/Graphic/Sprite.cpp b/Source/Graphic/Sprite.cpp index fc1cae2..c2b2d9e 100644 --- a/Source/Graphic/Sprite.cpp +++ b/Source/Graphic/Sprite.cpp @@ -135,14 +135,18 @@ void Sprite::Draw() break; case splintersprite: if (lastspecial != sprites[i]->special) { - if (sprites[i]->special == 0) + if (sprites[i]->special == 0) { splintertexture.bind(); - if (sprites[i]->special == 1) + } + if (sprites[i]->special == 1) { leaftexture.bind(); - if (sprites[i]->special == 2) + } + if (sprites[i]->special == 2) { snowflaketexture.bind(); - if (sprites[i]->special == 3) + } + if (sprites[i]->special == 3) { toothtexture.bind(); + } if (!blend) { blend = 1; glAlphaFunc(GL_GREATER, 0.0001); @@ -185,20 +189,23 @@ void Sprite::Draw() break; } } - if (sprites[i]->type == snowsprite) + if (sprites[i]->type == snowsprite) { distancemult = (144 - (distsq(&tempviewer, &sprites[i]->position) - (144 * fadestart)) * (1 / (1 - fadestart))) / 144; - else + } else { distancemult = (viewdistsquared - (distsq(&viewer, &sprites[i]->position) - (viewdistsquared * fadestart)) * (1 / (1 - fadestart))) / viewdistsquared; + } if (sprites[i]->type == flamesprite) { - if (distancemult >= 1) + if (distancemult >= 1) { glColor4f(sprites[i]->color[0], sprites[i]->color[1], sprites[i]->color[2], sprites[i]->opacity); - else + } else { glColor4f(sprites[i]->color[0], sprites[i]->color[1], sprites[i]->color[2], sprites[i]->opacity * distancemult); + } } else { - if (distancemult >= 1) + if (distancemult >= 1) { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity); - else + } else { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * distancemult); + } } lasttype = sprites[i]->type; lastspecial = sprites[i]->special; @@ -224,35 +231,41 @@ void Sprite::Draw() glRotatef(sprites[i]->rotation, 0, 0, 1); if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite)) { - if (sprites[i]->alivetime < .14) + if (sprites[i]->alivetime < .14) { glScalef(sprites[i]->alivetime / .14, sprites[i]->alivetime / .14, sprites[i]->alivetime / .14); + } } if (sprites[i]->type == smoketype || sprites[i]->type == snowsprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == breathsprite) { if (sprites[i]->alivetime < .3) { - if (distancemult >= 1) + if (distancemult >= 1) { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * sprites[i]->alivetime / .3); - if (distancemult < 1) + } + if (distancemult < 1) { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * distancemult * sprites[i]->alivetime / .3); + } } } if (sprites[i]->type == splintersprite && sprites[i]->special > 0 && sprites[i]->special != 3) { if (sprites[i]->alivetime < .2) { - if (distancemult >= 1) + if (distancemult >= 1) { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->alivetime / .2); - else + } else { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult * sprites[i]->alivetime / .2); + } } else { - if (distancemult >= 1) + if (distancemult >= 1) { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], 1); - else + } else { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult); + } } } if (sprites[i]->type == splintersprite && (sprites[i]->special == 0 || sprites[i]->special == 3)) { - if (distancemult >= 1) + if (distancemult >= 1) { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], 1); - else + } else { glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult); + } } glBegin(GL_TRIANGLES); @@ -278,10 +291,12 @@ void Sprite::Draw() sprites[i]->position += sprites[i]->velocity * multiplier; sprites[i]->velocity += windvector * multiplier; } - if (sprites[i]->type == flamesprite || sprites[i]->type == smoketype) + if (sprites[i]->type == flamesprite || sprites[i]->type == smoketype) { sprites[i]->position += windvector * multiplier / 2; - if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite)) + } + if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite)) { multiplier *= sprites[i]->speed * .7; + } sprites[i]->alivetime += multiplier; if (sprites[i]->type == cloudsprite || sprites[i]->type == cloudimpactsprite) { @@ -307,18 +322,24 @@ void Sprite::Draw() sprites[i]->rotation += multiplier * 360; sprites[i]->position.y -= multiplier; sprites[i]->position += windvector * multiplier; - if (sprites[i]->position.y < tempviewer.y - 6) + if (sprites[i]->position.y < tempviewer.y - 6) { sprites[i]->position.y += 12; - if (sprites[i]->position.y > tempviewer.y + 6) + } + if (sprites[i]->position.y > tempviewer.y + 6) { sprites[i]->position.y -= 12; - if (sprites[i]->position.z < tempviewer.z - 6) + } + if (sprites[i]->position.z < tempviewer.z - 6) { sprites[i]->position.z += 12; - if (sprites[i]->position.z > tempviewer.z + 6) + } + if (sprites[i]->position.z > tempviewer.z + 6) { sprites[i]->position.z -= 12; - if (sprites[i]->position.x < tempviewer.x - 6) + } + if (sprites[i]->position.x < tempviewer.x - 6) { sprites[i]->position.x += 12; - if (sprites[i]->position.x > tempviewer.x + 6) + } + if (sprites[i]->position.x > tempviewer.x + 6) { sprites[i]->position.x -= 12; + } } if (sprites[i]->type == bloodsprite) { bool spritehit = 0; @@ -333,13 +354,15 @@ void Sprite::Draw() if (!spritehit && Person::players[j]->dead && sprites[i]->alivetime > .1) { where = sprites[i]->oldposition; where -= Person::players[j]->coords; - if (!Person::players[j]->skeleton.free) + if (!Person::players[j]->skeleton.free) { where = DoRotation(where, 0, -Person::players[j]->yaw, 0); + } startpoint = where; where = sprites[i]->position; where -= Person::players[j]->coords; - if (!Person::players[j]->skeleton.free) + if (!Person::players[j]->skeleton.free) { where = DoRotation(where, 0, -Person::players[j]->yaw, 0); + } endpoint = where; movepoint = 0; @@ -361,13 +384,15 @@ void Sprite::Draw() k = terrain.patchobjects[whichpatchx][whichpatchz][j]; start = sprites[i]->oldposition; end = sprites[i]->position; - if (!spritehit) + if (!spritehit) { if (Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw) != -1) { - if (detail == 2 || (detail == 1 && abs(Random() % 4) == 0) || (detail == 0 && abs(Random() % 8) == 0)) + if (detail == 2 || (detail == 1 && abs(Random() % 4) == 0) || (detail == 0 && abs(Random() % 8) == 0)) { Object::objects[k]->model.MakeDecal(blooddecalfast, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), sprites[i]->size * 1.6, .5, Random() % 360); + } DeleteSprite(i); spritehit = 1; } + } } } } @@ -382,17 +407,21 @@ void Sprite::Draw() if (sprites[i]->type == splintersprite) { sprites[i]->rotation += sprites[i]->rotatespeed * multiplier; sprites[i]->opacity -= multiplier / 2; - if (sprites[i]->special == 0 || sprites[i]->special == 2 || sprites[i]->special == 3) + if (sprites[i]->special == 0 || sprites[i]->special == 2 || sprites[i]->special == 3) { sprites[i]->velocity.y += gravity * multiplier; - if (sprites[i]->special == 1) + } + if (sprites[i]->special == 1) { sprites[i]->velocity.y += gravity * multiplier * .5; + } } if (sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite) { sprites[i]->rotation += multiplier * sprites[i]->rotatespeed; sprites[i]->opacity -= multiplier * 5 / 4; - if (sprites[i]->type != weaponshinesprite && sprites[i]->type != bloodflamesprite) - if (sprites[i]->opacity < .5 && sprites[i]->opacity + multiplier * 5 / 4 >= .5 && (abs(Random() % 4) == 0 || (sprites[i]->initialsize > 2 && Random() % 2 == 0))) + if (sprites[i]->type != weaponshinesprite && sprites[i]->type != bloodflamesprite) { + if (sprites[i]->opacity < .5 && sprites[i]->opacity + multiplier * 5 / 4 >= .5 && (abs(Random() % 4) == 0 || (sprites[i]->initialsize > 2 && Random() % 2 == 0))) { MakeSprite(smoketype, sprites[i]->position, sprites[i]->velocity, .9, .9, .6, sprites[i]->size * 1.2, .4); + } + } if (sprites[i]->alivetime > .14 && (sprites[i]->type == flamesprite)) { sprites[i]->velocity = 0; sprites[i]->velocity.y = 1.5; @@ -403,24 +432,29 @@ void Sprite::Draw() sprites[i]->color[0] -= multiplier; sprites[i]->color[1] -= multiplier; sprites[i]->color[2] -= multiplier; - if (sprites[i]->color[0] < .6) + if (sprites[i]->color[0] < .6) { sprites[i]->color[0] = .6; - if (sprites[i]->color[1] < .6) + } + if (sprites[i]->color[1] < .6) { sprites[i]->color[1] = .6; - if (sprites[i]->color[2] < .6) + } + if (sprites[i]->color[2] < .6) { sprites[i]->color[2] = .6; + } sprites[i]->size += multiplier; sprites[i]->velocity = 0; sprites[i]->velocity.y = 1.5; sprites[i]->rotation += multiplier * sprites[i]->rotatespeed / 5; } - if (sprites[i]->opacity <= 0 || sprites[i]->size <= 0) + if (sprites[i]->opacity <= 0 || sprites[i]->size <= 0) { DeleteSprite(i); + } } - if (check) + if (check) { for (int i = sprites.size() - 1; i >= 0; i--) { sprites[i]->oldposition = sprites[i]->position; } + } glAlphaFunc(GL_GREATER, 0.0001); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } diff --git a/Source/Graphic/Text.cpp b/Source/Graphic/Text.cpp index a5b60b8..6998c7a 100644 --- a/Source/Graphic/Text.cpp +++ b/Source/Graphic/Text.cpp @@ -69,12 +69,13 @@ void Text::BuildFont() // Build Our Font Display List glTexCoord2f(cx, 1 - cy - +.001); // Texture Coord (Top Left) glVertex2i(0, 16); // Vertex Coord (Top Left) glEnd(); // Done Building Our Quad (Character) - if (loop < 256) + if (loop < 256) { glTranslated(10, 0, 0); // Move To The Right Of The Character - else + } else { glTranslated(8, 0, 0); // Move To The Right Of The Character - glEndList(); // Done Building The Display List - } // Loop Until All 256 Are Built + } + glEndList(); // Done Building The Display List + } // Loop Until All 256 Are Built } void Text::_glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end, int offset) // Where The Printing Happens diff --git a/Source/Graphic/Texture.cpp b/Source/Graphic/Texture.cpp index 69ff28e..4b4b9ea 100644 --- a/Source/Graphic/Texture.cpp +++ b/Source/Graphic/Texture.cpp @@ -39,8 +39,9 @@ void TextureRes::load() skinsize = texture.sizeX; GLuint type = GL_RGBA; - if (texture.bpp == 24) + if (texture.bpp == 24) { type = GL_RGB; + } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -62,9 +63,11 @@ void TextureRes::load() const int nb = texture.sizeY * texture.sizeX * (texture.bpp / 8); data = (GLubyte*)malloc(nb * sizeof(GLubyte)); datalen = 0; - for (int i = 0; i < nb; i++) - if ((i + 1) % 4 || type == GL_RGB) + for (int i = 0; i < nb; i++) { + if ((i + 1) % 4 || type == GL_RGB) { data[datalen++] = texture.data[i]; + } + } glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, data); } else { glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, type, GL_UNSIGNED_BYTE, texture.data); @@ -122,8 +125,9 @@ void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* void Texture::bind() { - if (tex) + if (tex) { tex->bind(); - else + } else { glBindTexture(GL_TEXTURE_2D, 0); + } } diff --git a/Source/Level/Awards.cpp b/Source/Level/Awards.cpp index b5da1db..7fa37a8 100644 --- a/Source/Level/Awards.cpp +++ b/Source/Level/Awards.cpp @@ -49,8 +49,9 @@ static const int bonus_values[bonus_count] = { void award_bonus(int playerid, int bonusid, int alt_value) { - if (playerid != 0) + if (playerid != 0) { return; + } bonus = bonusid; bonustime = 0; bonusvalue = alt_value ? alt_value : bonus_values[bonusid]; @@ -84,8 +85,9 @@ int award_awards(int* awards) } bool alldead = true; for (unsigned i = 1; i < Person::players.size(); i++) { - if (Person::players[i]->dead != 2) + if (Person::players[i]->dead != 2) { alldead = 0; + } } if (alldead) { awards[numawards] = awardalldead; @@ -93,8 +95,9 @@ int award_awards(int* awards) } alldead = 1; for (unsigned i = 1; i < Person::players.size(); i++) { - if (Person::players[i]->dead != 1) + if (Person::players[i]->dead != 1) { alldead = 0; + } } if (alldead) { awards[numawards] = awardnodead; @@ -134,8 +137,9 @@ int award_awards(int* awards) } alldead = 1; for (unsigned i = 1; i < Person::players.size(); i++) { - if (Person::players[i]->dead != 2) + if (Person::players[i]->dead != 2) { alldead = 0; + } } if (numafterkill > 0 && alldead) { awards[numawards] = awardbrutal; diff --git a/Source/Level/Campaign.cpp b/Source/Level/Campaign.cpp index 0ff7392..410abcc 100644 --- a/Source/Level/Campaign.cpp +++ b/Source/Level/Campaign.cpp @@ -45,8 +45,9 @@ std::vector ListCampaigns() std::vector campaignNames; while ((campaign = readdir(campaigns)) != NULL) { std::string name(campaign->d_name); - if (name.length() < 5) + if (name.length() < 5) { continue; + } if (!name.compare(name.length() - 4, 4, ".txt")) { campaignNames.push_back(name.substr(0, name.length() - 4)); } diff --git a/Source/Level/Dialog.cpp b/Source/Level/Dialog.cpp index ce15da6..79740e0 100644 --- a/Source/Level/Dialog.cpp +++ b/Source/Level/Dialog.cpp @@ -69,8 +69,9 @@ std::string funpackf_string(FILE* tfile, int maxlength) char* text = new char[maxlength]; for (m = 0; m < templength; m++) { funpackf(tfile, "Bb", &text[m]); - if (text[m] == '\0') + if (text[m] == '\0') { break; + } } text[m] = 0; std::string result(text); @@ -104,8 +105,9 @@ DialogScene::DialogScene(FILE* tfile) funpackf(tfile, "Bi", &participantfocus); funpackf(tfile, "Bi", &participantaction); - for (int m = 0; m < 10; m++) + for (int m = 0; m < 10; m++) { funpackf(tfile, "Bf Bf Bf", &participantfacing[m].x, &participantfacing[m].y, &participantfacing[m].z); + } funpackf(tfile, "Bf Bf", &camerayaw, &camerapitch); } @@ -143,8 +145,9 @@ DialogScene::DialogScene(ifstream& ipstream) ipstream.ignore(256, ' '); getline(ipstream, text); for (int j = 0; j < 128; j++) { - if (text[j] == '\\') + if (text[j] == '\\') { text[j] = '\n'; + } } ipstream.ignore(256, ':'); ipstream >> sound; @@ -228,8 +231,9 @@ void DialogScene::save(FILE* tfile) fpackf(tfile, "Bi", participantfocus); fpackf(tfile, "Bi", participantaction); - for (int m = 0; m < 10; m++) + for (int m = 0; m < 10; m++) { fpackf(tfile, "Bf Bf Bf", participantfacing[m].x, participantfacing[m].y, participantfacing[m].z); + } fpackf(tfile, "Bf Bf", camerayaw, camerapitch); } diff --git a/Source/MacCompatibility.cpp b/Source/MacCompatibility.cpp index dc1ad47..4ed3033 100644 --- a/Source/MacCompatibility.cpp +++ b/Source/MacCompatibility.cpp @@ -94,8 +94,9 @@ Duration AbsoluteDeltaToDuration(AbsoluteTime& a, AbsoluteTime& b) value2 |= b.lo; value -= value2; - if (value <= 0) + if (value <= 0) { return durationImmediate; + } __int64 frac = value % g_appTime.counterRate; value /= g_appTime.counterRate; diff --git a/Source/Math/Frustum.cpp b/Source/Math/Frustum.cpp index 516b9ce..3c7f21b 100644 --- a/Source/Math/Frustum.cpp +++ b/Source/Math/Frustum.cpp @@ -99,31 +99,42 @@ int FRUSTUM:: for (int i = 0; i < 6; i++) { c = 0; - if (frustum[i][0] * (x - size) + frustum[i][1] * (y - size) + frustum[i][2] * (z - size) + frustum[i][3] > 0) + if (frustum[i][0] * (x - size) + frustum[i][1] * (y - size) + frustum[i][2] * (z - size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x + size) + frustum[i][1] * (y - size) + frustum[i][2] * (z - size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x + size) + frustum[i][1] * (y - size) + frustum[i][2] * (z - size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x - size) + frustum[i][1] * (y + size) + frustum[i][2] * (z - size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x - size) + frustum[i][1] * (y + size) + frustum[i][2] * (z - size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x + size) + frustum[i][1] * (y + size) + frustum[i][2] * (z - size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x + size) + frustum[i][1] * (y + size) + frustum[i][2] * (z - size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x - size) + frustum[i][1] * (y - size) + frustum[i][2] * (z + size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x - size) + frustum[i][1] * (y - size) + frustum[i][2] * (z + size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x + size) + frustum[i][1] * (y - size) + frustum[i][2] * (z + size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x + size) + frustum[i][1] * (y - size) + frustum[i][2] * (z + size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x - size) + frustum[i][1] * (y + size) + frustum[i][2] * (z + size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x - size) + frustum[i][1] * (y + size) + frustum[i][2] * (z + size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x + size) + frustum[i][1] * (y + size) + frustum[i][2] * (z + size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x + size) + frustum[i][1] * (y + size) + frustum[i][2] * (z + size) + frustum[i][3] > 0) { c++; - if (c == 0) + } + if (c == 0) { return 0; - if (c == 8) + } + if (c == 8) { c2++; + } } - if (c2 >= 6) + if (c2 >= 6) { return 2; - else + } else { return 1; + } } int FRUSTUM:: @@ -133,31 +144,42 @@ int FRUSTUM:: for (int i = 0; i < 6; i++) { c = 0; - if (frustum[i][0] * (x - size) + frustum[i][1] * (y - height) + frustum[i][2] * (z - size) + frustum[i][3] > 0) + if (frustum[i][0] * (x - size) + frustum[i][1] * (y - height) + frustum[i][2] * (z - size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x + size) + frustum[i][1] * (y - height) + frustum[i][2] * (z - size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x + size) + frustum[i][1] * (y - height) + frustum[i][2] * (z - size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x - size) + frustum[i][1] * (y + height) + frustum[i][2] * (z - size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x - size) + frustum[i][1] * (y + height) + frustum[i][2] * (z - size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x + size) + frustum[i][1] * (y + height) + frustum[i][2] * (z - size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x + size) + frustum[i][1] * (y + height) + frustum[i][2] * (z - size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x - size) + frustum[i][1] * (y - height) + frustum[i][2] * (z + size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x - size) + frustum[i][1] * (y - height) + frustum[i][2] * (z + size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x + size) + frustum[i][1] * (y - height) + frustum[i][2] * (z + size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x + size) + frustum[i][1] * (y - height) + frustum[i][2] * (z + size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x - size) + frustum[i][1] * (y + height) + frustum[i][2] * (z + size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x - size) + frustum[i][1] * (y + height) + frustum[i][2] * (z + size) + frustum[i][3] > 0) { c++; - if (frustum[i][0] * (x + size) + frustum[i][1] * (y + height) + frustum[i][2] * (z + size) + frustum[i][3] > 0) + } + if (frustum[i][0] * (x + size) + frustum[i][1] * (y + height) + frustum[i][2] * (z + size) + frustum[i][3] > 0) { c++; - if (c == 0) + } + if (c == 0) { return 0; - if (c == 8) + } + if (c == 8) { c2++; + } } - if (c2 >= 6) + if (c2 >= 6) { return 2; - else + } else { return 1; + } } int FRUSTUM:: @@ -166,13 +188,15 @@ int FRUSTUM:: static int c2; for (int i = 0; i < 6; i++) { - if (frustum[i][0] * x + frustum[i][1] * y + frustum[i][2] * z + frustum[i][3] > -1 * radius) + if (frustum[i][0] * x + frustum[i][1] * y + frustum[i][2] * z + frustum[i][3] > -1 * radius) { c2++; - else + } else { return 0; + } } - if (c2 >= 6) + if (c2 >= 6) { return 2; - else + } else { return 1; + } } diff --git a/Source/Math/XYZ.cpp b/Source/Math/XYZ.cpp index 113ddf5..a78655a 100644 --- a/Source/Math/XYZ.cpp +++ b/Source/Math/XYZ.cpp @@ -85,15 +85,17 @@ bool PointInTriangle(XYZ* p, XYZ normal, XYZ* p1, XYZ* p2, XYZ* p3) b = u0 / u2; if (0.0f <= b && b <= 1.0f) { a = (v0 - b * v2) / v1; - if ((a >= 0.0f) && ((a + b) <= 1.0f)) + if ((a >= 0.0f) && ((a + b) <= 1.0f)) { bInter = 1; + } } } else { b = (v0 * u1 - u0 * v1) / (v2 * u1 - u2 * v1); if (0.0f <= b && b <= 1.0f) { a = (u0 - b * u2) / u1; - if ((a >= 0.0f) && ((a + b) <= 1.0f)) + if ((a >= 0.0f) && ((a + b) <= 1.0f)) { bInter = 1; + } } } @@ -115,14 +117,16 @@ bool LineFacet(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ* p) //Calculate the position on the line that intersects the plane denom = n.x * (p2.x - p1.x) + n.y * (p2.y - p1.y) + n.z * (p2.z - p1.z); - if (fabs(denom) < 0.0000001) // Line and plane don't intersect + if (fabs(denom) < 0.0000001) { // Line and plane don't intersect return 0; + } mu = -(d + n.x * p1.x + n.y * p1.y + n.z * p1.z) / denom; p->x = p1.x + mu * (p2.x - p1.x); p->y = p1.y + mu * (p2.y - p1.y); p->z = p1.z + mu * (p2.z - p1.z); - if (mu < 0 || mu > 1) // Intersection not along line segment + if (mu < 0 || mu > 1) { // Intersection not along line segment return 0; + } if (!PointInTriangle(p, n, &pa, &pb, &pc)) { return 0; @@ -146,14 +150,16 @@ float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ* p) //Calculate the position on the line that intersects the plane denom = n.x * (p2.x - p1.x) + n.y * (p2.y - p1.y) + n.z * (p2.z - p1.z); - if (fabs(denom) < 0.0000001) // Line and plane don't intersect + if (fabs(denom) < 0.0000001) { // Line and plane don't intersect return 0; + } mu = -(d + n.x * p1.x + n.y * p1.y + n.z * p1.z) / denom; p->x = p1.x + mu * (p2.x - p1.x); p->y = p1.y + mu * (p2.y - p1.y); p->z = p1.z + mu * (p2.z - p1.z); - if (mu < 0 || mu > 1) // Intersection not along line segment + if (mu < 0 || mu > 1) { // Intersection not along line segment return 0; + } if (!PointInTriangle(p, n, &pa, &pb, &pc)) { return 0; @@ -172,14 +178,16 @@ float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ n, XYZ* p) //Calculate the position on the line that intersects the plane denom = n.x * (p2.x - p1.x) + n.y * (p2.y - p1.y) + n.z * (p2.z - p1.z); - if (fabs(denom) < 0.0000001) // Line and plane don't intersect + if (fabs(denom) < 0.0000001) { // Line and plane don't intersect return 0; + } mu = -(d + n.x * p1.x + n.y * p1.y + n.z * p1.z) / denom; p->x = p1.x + mu * (p2.x - p1.x); p->y = p1.y + mu * (p2.y - p1.y); p->z = p1.z + mu * (p2.z - p1.z); - if (mu < 0 || mu > 1) // Intersection not along line segment + if (mu < 0 || mu > 1) { // Intersection not along line segment return 0; + } if (!PointInTriangle(p, n, &pa, &pb, &pc)) { return 0; @@ -202,14 +210,16 @@ float LineFacetd(XYZ* p1, XYZ* p2, XYZ* pa, XYZ* pb, XYZ* pc, XYZ* p) //Calculate the position on the line that intersects the plane denom = n.x * (p2->x - p1->x) + n.y * (p2->y - p1->y) + n.z * (p2->z - p1->z); - if (fabs(denom) < 0.0000001) // Line and plane don't intersect + if (fabs(denom) < 0.0000001) { // Line and plane don't intersect return 0; + } mu = -(d + n.x * p1->x + n.y * p1->y + n.z * p1->z) / denom; p->x = p1->x + mu * (p2->x - p1->x); p->y = p1->y + mu * (p2->y - p1->y); p->z = p1->z + mu * (p2->z - p1->z); - if (mu < 0 || mu > 1) // Intersection not along line segment + if (mu < 0 || mu > 1) { // Intersection not along line segment return 0; + } if (!PointInTriangle(p, n, pa, pb, pc)) { return 0; @@ -227,14 +237,16 @@ float LineFacetd(XYZ* p1, XYZ* p2, XYZ* pa, XYZ* pb, XYZ* pc, XYZ* n, XYZ* p) //Calculate the position on the line that intersects the plane denom = n->x * (p2->x - p1->x) + n->y * (p2->y - p1->y) + n->z * (p2->z - p1->z); - if (fabs(denom) < 0.0000001) // Line and plane don't intersect + if (fabs(denom) < 0.0000001) { // Line and plane don't intersect return 0; + } mu = -(d + n->x * p1->x + n->y * p1->y + n->z * p1->z) / denom; p->x = p1->x + mu * (p2->x - p1->x); p->y = p1->y + mu * (p2->y - p1->y); p->z = p1->z + mu * (p2->z - p1->z); - if (mu < 0 || mu > 1) // Intersection not along line segment + if (mu < 0 || mu > 1) { // Intersection not along line segment return 0; + } if (!PointInTriangle(p, *n, pa, pb, pc)) { return 0; diff --git a/Source/Menu/Menu.cpp b/Source/Menu/Menu.cpp index 4242ff0..b181769 100644 --- a/Source/Menu/Menu.cpp +++ b/Source/Menu/Menu.cpp @@ -120,32 +120,36 @@ void Menu::addMapLabel(int id, const string& text, int x, int y, float r, float void Menu::setText(int id, const string& text) { - for (vector::iterator it = items.begin(); it != items.end(); it++) + for (vector::iterator it = items.begin(); it != items.end(); it++) { if (it->id == id) { it->text = text; it->w = it->text.length() * 10; break; } + } } void Menu::setText(int id, const string& text, int x, int y, int w, int h) { - for (vector::iterator it = items.begin(); it != items.end(); it++) + for (vector::iterator it = items.begin(); it != items.end(); it++) { if (it->id == id) { it->text = text; it->x = x; it->y = y; - if (w == -1) + if (w == -1) { it->w = it->text.length() * 10; - if (h == -1) + } + if (h == -1) { it->h = 20; + } break; } + } } int Menu::getSelected(int mousex, int mousey) { - for (vector::reverse_iterator it = items.rbegin(); it != items.rend(); it++) + for (vector::reverse_iterator it = items.rbegin(); it != items.rend(); it++) { if (it->type == MenuItem::BUTTON || it->type == MenuItem::IMAGEBUTTON || it->type == MenuItem::MAPMARKER) { int mx = mousex; int my = mousey; @@ -153,9 +157,11 @@ int Menu::getSelected(int mousex, int mousey) mx -= 1; my += 2; } - if (mx >= it->x && mx < it->x + it->w && my >= it->y && my < it->y + it->h) + if (mx >= it->x && mx < it->x + it->w && my >= it->y && my < it->y + it->h) { return it->id; + } } + } return -1; } @@ -164,12 +170,14 @@ void Menu::handleFadeEffect() for (vector::iterator it = items.begin(); it != items.end(); it++) { if (it->id == Game::selected) { it->effectfade += multiplier * 5; - if (it->effectfade > 1) + if (it->effectfade > 1) { it->effectfade = 1; + } } else { it->effectfade -= multiplier * 5; - if (it->effectfade < 0) + if (it->effectfade < 0) { it->effectfade = 0; + } } } } @@ -292,18 +300,24 @@ void Menu::updateSettingsMenu() } setText(0, sbuf); setText(14, fullscreen ? "Fullscreen: On" : "Fullscreen: Off"); - if (newdetail == 0) + if (newdetail == 0) { setText(1, "Detail: Low"); - if (newdetail == 1) + } + if (newdetail == 1) { setText(1, "Detail: Medium"); - if (newdetail == 2) + } + if (newdetail == 2) { setText(1, "Detail: High"); - if (bloodtoggle == 0) + } + if (bloodtoggle == 0) { setText(2, "Blood: Off"); - if (bloodtoggle == 1) + } + if (bloodtoggle == 1) { setText(2, "Blood: On, low detail"); - if (bloodtoggle == 2) + } + if (bloodtoggle == 2) { setText(2, "Blood: On, high detail (slower)"); + } setText(4, ismotionblur ? "Blur Effects: Enabled (less compatible)" : "Blur Effects: Disabled (more compatible)"); setText(5, decalstoggle ? "Decals: Enabled (slower)" : "Decals: Disabled"); setText(6, musictoggle ? "Music: Enabled" : "Music: Disabled"); @@ -445,10 +459,11 @@ void Menu::Load() addButton(2, "No", 10, 320); break; case 7: - if (Account::getNbAccounts() < 8) + if (Account::getNbAccounts() < 8) { addButton(0, "New User", 10, 400); - else + } else { addLabel(0, "No More Users", 10, 400); + } addLabel(-2, "", 20, 400); addButton(Account::getNbAccounts() + 1, "Back", 10, 10); for (int i = 0; i < Account::getNbAccounts(); i++) { @@ -474,8 +489,9 @@ void Menu::Load() int fasttime = (int)round(Account::active().getFastTime(i)); name += to_string(int((fasttime - fasttime % 60) / 60)); name += ":"; - if (fasttime % 60 < 10) + if (fasttime % 60 < 10) { name += "0"; + } name += to_string(fasttime % 60); addButton(i, name, 10, 400 - i * 25, i > Account::active().getProgress() ? 0.5 : 1, 0, 0); @@ -544,8 +560,9 @@ void Menu::Tick() Account::active().endGame(); endgame = 0; } - if (mainmenu == 10) + if (mainmenu == 10) { endgame = 2; + } if (mainmenu == 18 && Input::isKeyPressed(MOUSEBUTTON_RIGHT) && selected == 1) { stereoseparation -= 0.001; updateStereoConfigMenu(); @@ -575,18 +592,24 @@ void Menu::Tick() fireSound(); flash(); mainmenu = 3; - if (newdetail > 2) + if (newdetail > 2) { newdetail = detail; - if (newdetail < 0) + } + if (newdetail < 0) { newdetail = detail; - if (newscreenwidth > 3000) + } + if (newscreenwidth > 3000) { newscreenwidth = screenwidth; - if (newscreenwidth < 0) + } + if (newscreenwidth < 0) { newscreenwidth = screenwidth; - if (newscreenheight > 3000) + } + if (newscreenheight > 3000) { newscreenheight = screenheight; - if (newscreenheight < 0) + } + if (newscreenheight < 0) { newscreenheight = screenheight; + } break; case 3: fireSound(); @@ -617,13 +640,15 @@ void Menu::Tick() break; case 1: newdetail++; - if (newdetail > 2) + if (newdetail > 2) { newdetail = 0; + } break; case 2: bloodtoggle++; - if (bloodtoggle > 2) + if (bloodtoggle > 2) { bloodtoggle = 0; + } break; case 4: ismotionblur = !ismotionblur; @@ -662,13 +687,15 @@ void Menu::Tick() break; case 10: usermousesensitivity += .2; - if (usermousesensitivity > 2) + if (usermousesensitivity > 2) { usermousesensitivity = .2; + } break; case 11: volume += .1f; - if (volume > 1.0001f) + if (volume > 1.0001f) { volume = 0; + } OPENAL_SetSFXMasterVolume((int)(volume * 255)); break; case 12: @@ -689,10 +716,12 @@ void Menu::Tick() case 4: if (!waiting) { fireSound(); - if (selected < (devtools ? 10 : 9) && keyselect == -1) + if (selected < (devtools ? 10 : 9) && keyselect == -1) { keyselect = selected; - if (keyselect != -1) + } + if (keyselect != -1) { setKeySelected(); + } if (selected == (devtools ? 10 : 9)) { flash(); mainmenu = 3; @@ -758,12 +787,14 @@ void Menu::Tick() vector campaigns = ListCampaigns(); vector::iterator c; if ((c = find(campaigns.begin(), campaigns.end(), Account::active().getCurrentCampaign())) == campaigns.end()) { - if (!campaigns.empty()) + if (!campaigns.empty()) { Account::active().setCurrentCampaign(campaigns.front()); + } } else { c++; - if (c == campaigns.end()) + if (c == campaigns.end()) { c = campaigns.begin(); + } Account::active().setCurrentCampaign(*c); } Load(); @@ -804,8 +835,9 @@ void Menu::Tick() case 8: fireSound(); flash(); - if (selected <= 2) + if (selected <= 2) { Account::active().setDifficulty(selected); + } mainmenu = 5; break; case 9: @@ -844,17 +876,18 @@ void Menu::Tick() } break; case 18: - if (selected == 1) + if (selected == 1) { stereoseparation += 0.001; - else { + } else { fireSound(); if (selected == 0) { newstereomode = (StereoMode)(newstereomode + 1); while (!CanInitStereo(newstereomode)) { printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode).c_str(), newstereomode); newstereomode = (StereoMode)(newstereomode + 1); - if (newstereomode >= stereoCount) + if (newstereomode >= stereoCount) { newstereomode = stereoNone; + } } } else if (selected == 2) { stereoreverse = !stereoreverse; @@ -905,8 +938,9 @@ void Menu::Tick() setText(-2, newuserblink ? "_" : "", 20 + newuserselected * 10, 400, -1, -1); } - if (oldmainmenu != mainmenu) + if (oldmainmenu != mainmenu) { Load(); + } oldmainmenu = mainmenu; } diff --git a/Source/Objects/Object.cpp b/Source/Objects/Object.cpp index f0dd169..081f23d 100644 --- a/Source/Objects/Object.cpp +++ b/Source/Objects/Object.cpp @@ -251,42 +251,58 @@ void Object::handleRot(int divide) { messedwith -= multiplier; if (rotxvel || rotx) { - if (rotx > 0) + if (rotx > 0) { rotxvel -= multiplier * 8 * fabs(rotx); - if (rotx < 0) + } + if (rotx < 0) { rotxvel += multiplier * 8 * fabs(rotx); - if (rotx > 0) + } + if (rotx > 0) { rotxvel -= multiplier * 4; - if (rotx < 0) + } + if (rotx < 0) { rotxvel += multiplier * 4; - if (rotxvel > 0) + } + if (rotxvel > 0) { rotxvel -= multiplier * 4; - if (rotxvel < 0) + } + if (rotxvel < 0) { rotxvel += multiplier * 4; - if (fabs(rotx) < multiplier * 4) + } + if (fabs(rotx) < multiplier * 4) { rotx = 0; - if (fabs(rotxvel) < multiplier * 4) + } + if (fabs(rotxvel) < multiplier * 4) { rotxvel = 0; + } rotx += rotxvel * multiplier * 4; } if (rotyvel || roty) { - if (roty > 0) + if (roty > 0) { rotyvel -= multiplier * 8 * fabs(roty); - if (roty < 0) + } + if (roty < 0) { rotyvel += multiplier * 8 * fabs(roty); - if (roty > 0) + } + if (roty > 0) { rotyvel -= multiplier * 4; - if (roty < 0) + } + if (roty < 0) { rotyvel += multiplier * 4; - if (rotyvel > 0) + } + if (rotyvel > 0) { rotyvel -= multiplier * 4; - if (rotyvel < 0) + } + if (rotyvel < 0) { rotyvel += multiplier * 4; - if (fabs(roty) < multiplier * 4) + } + if (fabs(roty) < multiplier * 4) { roty = 0; - if (fabs(rotyvel) < multiplier * 4) + } + if (fabs(rotyvel) < multiplier * 4) { rotyvel = 0; + } roty += rotyvel * multiplier * 4; } @@ -296,14 +312,18 @@ void Object::handleRot(int divide) if (rotx) { glRotatef(-rotx / divide, 0, 0, 1); } - if (rotx > 10) + if (rotx > 10) { rotx = 10; - if (rotx < -10) + } + if (rotx < -10) { rotx = -10; - if (roty > 10) + } + if (roty > 10) { roty = 10; - if (roty < -10) + } + if (roty < -10) { roty = -10; + } } void Object::draw() @@ -321,22 +341,25 @@ void Object::draw() hidden = !(distsqflat(&viewer, &position) > playerdist + 3 || (type != bushtype && type != treeleavestype)); if (!hidden) { - if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment) + if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment) { glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness); - else + } else { glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0); + } distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance; - if (distance > 1) + if (distance > 1) { distance = 1; + } if (distance > 0) { if (occluded < 6) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); - if (!model.color) + if (!model.color) { glEnable(GL_LIGHTING); - else + } else { glDisable(GL_LIGHTING); + } glDepthMask(1); glTranslatef(position.x, position.y, position.z); if (type == bushtype) { @@ -634,8 +657,9 @@ void Object::DoShadows() { XYZ lightloc; lightloc = light.location; - if (!skyboxtexture) + if (!skyboxtexture) { lightloc = 0; + } lightloc.y += 10; Normalise(&lightloc); diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 3c89326..073ad0b 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -454,8 +454,9 @@ Person::Person(FILE* tfile, int mapvers, unsigned i) for (int k = 0; k < numclothes; k++) { int templength; funpackf(tfile, "Bi", &templength); - for (int l = 0; l < templength; l++) + for (int l = 0; l < templength; l++) { funpackf(tfile, "Bb", &clothes[k][l]); + } clothes[k][templength] = '\0'; funpackf(tfile, "Bf Bf Bf", &clothestintr[k], &clothestintg[k], &clothestintb[k]); } @@ -520,8 +521,9 @@ void Person::skeletonLoad(bool clothes) */ void Person::CheckKick() { - if (!(hasvictim && (animTarget == rabbitkickanim && victim && victim != this->shared_from_this() && frameCurrent >= 2 && animCurrent == rabbitkickanim) && distsq(&coords, &victim->coords) < 1.2 && !victim->skeleton.free)) + if (!(hasvictim && (animTarget == rabbitkickanim && victim && victim != this->shared_from_this() && frameCurrent >= 2 && animCurrent == rabbitkickanim) && distsq(&coords, &victim->coords) < 1.2 && !victim->skeleton.free)) { return; + } if (Animation::animations[victim->animTarget].height != lowheight) { float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power; @@ -531,16 +533,18 @@ void Person::CheckKick() victim->spurt = 1; DoBlood(.2, 250); - if (!Tutorial::active) + if (!Tutorial::active) { emit_sound_at(heavyimpactsound, victim->coords); + } victim->RagDoll(0); for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) { victim->skeleton.joints[i].velocity += relative * 120 * damagemult; } victim->Puff(neck); victim->DoDamage(100 * damagemult / victim->protectionhigh); - if (id == 0) + if (id == 0) { camerashake += .4; + } target = 0; frameCurrent = 3; @@ -549,8 +553,9 @@ void Person::CheckKick() velocity = facing * -10; velocity.y = 5; skeleton.free = 0; - if (id == 0) + if (id == 0) { resume_stream(whooshsound); + } award_bonus(id, cannon); } else if (victim->isCrouch()) { @@ -609,52 +614,70 @@ void Person::CatchFire() */ int Person::getIdle() { - if (Dialog::inDialog() && (howactive == typeactive) && (creature == rabbittype)) + if (Dialog::inDialog() && (howactive == typeactive) && (creature == rabbittype)) { return talkidleanim; + } if (hasvictim && (victim != this->shared_from_this())) { if ((!victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < Person::players.size())) { if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) { - if (creature == rabbittype) + if (creature == rabbittype) { return fightidleanim; - if (creature == wolftype) + } + if (creature == wolftype) { return wolfidle; + } } if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) { - if (weapons[weaponids[weaponactive]].getType() == knife) + if (weapons[weaponids[weaponactive]].getType() == knife) { return knifefightidleanim; - if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1) + } + if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1) { return swordfightidlebothanim; - if (weapons[weaponids[weaponactive]].getType() == sword) + } + if (weapons[weaponids[weaponactive]].getType() == sword) { return swordfightidleanim; - if (weapons[weaponids[weaponactive]].getType() == staff) + } + if (weapons[weaponids[weaponactive]].getType() == staff) { return swordfightidleanim; + } } - if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause) + if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause) { return fightsidestep; + } } } - if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype) + if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype) { return hurtidleanim; - if (howactive == typesitting) + } + if (howactive == typesitting) { return sitanim; - if (howactive == typesittingwall) + } + if (howactive == typesittingwall) { return sitwallanim; - if (howactive == typesleeping) + } + if (howactive == typesleeping) { return sleepanim; - if (howactive == typedead1) + } + if (howactive == typedead1) { return dead1anim; - if (howactive == typedead2) + } + if (howactive == typedead2) { return dead2anim; - if (howactive == typedead3) + } + if (howactive == typedead3) { return dead3anim; - if (howactive == typedead4) + } + if (howactive == typedead4) { return dead4anim; - if (creature == rabbittype) + } + if (creature == rabbittype) { return bounceidleanim; - if (creature == wolftype) + } + if (creature == wolftype) { return wolfidle; + } return 0; } @@ -663,10 +686,12 @@ int Person::getIdle() */ int Person::getCrouch() { - if (creature == rabbittype) + if (creature == rabbittype) { return crouchanim; - if (creature == wolftype) + } + if (creature == wolftype) { return wolfcrouchanim; + } return 0; } @@ -675,15 +700,19 @@ int Person::getCrouch() */ int Person::getRun() { - if (creature == rabbittype && (!superruntoggle || weaponactive != -1)) + if (creature == rabbittype && (!superruntoggle || weaponactive != -1)) { return runanim; - if (creature == wolftype && (!superruntoggle)) + } + if (creature == wolftype && (!superruntoggle)) { return wolfrunanim; + } - if (creature == rabbittype && (superruntoggle && weaponactive == -1)) + if (creature == rabbittype && (superruntoggle && weaponactive == -1)) { return rabbitrunninganim; - if (creature == wolftype && (superruntoggle)) + } + if (creature == wolftype && (superruntoggle)) { return wolfrunninganim; + } return 0; } @@ -691,10 +720,12 @@ int Person::getRun() */ int Person::getStop() { - if (creature == rabbittype) + if (creature == rabbittype) { return stopanim; - if (creature == wolftype) + } + if (creature == wolftype) { return wolfstopanim; + } return 0; } @@ -702,10 +733,12 @@ int Person::getStop() */ int Person::getLanding() { - if (creature == rabbittype) + if (creature == rabbittype) { return landanim; - if (creature == wolftype) + } + if (creature == wolftype) { return wolflandanim; + } return 0; } @@ -713,10 +746,12 @@ int Person::getLanding() */ int Person::getLandhard() { - if (creature == rabbittype) + if (creature == rabbittype) { return landhardanim; - if (creature == wolftype) + } + if (creature == wolftype) { return wolflandhardanim; + } return 0; } @@ -728,10 +763,11 @@ int Person::getLandhard() static void SolidHitBonus(int playerid) { - if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo) + if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo) { award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1); - else + } else { award_bonus(playerid, solidhit); + } } /* EFFECT @@ -761,7 +797,7 @@ void Person::DoBlood(float howmuch, int which) Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1); } } - if (Random() % 2 == 0) // 50% chance + if (Random() % 2 == 0) { // 50% chance for (int i = 0; i < 3; i++) { if (Random() % 2 != 0) { // emit teeth particles @@ -783,22 +819,25 @@ void Person::DoBlood(float howmuch, int which) Sprite::setLastSpriteSpecial(3); // sets it to teeth } } + } } if (decalstoggle) { // FIXME: manipulating attributes bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25; bleedxint = 0; bleedyint = 0; - if (creature == rabbittype) + if (creature == rabbittype) { while (bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) { bleedxint = abs(Random() % 512); bleedyint = abs(Random() % 512); } - if (creature == wolftype) + } + if (creature == wolftype) { while (wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) { bleedxint = abs(Random() % 512); bleedyint = abs(Random() % 512); } + } bleedy = bleedxint; bleedx = bleedyint; bleedy /= realtexdetail; @@ -806,8 +845,9 @@ void Person::DoBlood(float howmuch, int which) direction = abs(Random() % 2) * 2 - 1; } } - if (bleeding > 2) + if (bleeding > 2) { bleeding = 2; + } } /* EFFECT @@ -818,27 +858,32 @@ void Person::DoBloodBig(float howmuch, int which) { static int bleedxint, bleedyint, i, j; static XYZ bloodvel; - if (howmuch && id == 0) + if (howmuch && id == 0) { blooddimamount = 1; + } - if (!Tutorial::active || id == 0) + if (!Tutorial::active || id == 0) { if (aitype != playercontrolled && howmuch > 0) { // play pain sounds int whichsound = -1; if (creature == wolftype) { int i = abs(Random() % 2); - if (i == 0) + if (i == 0) { whichsound = snarlsound; - if (i == 1) + } + if (i == 1) { whichsound = snarl2sound; + } } if (creature == rabbittype) { int i = abs(Random() % 2); - if (i == 0) + if (i == 0) { whichsound = rabbitpainsound; - if (i == 1 && howmuch >= 2) + } + if (i == 1 && howmuch >= 2) { whichsound = rabbitpain1sound; + } } if (whichsound != -1) { @@ -846,6 +891,7 @@ void Person::DoBloodBig(float howmuch, int which) addEnvSound(coords); } } + } if (id == 0 && howmuch > 0) { Game::flash(.5, 0); @@ -903,54 +949,70 @@ void Person::DoBloodBig(float howmuch, int which) int endx = 0; int endy = 0; GLubyte color; - if (creature == rabbittype) + if (creature == rabbittype) { for (i = 0; i < 512; i++) { for (j = 0; j < 512; j++) { if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) { - if (i < startx) + if (i < startx) { startx = i; - if (j < starty) + } + if (j < starty) { starty = j; - if (i > endx) + } + if (i > endx) { endx = i; - if (j > endy) + } + if (j > endy) { endy = j; + } } } } - if (creature == wolftype) + } + if (creature == wolftype) { for (i = 0; i < 512; i++) { for (j = 0; j < 512; j++) { if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) { - if (i < startx) + if (i < startx) { startx = i; - if (j < starty) + } + if (j < starty) { starty = j; - if (i > endx) + } + if (i > endx) { endx = i; - if (j > endy) + } + if (j > endy) { endy = j; + } } } } + } startx += offsetx; endx += offsetx; starty += offsety; endy += offsety; - if (startx < 0) + if (startx < 0) { startx = 0; - if (starty < 0) + } + if (starty < 0) { starty = 0; - if (endx > 512 - 1) + } + if (endx > 512 - 1) { endx = 512 - 1; - if (endy > 512 - 1) + } + if (endy > 512 - 1) { endy = 512 - 1; - if (endx < startx) + } + if (endx < startx) { endx = startx; - if (endy < starty) + } + if (endy < starty) { endy = starty; + } startx /= realtexdetail; starty /= realtexdetail; @@ -959,59 +1021,69 @@ void Person::DoBloodBig(float howmuch, int which) int texdetailint = realtexdetail; int where; - if (creature == rabbittype) + if (creature == rabbittype) { for (i = startx; i < endx; i++) { for (j = starty; j < endy; j++) { if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) { color = Random() % 85 + 170; where = i * skeleton.skinsize * 3 + j * 3; - if (skeleton.skinText[where + 0] > color / 2) + if (skeleton.skinText[where + 0] > color / 2) { skeleton.skinText[where + 0] = color / 2; + } skeleton.skinText[where + 1] = 0; skeleton.skinText[where + 2] = 0; } } } - if (creature == wolftype) + } + if (creature == wolftype) { for (i = startx; i < endx; i++) { for (j = starty; j < endy; j++) { if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) { color = Random() % 85 + 170; where = i * skeleton.skinsize * 3 + j * 3; - if (skeleton.skinText[where + 0] > color / 2) + if (skeleton.skinText[where + 0] > color / 2) { skeleton.skinText[where + 0] = color / 2; + } skeleton.skinText[where + 1] = 0; skeleton.skinText[where + 2] = 0; } } } + } skeleton.drawmodel.textureptr.bind(); DoMipmaps(); bleedxint = 0; bleedyint = 0; - if (creature == rabbittype) + if (creature == rabbittype) { while (bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) { bleedxint = abs(Random() % 512); bleedyint = abs(Random() % 512); } - if (creature == wolftype) + } + if (creature == wolftype) { while (wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) { bleedxint = abs(Random() % 512); bleedyint = abs(Random() % 512); } + } bleedy = bleedxint + offsetx; bleedx = bleedyint + offsety; bleedy /= realtexdetail; bleedx /= realtexdetail; - if (bleedx < 0) + if (bleedx < 0) { bleedx = 0; - if (bleedy < 0) + } + if (bleedy < 0) { bleedy = 0; - if (bleedx > skeleton.skinsize - 1) + } + if (bleedx > skeleton.skinsize - 1) { bleedx = skeleton.skinsize - 1; - if (bleedy > skeleton.skinsize - 1) + } + if (bleedy > skeleton.skinsize - 1) { bleedy = skeleton.skinsize - 1; + } direction = abs(Random() % 2) * 2 - 1; } bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25; @@ -1022,12 +1094,14 @@ void Person::DoBloodBig(float howmuch, int which) if (abs(Random() % 2) == 0) { aitype = gethelptype; lastseentime = 12; - } else + } else { aitype = attacktypecutoff; + } ally = 0; } - if (bleeding > 2) + if (bleeding > 2) { bleeding = 2; + } } /* EFFECT @@ -1048,8 +1122,9 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) if (bloodtoggle && decalstoggle && !Tutorial::active) { where -= coords; - if (!skeleton.free) + if (!skeleton.free) { where = DoRotation(where, 0, -yaw, 0); + } //where=scale; startpoint = where; startpoint.y += 100; @@ -1125,53 +1200,69 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) int endx = 0; int endy = 0; GLubyte color; - if (creature == rabbittype) + if (creature == rabbittype) { for (i = 0; i < 512; i++) { for (j = 0; j < 512; j++) { if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) { - if (i < startx) + if (i < startx) { startx = i; - if (j < starty) + } + if (j < starty) { starty = j; - if (i > endx) + } + if (i > endx) { endx = i; - if (j > endy) + } + if (j > endy) { endy = j; + } } } } - if (creature == wolftype) + } + if (creature == wolftype) { for (i = 0; i < 512; i++) { for (j = 0; j < 512; j++) { if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) { - if (i < startx) + if (i < startx) { startx = i; - if (j < starty) + } + if (j < starty) { starty = j; - if (i > endx) + } + if (i > endx) { endx = i; - if (j > endy) + } + if (j > endy) { endy = j; + } } } } + } startx += offsetx; endx += offsetx; starty += offsety; endy += offsety; - if (startx < 0) + if (startx < 0) { startx = 0; - if (starty < 0) + } + if (starty < 0) { starty = 0; - if (endx > 512 - 1) + } + if (endx > 512 - 1) { endx = 512 - 1; - if (endy > 512 - 1) + } + if (endy > 512 - 1) { endy = 512 - 1; - if (endx < startx) + } + if (endx < startx) { endx = startx; - if (endy < starty) + } + if (endy < starty) { endy = starty; + } startx /= realtexdetail; starty /= realtexdetail; @@ -1180,46 +1271,52 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) int texdetailint = realtexdetail; int where; - if (creature == rabbittype) + if (creature == rabbittype) { for (i = startx; i < endx; i++) { for (j = starty; j < endy; j++) { if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) { color = Random() % 85 + 170; where = i * skeleton.skinsize * 3 + j * 3; - if (skeleton.skinText[where + 0] > color / 2) + if (skeleton.skinText[where + 0] > color / 2) { skeleton.skinText[where + 0] = color / 2; + } skeleton.skinText[where + 1] = 0; skeleton.skinText[where + 2] = 0; } else if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) { color = Random() % 85 + 170; where = i * skeleton.skinsize * 3 + j * 3; - if (skeleton.skinText[where + 0] > color / 2) + if (skeleton.skinText[where + 0] > color / 2) { skeleton.skinText[where + 0] = color / 2; + } skeleton.skinText[where + 1] = 0; skeleton.skinText[where + 2] = 0; } } } - if (creature == wolftype) + } + if (creature == wolftype) { for (i = startx; i < endx; i++) { for (j = starty; j < endy; j++) { if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) { color = Random() % 85 + 170; where = i * skeleton.skinsize * 3 + j * 3; - if (skeleton.skinText[where + 0] > color / 2) + if (skeleton.skinText[where + 0] > color / 2) { skeleton.skinText[where + 0] = color / 2; + } skeleton.skinText[where + 1] = 0; skeleton.skinText[where + 2] = 0; } else if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) { color = Random() % 85 + 170; where = i * skeleton.skinsize * 3 + j * 3; - if (skeleton.skinText[where + 0] > color / 2) + if (skeleton.skinText[where + 0] > color / 2) { skeleton.skinText[where + 0] = color / 2; + } skeleton.skinText[where + 1] = 0; skeleton.skinText[where + 2] = 0; } } } + } skeleton.drawmodel.textureptr.bind(); DoMipmaps(); @@ -1227,18 +1324,23 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) bleedx = coordsx * 512; bleedy /= realtexdetail; bleedx /= realtexdetail; - if (bleedx < 0) + if (bleedx < 0) { bleedx = 0; - if (bleedy < 0) + } + if (bleedy < 0) { bleedy = 0; - if (bleedx > skeleton.skinsize - 1) + } + if (bleedx > skeleton.skinsize - 1) { bleedx = skeleton.skinsize - 1; - if (bleedy > skeleton.skinsize - 1) + } + if (bleedy > skeleton.skinsize - 1) { bleedy = skeleton.skinsize - 1; + } direction = abs(Random() % 2) * 2 - 1; } - if (whichtri == -1) + if (whichtri == -1) { return 0; + } } bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25; deathbleeding += bleeding; @@ -1248,12 +1350,14 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) if (abs(Random() % 2) == 0) { aitype = gethelptype; lastseentime = 12; - } else + } else { aitype = attacktypecutoff; + } ally = 0; } - if (bleeding > 2) + if (bleeding > 2) { bleeding = 2; + } return 1; } @@ -1262,11 +1366,13 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) */ void Person::Reverse() { - if (!((victim->aitype == playercontrolled || hostiletime > 1 || staggerdelay <= 0) && victim->animTarget != jumpupanim && victim->animTarget != jumpdownanim && (!Tutorial::active || cananger) && hostile)) + if (!((victim->aitype == playercontrolled || hostiletime > 1 || staggerdelay <= 0) && victim->animTarget != jumpupanim && victim->animTarget != jumpdownanim && (!Tutorial::active || cananger) && hostile)) { return; + } - if (normaldotproduct(victim->facing, victim->coords - coords) > 0 && (victim->id != 0 || difficulty >= 2) && (creature != wolftype || victim->creature == wolftype)) + if (normaldotproduct(victim->facing, victim->coords - coords) > 0 && (victim->id != 0 || difficulty >= 2) && (creature != wolftype || victim->creature == wolftype)) { return; + } if (animTarget == sweepanim) { animTarget = sweepreversedanim; @@ -1296,14 +1402,16 @@ void Person::Reverse() if (victim->weaponactive != -1) { victim->throwtogglekeydown = 1; XYZ tempVelocity = victim->velocity * .2; - if (tempVelocity.x == 0) + if (tempVelocity.x == 0) { tempVelocity.x = .1; + } weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false); victim->num_weapons--; if (victim->num_weapons) { victim->weaponids[0] = victim->weaponids[victim->num_weapons]; - if (victim->weaponstuck == victim->num_weapons) + if (victim->weaponstuck == victim->num_weapons) { victim->weaponstuck = 0; + } } victim->weaponactive = -1; @@ -1321,14 +1429,16 @@ void Person::Reverse() if (victim->weaponactive != -1) { victim->throwtogglekeydown = 1; XYZ tempVelocity = victim->velocity * .2; - if (tempVelocity.x == 0) + if (tempVelocity.x == 0) { tempVelocity.x = .1; + } weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false); victim->num_weapons--; if (victim->num_weapons) { victim->weaponids[0] = victim->weaponids[victim->num_weapons]; - if (victim->weaponstuck == victim->num_weapons) + if (victim->weaponstuck == victim->num_weapons) { victim->weaponstuck = 0; + } } victim->weaponactive = -1; @@ -1345,14 +1455,16 @@ void Person::Reverse() if (victim->weaponactive != -1) { victim->throwtogglekeydown = 1; XYZ tempVelocity = victim->velocity * .2; - if (tempVelocity.x == 0) + if (tempVelocity.x == 0) { tempVelocity.x = .1; + } weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false); victim->num_weapons--; if (victim->num_weapons) { victim->weaponids[0] = victim->weaponids[victim->num_weapons]; - if (victim->weaponstuck == victim->num_weapons) + if (victim->weaponstuck == victim->num_weapons) { victim->weaponstuck = 0; + } } victim->weaponactive = -1; @@ -1369,14 +1481,16 @@ void Person::Reverse() if (victim->weaponactive != -1) { victim->throwtogglekeydown = 1; XYZ tempVelocity = victim->velocity * .2; - if (tempVelocity.x == 0) + if (tempVelocity.x == 0) { tempVelocity.x = .1; + } weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false); victim->num_weapons--; if (victim->num_weapons) { victim->weaponids[0] = victim->weaponids[victim->num_weapons]; - if (victim->weaponstuck == victim->num_weapons) + if (victim->weaponstuck == victim->num_weapons) { victim->weaponstuck = 0; + } } victim->weaponactive = -1; @@ -1430,10 +1544,12 @@ void Person::Reverse() if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) { if (victim->weaponactive != -1) { if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) { - if (weapons[victim->weaponids[0]].getType() == staff) + if (weapons[victim->weaponids[0]].getType() == staff) { weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; - if (weapons[weaponids[0]].getType() == staff) + } + if (weapons[weaponids[0]].getType() == staff) { weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; + } emit_sound_at(swordstaffsound, victim->coords); } else { emit_sound_at(metalhitsound, victim->coords); @@ -1452,8 +1568,9 @@ void Person::Reverse() victim->num_weapons--; if (victim->num_weapons) { victim->weaponids[0] = victim->weaponids[num_weapons]; - if (victim->weaponstuck == victim->num_weapons) + if (victim->weaponstuck == victim->num_weapons) { victim->weaponstuck = 0; + } } victim->weaponactive = -1; for (unsigned i = 0; i < Person::players.size(); i++) { @@ -1464,10 +1581,12 @@ void Person::Reverse() if (abs(Random() % 20) == 0) { if (weaponactive != -1) { if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) { - if (weapons[victim->weaponids[0]].getType() == staff) + if (weapons[victim->weaponids[0]].getType() == staff) { weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; - if (weapons[weaponids[0]].getType() == staff) + } + if (weapons[weaponids[0]].getType() == staff) { weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; + } emit_sound_at(swordstaffsound, coords); } else { @@ -1488,8 +1607,9 @@ void Person::Reverse() num_weapons--; if (num_weapons) { weaponids[0] = weaponids[num_weapons]; - if (weaponstuck == num_weapons) + if (weaponstuck == num_weapons) { weaponstuck = 0; + } } weaponactive = -1; for (unsigned i = 0; i < Person::players.size(); i++) { @@ -1497,7 +1617,7 @@ void Person::Reverse() } } } - if (hasvictim) + if (hasvictim) { if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) { if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) { victim->animTarget = dodgebackanim; @@ -1509,8 +1629,9 @@ void Person::Reverse() Normalise(&rotatetarget); victim->targetyaw = -asin(0 - rotatetarget.x); victim->targetyaw *= 360 / 6.28; - if (rotatetarget.z < 0) + if (rotatetarget.z < 0) { victim->targetyaw = 180 - victim->targetyaw; + } victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70; @@ -1527,8 +1648,9 @@ void Person::Reverse() Normalise(&rotatetarget); victim->targetyaw = -asin(0 - rotatetarget.x); victim->targetyaw *= 360 / 6.28; - if (rotatetarget.z < 0) + if (rotatetarget.z < 0) { victim->targetyaw = 180 - victim->targetyaw; + } victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70; @@ -1537,6 +1659,7 @@ void Person::Reverse() victim->lastattack = victim->animTarget; } } + } velocity = 0; victim->velocity = 0; @@ -1551,8 +1674,9 @@ void Person::Reverse() } } - if (victim->id == 0 && Animation::animations[victim->animTarget].attack == reversal) + if (victim->id == 0 && Animation::animations[victim->animTarget].attack == reversal) { numreversals++; + } } /* EFFECT @@ -1579,10 +1703,12 @@ void Person::DoDamage(float howmuch) superpermanentdamage += howmuch / 4 / power; } // visual effects - if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2) + if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2) { DoBlood(1, 255); - if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt) + } + if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt) { DoBlood(1, 255); + } spurt = 0; if (id == 0) { camerashake += howmuch / 100; @@ -1595,14 +1721,16 @@ void Person::DoDamage(float howmuch) } // cancel attack? - if (aitype == passivetype && damage < damagetolerance && ((!Tutorial::active || cananger) && hostile)) + if (aitype == passivetype && damage < damagetolerance && ((!Tutorial::active || cananger) && hostile)) { aitype = attacktypecutoff; + } if (!Tutorial::active && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) { if (abs(Random() % 2) == 0) { aitype = gethelptype; lastseentime = 12; - } else + } else { aitype = attacktypecutoff; + } ally = 0; } @@ -1644,17 +1772,21 @@ void Person::DoDamage(float howmuch) if (creature == wolftype) { int i = abs(Random() % 2); - if (i == 0) + if (i == 0) { whichsound = snarlsound; - if (i == 1) + } + if (i == 1) { whichsound = snarl2sound; + } } if (creature == rabbittype) { int i = abs(Random() % 2); - if (i == 0) + if (i == 0) { whichsound = rabbitpainsound; - if (i == 1 && damage > damagetolerance) + } + if (i == 1 && damage > damagetolerance) { whichsound = rabbitpain1sound; + } } if (whichsound != -1) { @@ -1681,53 +1813,68 @@ void Person::DoHead() targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100; targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100; - while (targetheadyaw > 180) + while (targetheadyaw > 180) { targetheadyaw -= 360; - while (targetheadyaw < -180) + } + while (targetheadyaw < -180) { targetheadyaw += 360; + } - if (targetheadyaw > 160) + if (targetheadyaw > 160) { targetheadpitch = targetheadpitch * -1; - if (targetheadyaw < -160) + } + if (targetheadyaw < -160) { targetheadpitch = targetheadpitch * -1; - if (targetheadyaw > 160) + } + if (targetheadyaw > 160) { targetheadyaw = targetheadyaw - 180; - if (targetheadyaw < -160) + } + if (targetheadyaw < -160) { targetheadyaw = targetheadyaw + 180; + } - if (targetheadpitch > 120) + if (targetheadpitch > 120) { targetheadpitch = 120; - if (targetheadpitch < -120) + } + if (targetheadpitch < -120) { targetheadpitch = -120; - if (targetheadyaw > 120) + } + if (targetheadyaw > 120) { targetheadyaw = 120; - if (targetheadyaw < -120) + } + if (targetheadyaw < -120) { targetheadyaw = -120; + } - if (!isIdle()) + if (!isIdle()) { targetheadpitch = 0; + } if (isIdle()) { - if (targetheadyaw > 80) + if (targetheadyaw > 80) { targetheadyaw = 80; - if (targetheadyaw < -80) + } + if (targetheadyaw < -80) { targetheadyaw = -80; - if (targetheadpitch > 50) + } + if (targetheadpitch > 50) { targetheadpitch = 50; - if (targetheadpitch < -50) + } + if (targetheadpitch < -50) { targetheadpitch = -50; + } } - if (abs(headyaw - targetheadyaw) < multiplier * lookspeed) + if (abs(headyaw - targetheadyaw) < multiplier * lookspeed) { headyaw = targetheadyaw; - else if (headyaw > targetheadyaw) { + } else if (headyaw > targetheadyaw) { headyaw -= multiplier * lookspeed; } else if (headyaw < targetheadyaw) { headyaw += multiplier * lookspeed; } - if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2) + if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2) { headpitch = targetheadpitch; - else if (headpitch > targetheadpitch) { + } else if (headpitch > targetheadpitch) { headpitch -= multiplier * lookspeed / 2; } else if (headpitch < targetheadpitch) { headpitch += multiplier * lookspeed / 2; @@ -1772,10 +1919,12 @@ void Person::RagDoll(bool checkcollision) static int i; static float speed; if (!skeleton.free) { - if (id == 0) + if (id == 0) { numfalls++; - if (id == 0 && isFlip()) + } + if (id == 0 && isFlip()) { numflipfail++; + } escapednum = 0; @@ -1793,29 +1942,38 @@ void Person::RagDoll(bool checkcollision) freefall = 1; skeleton.freefall = 1; - if (!isnormal(velocity.x)) + if (!isnormal(velocity.x)) { velocity.x = 0; - if (!isnormal(velocity.y)) + } + if (!isnormal(velocity.y)) { velocity.y = 0; - if (!isnormal(velocity.z)) + } + if (!isnormal(velocity.z)) { velocity.z = 0; - if (!isnormal(yaw)) + } + if (!isnormal(yaw)) { yaw = 0; - if (!isnormal(coords.x)) + } + if (!isnormal(coords.x)) { coords = 0; - if (!isnormal(tilt)) + } + if (!isnormal(tilt)) { tilt = 0; - if (!isnormal(tilt2)) + } + if (!isnormal(tilt2)) { tilt2 = 0; + } for (unsigned i = 0; i < skeleton.joints.size(); i++) { skeleton.joints[i].delay = 0; skeleton.joints[i].locked = 0; skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0); - if (!isnormal(skeleton.joints[i].position.x)) + if (!isnormal(skeleton.joints[i].position.x)) { skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0); - if (!isnormal(skeleton.joints[i].position.x)) + } + if (!isnormal(skeleton.joints[i].position.x)) { skeleton.joints[i].position = coords; + } skeleton.joints[i].position.y += .1; skeleton.joints[i].oldposition = skeleton.joints[i].position; skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords; @@ -1837,16 +1995,18 @@ void Person::RagDoll(bool checkcollision) if (currentFrame().speed > targetFrame().speed) { speed = currentFrame().speed * 2; } - if (transspeed) + if (transspeed) { speed = transspeed * 2; + } speed *= speedmult; for (unsigned i = 0; i < skeleton.joints.size(); i++) { - if ((Animation::animations[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && Animation::animations[animCurrent].height == Animation::animations[animTarget].height) + if ((Animation::animations[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && Animation::animations[animCurrent].height == Animation::animations[animTarget].height) { skeleton.joints[i].velocity = velocity / scale + facing * 5 + DoRotation(DoRotation(DoRotation((targetFrame().joints[i].position - currentFrame().joints[i].position) * speed, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0); - else + } else { skeleton.joints[i].velocity = velocity / scale + facing * 5; + } change.x = (float)(Random() % 100) / 100; change.y = (float)(Random() % 100) / 100; change.z = (float)(Random() % 100) / 100; @@ -1906,8 +2066,9 @@ void Person::RagDoll(bool checkcollision) num_weapons--; if (num_weapons) { weaponids[0] = weaponids[num_weapons]; - if (weaponstuck == num_weapons) + if (weaponstuck == num_weapons) { weaponstuck = 0; + } } weaponactive = -1; for (unsigned i = 0; i < Person::players.size(); i++) { @@ -1937,12 +2098,14 @@ void Person::FootLand(bodypart whichfoot, float opacity) if (opacity > 1) { footvel = 0; footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords; - if (distsq(&footpoint, &viewer)) + if (distsq(&footpoint, &viewer)) { Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity); + } } else if (onterrain && terrain.getOpacity(coords.x, coords.z) < .2) { footvel = velocity / 5; - if (footvel.y < .8) + if (footvel.y < .8) { footvel.y = .8; + } footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords; footpoint.y = terrain.getHeight(footpoint.x, footpoint.z); terrainlight = terrain.getLighting(footpoint.x, footpoint.z); @@ -1963,8 +2126,9 @@ void Person::FootLand(bodypart whichfoot, float opacity) } } else if (isLanding() || (animTarget == jumpupanim) || isLandhard()) { footvel = velocity / 5; - if (footvel.y < .8) + if (footvel.y < .8) { footvel.y = .8; + } footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords; if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity); @@ -2004,8 +2168,9 @@ void Person::DoAnimations() if (!skeleton.free) { static float oldtarget; - if (isIdle() && animCurrent != getIdle()) + if (isIdle() && animCurrent != getIdle()) { normalsupdatedelay = 0; + } if (animTarget == tempanim || animCurrent == tempanim) { Animation::animations[tempanim] = tempanimation; @@ -2024,10 +2189,12 @@ void Person::DoAnimations() OPENAL_3D_SetAttributes(channels[whooshsound], gLoc); OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5); } - if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z)) + if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z)) { landhard = 1; - if (!crouchkeydown && velocity.y >= -15) + } + if (!crouchkeydown && velocity.y >= -15) { landhard = 0; + } } if ((animCurrent == jumpupanim || animTarget == jumpdownanim) /*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) { XYZ targfacing; @@ -2036,34 +2203,41 @@ void Person::DoAnimations() targfacing = DoRotation(targfacing, 0, targetyaw, 0); - if (normaldotproduct(targfacing, velocity) >= -.3) + if (normaldotproduct(targfacing, velocity) >= -.3) { animTarget = flipanim; - else + } else { animTarget = backflipanim; + } crouchtogglekeydown = 1; frameTarget = 0; target = 0; - if (id == 0) + if (id == 0) { numflipped++; + } } - if (Animation::animations[animTarget].attack != reversed) + if (Animation::animations[animTarget].attack != reversed) { feint = 0; + } if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) { crouchtogglekeydown = 0; - if (aitype == playercontrolled) + if (aitype == playercontrolled) { feint = 0; + } } else { - if (!crouchtogglekeydown && Animation::animations[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain)) + if (!crouchtogglekeydown && Animation::animations[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain)) { feint = 1; - if (!isFlip()) + } + if (!isFlip()) { crouchtogglekeydown = 1; + } } if (Animation::animations[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) { - if (detail) + if (detail) { normalsupdatedelay = 0; + } } if (target >= 1) { @@ -2075,19 +2249,22 @@ void Person::DoAnimations() } if (animTarget == rabbittacklinganim && frameTarget == 1) { - if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0) + if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0) { Reverse(); + } if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) { - if (normaldotproduct(victim->facing, facing) > 0) + if (normaldotproduct(victim->facing, facing) > 0) { victim->animTarget = rabbittackledbackanim; - else + } else { victim->animTarget = rabbittackledfrontanim; + } victim->frameTarget = 2; victim->target = 0; victim->yaw = yaw; victim->targetyaw = yaw; - if (victim->aitype == gethelptype) + if (victim->aitype == gethelptype) { victim->DoDamage(victim->damagetolerance - victim->damage); + } //victim->DoDamage(30); if (creature == wolftype) { DoBloodBig(0, 255); @@ -2102,10 +2279,11 @@ void Person::DoAnimations() if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (targetFrame().label || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) { if (weapons[weaponids[0]].getType() == knife) { - if (weaponactive == -1) + if (weaponactive == -1) { weaponactive = 0; - else if (weaponactive == 0) + } else if (weaponactive == 0) { weaponactive = -1; + } if (weaponactive == -1) { emit_sound_at(knifesheathesound, coords); @@ -2117,46 +2295,54 @@ void Person::DoAnimations() drawtogglekeydown = 1; } //Footstep sounds - if (!Tutorial::active || id == 0) + if (!Tutorial::active || id == 0) { if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) { int whichsound = -1; if (onterrain) { if (terrain.getOpacity(coords.x, coords.z) < .2) { - if (targetFrame().label == 1) + if (targetFrame().label == 1) { whichsound = footstepsound; - else + } else { whichsound = footstepsound2; - if (targetFrame().label == 1) + } + if (targetFrame().label == 1) { FootLand(leftfoot, 1); - if (targetFrame().label == 2) + } + if (targetFrame().label == 2) { FootLand(rightfoot, 1); + } if (targetFrame().label == 3 && isRun()) { FootLand(rightfoot, 1); FootLand(leftfoot, 1); } } if (terrain.getOpacity(coords.x, coords.z) >= .2) { - if (targetFrame().label == 1) + if (targetFrame().label == 1) { whichsound = footstepsound3; - else + } else { whichsound = footstepsound4; + } } } if (!onterrain) { - if (targetFrame().label == 1) + if (targetFrame().label == 1) { whichsound = footstepsound3; - else + } else { whichsound = footstepsound4; + } } if (targetFrame().label == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) { if (Animation::animations[animTarget].attack != neutral) { unsigned r = abs(Random() % 3); - if (r == 0) + if (r == 0) { whichsound = lowwhooshsound; - if (r == 1) + } + if (r == 1) { whichsound = midwhooshsound; - if (r == 2) + } + if (r == 2) { whichsound = highwhooshsound; + } } if (Animation::animations[animTarget].attack == neutral) { whichsound = movewhooshsound; @@ -2187,35 +2373,44 @@ void Person::DoAnimations() } } } + } //Combat sounds - if (!Tutorial::active || id == 0) - if (speechdelay <= 0) - if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) + if (!Tutorial::active || id == 0) { + if (speechdelay <= 0) { + if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) { if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) { int whichsound = -1; if (targetFrame().label == 4 && aitype != playercontrolled) { if (Animation::animations[animTarget].attack != neutral) { unsigned r = abs(Random() % 4); if (creature == rabbittype) { - if (r == 0) + if (r == 0) { whichsound = rabbitattacksound; - if (r == 1) + } + if (r == 1) { whichsound = rabbitattack2sound; - if (r == 2) + } + if (r == 2) { whichsound = rabbitattack3sound; - if (r == 3) + } + if (r == 3) { whichsound = rabbitattack4sound; + } } if (creature == wolftype) { - if (r == 0) + if (r == 0) { whichsound = barksound; - if (r == 1) + } + if (r == 1) { whichsound = bark2sound; - if (r == 2) + } + if (r == 2) { whichsound = bark3sound; - if (r == 3) + } + if (r == 3) { whichsound = barkgrowlsound; + } } speechdelay = .3; } @@ -2225,6 +2420,9 @@ void Person::DoAnimations() emit_sound_at(whichsound, coords); } } + } + } + } if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) { FootLand(leftfoot, 1); @@ -2239,7 +2437,7 @@ void Person::DoAnimations() if (animTarget == removeknifeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { for (unsigned i = 0; i < weapons.size(); i++) { - if (weapons[i].owner == -1) + if (weapons[i].owner == -1) { if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) { if (distsq(&coords, &weapons[i].position) >= 1) { if (weapons[i].getType() != staff) { @@ -2249,27 +2447,33 @@ void Person::DoAnimations() takeWeapon(i); } } + } } } if (animTarget == crouchremoveknifeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { for (unsigned i = 0; i < weapons.size(); i++) { bool willwork = true; - if (weapons[i].owner != -1) - if (Person::players[weapons[i].owner]->weaponstuck != -1) - if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i)) - if (Person::players[weapons[i].owner]->num_weapons > 1) + if (weapons[i].owner != -1) { + if (Person::players[weapons[i].owner]->weaponstuck != -1) { + if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i)) { + if (Person::players[weapons[i].owner]->num_weapons > 1) { willwork = 0; - if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free)) + } + } + } + } + if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free)) { if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) { if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) { bool fleshstuck = false; - if (weapons[i].owner != -1) + if (weapons[i].owner != -1) { if (victim->weaponstuck != -1) { if (victim->weaponids[victim->weaponstuck] == int(i)) { fleshstuck = true; } } + } if (fleshstuck) { emit_sound_at(fleshstabremovesound, coords, 128.); } else { @@ -2279,10 +2483,11 @@ void Person::DoAnimations() } if (weapons[i].owner != -1) { victim = Person::players[weapons[i].owner]; - if (victim->num_weapons == 1) + if (victim->num_weapons == 1) { victim->num_weapons = 0; - else + } else { victim->num_weapons = 1; + } //victim->weaponactive=-1; victim->skeleton.longdead = 0; @@ -2303,18 +2508,21 @@ void Person::DoAnimations() footpoint = weapons[i].position; if (victim->weaponstuck != -1) { if (victim->weaponids[victim->weaponstuck] == int(i)) { - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3); + } weapons[i].bloody = 2; weapons[i].blooddrip = 5; victim->weaponstuck = -1; } } if (victim->num_weapons > 0) { - if (victim->weaponstuck != 0 && victim->weaponstuck != -1) + if (victim->weaponstuck != 0 && victim->weaponstuck != -1) { victim->weaponstuck = 0; - if (victim->weaponids[0] == int(i)) + } + if (victim->weaponids[0] == int(i)) { victim->weaponids[0] = victim->weaponids[victim->num_weapons]; + } } victim->jointVel(abdomen) += relative * 6; @@ -2325,13 +2533,14 @@ void Person::DoAnimations() takeWeapon(i); } } + } } } if (animCurrent == drawleftanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { - if (weaponactive == -1) + if (weaponactive == -1) { weaponactive = 0; - else if (weaponactive == 0) { + } else if (weaponactive == 0) { weaponactive = -1; if (num_weapons == 2) { int buffer; @@ -2353,24 +2562,31 @@ void Person::DoAnimations() Normalise(&rotatetarget); targetyaw = -asin(0 - rotatetarget.x); targetyaw *= 360 / 6.28; - if (rotatetarget.z < 0) + if (rotatetarget.z < 0) { targetyaw = 180 - targetyaw; + } - if (animTarget == walljumprightkickanim) + if (animTarget == walljumprightkickanim) { targetyaw += 40; - if (animTarget == walljumpleftkickanim) + } + if (animTarget == walljumpleftkickanim) { targetyaw -= 40; + } } bool dojumpattack; dojumpattack = 0; - if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0)) + if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0)) { dojumpattack = 1; - if (hasvictim) - if (distsq(&victim->coords, &/*Person::players[i]->*/ coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1) + } + if (hasvictim) { + if (distsq(&victim->coords, &/*Person::players[i]->*/ coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1) { dojumpattack = 1; - if (!hostile) + } + } + if (!hostile) { dojumpattack = 0; + } if (dojumpattack) { if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) { animTarget = rabbittackleanim; @@ -2387,13 +2603,14 @@ void Person::DoAnimations() Normalise(&targetloc); targetloc += coords; for (unsigned i = 0; i < Person::players.size(); i++) { - if (i != id) + if (i != id) { if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) { closestdist = distsq(&targetloc, &Person::players[i]->coords); closestid = i; } + } } - if (closestid != -1) + if (closestid != -1) { if (closestdist < 5 && !Person::players[closestid]->dead && Animation::animations[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) { hasvictim = 1; victim = Person::players[closestid]; @@ -2408,19 +2625,22 @@ void Person::DoAnimations() Normalise(&rotatetarget); targetyaw = -asin(0 - rotatetarget.x); targetyaw *= 360 / 6.28; - if (rotatetarget.z < 0) + if (rotatetarget.z < 0) { targetyaw = 180 - targetyaw; + } } if (animTarget != rabbitrunninganim) { emit_sound_at(jumpsound, coords, 128.); } } + } } //Move impacts float damagemult = 1 * power; - if (creature == wolftype) + if (creature == wolftype) { damagemult = 2.5 * power; + } if (hasvictim) { damagemult /= victim->damagetolerance / 200; } @@ -2428,13 +2648,15 @@ void Person::DoAnimations() if (animTarget == spinkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2 || creature == wolftype) { victim->spurt = 1; DoBlood(.2, 250); - if (creature == wolftype) + if (creature == wolftype) { DoBloodBig(0, 250); + } } if (!Tutorial::active) { emit_sound_at(heavyimpactsound, victim->coords, 128.); @@ -2464,12 +2686,14 @@ void Person::DoAnimations() if (animTarget == wolfslapanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2 || creature == wolftype) { victim->spurt = 1; - if (creature == wolftype) + if (creature == wolftype) { DoBloodBig(0, 235); + } } emit_sound_at(whooshhitsound, victim->coords); if (creature == wolftype) { @@ -2497,8 +2721,9 @@ void Person::DoAnimations() if (animTarget == walljumprightkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } victim->spurt = 1; DoBlood(.2, 250); if (!Tutorial::active) { @@ -2522,18 +2747,20 @@ void Person::DoAnimations() victim->Puff(head); victim->DoDamage(damagemult * 150 / victim->protectionhead); - if (victim->damage > victim->damagetolerance) + if (victim->damage > victim->damagetolerance) { award_bonus(id, style); - else + } else { SolidHitBonus(id); + } } } if (animTarget == walljumpleftkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } victim->spurt = 1; DoBlood(.2, 250); if (!Tutorial::active) { @@ -2557,18 +2784,20 @@ void Person::DoAnimations() victim->Puff(head); victim->DoDamage(damagemult * 150 / victim->protectionhead); - if (victim->damage > victim->damagetolerance) + if (victim->damage > victim->damagetolerance) { award_bonus(id, style); - else + } else { SolidHitBonus(id); + } } } if (animTarget == blockhighleftstrikeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2) { victim->spurt = 1; DoBlood(.2, 235); @@ -2591,8 +2820,9 @@ void Person::DoAnimations() if (animTarget == killanim && Animation::animations[animTarget].frames[frameCurrent].label == 8) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .2; + } emit_sound_at(whooshhitsound, victim->coords, 128.); victim->skeleton.longdead = 0; @@ -2625,8 +2855,9 @@ void Person::DoAnimations() if (animTarget == killanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (!Tutorial::active) { emit_sound_at(heavyimpactsound, coords, 128.); } @@ -2650,8 +2881,9 @@ void Person::DoAnimations() if (animTarget == dropkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (!Tutorial::active) { emit_sound_at(thudsound, coords); } @@ -2674,23 +2906,27 @@ void Person::DoAnimations() for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) { victim->skeleton.joints[i].velocity += relative * damagemult * 20; } - if (!victim->dead) + if (!victim->dead) { SolidHitBonus(id); + } victim->Puff(abdomen); victim->DoDamage(damagemult * 20 / victim->protectionhigh); victim->jointVel(abdomen) += relative * damagemult * 200; staggerdelay = .5; - if (!victim->dead) + if (!victim->dead) { staggerdelay = 1.2; + } } } if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) { - if (hasvictim) - if (!victim->skeleton.free) + if (hasvictim) { + if (!victim->skeleton.free) { hasvictim = 0; + } + } if (!hasvictim) { terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360); @@ -2706,8 +2942,9 @@ void Person::DoAnimations() if (weapons[weaponids[weaponactive]].getType() == knife) { where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4); where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } //where=scale; startpoint = where; startpoint.y += 100; @@ -2717,25 +2954,29 @@ void Person::DoAnimations() if (weapons[weaponids[weaponactive]].getType() == sword) { where = weapons[weaponids[weaponactive]].position; where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } startpoint = where; where = weapons[weaponids[weaponactive]].tippoint; where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } endpoint = where; } if (weapons[weaponids[weaponactive]].getType() == staff) { where = weapons[weaponids[weaponactive]].position; where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } startpoint = where; where = weapons[weaponids[weaponactive]].tippoint; where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } endpoint = where; } movepoint = 0; @@ -2745,11 +2986,13 @@ void Person::DoAnimations() if (whichtri != -1) { if (victim->dead != 2) { victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2)); - if (!victim->dead) + if (!victim->dead) { award_bonus(id, FinishedBonus); + } } - if (bloodtoggle) + if (bloodtoggle) { weapons[weaponids[weaponactive]].bloody = 2; + } victim->skeleton.longdead = 0; victim->skeleton.free = 1; @@ -2794,13 +3037,15 @@ void Person::DoAnimations() where = weapons[weaponids[weaponactive]].position; where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } startpoint = where; where = weapons[weaponids[weaponactive]].tippoint; where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } endpoint = where; movepoint = 0; @@ -2819,13 +3064,15 @@ void Person::DoAnimations() where = weapons[weaponids[weaponactive]].position; where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } startpoint = where; where = weapons[weaponids[weaponactive]].tippoint; where -= victim->coords; - if (!victim->skeleton.free) + if (!victim->skeleton.free) { where = DoRotation(where, 0, -victim->yaw, 0); + } endpoint = where; movepoint = 0; @@ -2855,8 +3102,9 @@ void Person::DoAnimations() relative.y = 10; Normalise(&relative); //victim->Puff(abdomen); - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3); + } if (victim->bloodloss < victim->damagetolerance) { victim->bloodloss += 1000; @@ -2876,8 +3124,9 @@ void Person::DoAnimations() if (animTarget == upunchanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2) { victim->spurt = 1; DoBlood(.2, 235); @@ -2913,8 +3162,9 @@ void Person::DoAnimations() if (animTarget == winduppunchanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && Animation::animations[victim->animTarget].height != lowheight) { if (!Tutorial::active) { emit_sound_at(thudsound, victim->coords); @@ -2929,8 +3179,9 @@ void Person::DoAnimations() } } - if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || Animation::animations[victim->animTarget].height == lowheight) + if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || Animation::animations[victim->animTarget].height == lowheight) { victim->RagDoll(0); + } XYZ relative; relative = victim->coords - coords; relative.y = 0; @@ -2957,8 +3208,9 @@ void Person::DoAnimations() if (animTarget == blockhighleftanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) { - if (victim->id == 0) + if (victim->id == 0) { camerashake += .4; + } emit_sound_at(landsound2, victim->coords); Puff(righthand); @@ -2967,15 +3219,18 @@ void Person::DoAnimations() if (animTarget == swordslashparryanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) { - if (victim->id == 0) + if (victim->id == 0) { camerashake += .4; + } if (weaponactive != -1) { if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) { - if (weapons[victim->weaponids[0]].getType() == staff) + if (weapons[victim->weaponids[0]].getType() == staff) { weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; - if (weapons[weaponids[0]].getType() == staff) + } + if (weapons[weaponids[0]].getType() == staff) { weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; + } emit_sound_at(swordstaffsound, victim->coords); } else { @@ -3003,7 +3258,7 @@ void Person::DoAnimations() } if (animTarget == knifeslashstartanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { - if (hasvictim) + if (hasvictim) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 && /*Animation::animations[victim->animTarget].height!=lowheight&&*/ victim->animTarget != dodgebackanim && victim->animTarget != rollanim) { escapednum = 0; if (!Tutorial::active) { @@ -3025,8 +3280,9 @@ void Person::DoAnimations() } victim->lowreversaldelay = 0; victim->highreversaldelay = 0; - if (aitype != playercontrolled) + if (aitype != playercontrolled) { weaponmissdelay = .6; + } if (!Tutorial::active) { if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) { @@ -3056,6 +3312,7 @@ void Person::DoAnimations() } victim->DoDamage(damagemult * 0); } + } } if (animTarget == swordslashanim && Animation::animations[animTarget].frames[frameCurrent].label == 5 && victim->animTarget != rollanim) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) { @@ -3063,10 +3320,11 @@ void Person::DoAnimations() award_bonus(id, Slashbonus); escapednum = 0; if (!Tutorial::active) { - if (normaldotproduct(victim->facing, victim->coords - coords) < 0) + if (normaldotproduct(victim->facing, victim->coords - coords) < 0) { victim->DoBloodBig(2 / victim->armorhigh, 190); - else + } else { victim->DoBloodBig(2 / victim->armorhigh, 185); + } victim->deathbleeding = 1; emit_sound_at(swordslicesound, victim->coords); victim->frameTarget = 0; @@ -3103,10 +3361,12 @@ void Person::DoAnimations() } else { if (victim->weaponactive != -1) { if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) { - if (weapons[victim->weaponids[0]].getType() == staff) + if (weapons[victim->weaponids[0]].getType() == staff) { weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; - if (weapons[weaponids[0]].getType() == staff) + } + if (weapons[weaponids[0]].getType() == staff) { weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; + } emit_sound_at(swordstaffsound, victim->coords); } else { @@ -3127,8 +3387,9 @@ void Person::DoAnimations() victim->num_weapons--; if (victim->num_weapons) { victim->weaponids[0] = victim->weaponids[num_weapons]; - if (victim->weaponstuck == victim->num_weapons) + if (victim->weaponstuck == victim->num_weapons) { victim->weaponstuck = 0; + } } victim->weaponactive = -1; for (unsigned i = 0; i < Person::players.size(); i++) { @@ -3143,8 +3404,9 @@ void Person::DoAnimations() if (!Tutorial::active) { weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250; escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2 || creature == wolftype) { victim->spurt = 1; } @@ -3177,8 +3439,9 @@ void Person::DoAnimations() if (!Tutorial::active) { weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250; escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2 || creature == wolftype) { victim->spurt = 1; } @@ -3208,10 +3471,12 @@ void Person::DoAnimations() if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) { escapednum = 0; if (!Tutorial::active) { - if (!victim->dead) + if (!victim->dead) { weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500; - if (id == 0) + } + if (id == 0) { camerashake += .4; + } if (Random() % 2 || creature == wolftype) { victim->spurt = 1; } @@ -3257,8 +3522,9 @@ void Person::DoAnimations() if (animTarget == lowkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != highheight) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } XYZ relative; relative = victim->coords - coords; relative.y = 0; @@ -3281,16 +3547,18 @@ void Person::DoAnimations() } victim->Puff(head); victim->DoDamage(damagemult * 100 / victim->protectionhead); - if (victim->howactive == typesleeping) + if (victim->howactive == typesleeping) { victim->DoDamage(damagemult * 150 / victim->protectionhead); + } if (creature == wolftype) { emit_sound_at(clawslicesound, victim->coords, 128.); victim->spurt = 1; victim->DoBloodBig(2 / victim->armorhead, 175); } } else { - if (victim->damage >= victim->damagetolerance) + if (victim->damage >= victim->damagetolerance) { victim->RagDoll(0); + } for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) { victim->skeleton.joints[i].velocity += relative * damagemult * 10; } @@ -3318,8 +3586,9 @@ void Person::DoAnimations() (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) && (victim != this->shared_from_this())) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .2; + } if (!Tutorial::active) { emit_sound_at(landsound2, victim->coords, 128.); } @@ -3337,22 +3606,25 @@ void Person::DoAnimations() relative = DoRotation(relative, 0, -90, 0); relative.y += .1; for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) { - if (victim->skeleton.joints[i].label == leftfoot || victim->skeleton.joints[i].label == rightfoot || victim->skeleton.joints[i].label == leftankle || victim->skeleton.joints[i].label == rightankle) + if (victim->skeleton.joints[i].label == leftfoot || victim->skeleton.joints[i].label == rightfoot || victim->skeleton.joints[i].label == leftankle || victim->skeleton.joints[i].label == rightankle) { victim->skeleton.joints[i].velocity = relative * 80; + } } victim->Puff(rightankle); victim->Puff(leftankle); victim->DoDamage(damagemult * 40 / victim->protectionlow); } else { - if (victim->damage >= victim->damagetolerance) + if (victim->damage >= victim->damagetolerance) { victim->RagDoll(0); + } for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) { victim->skeleton.joints[i].velocity += relative * damagemult * 10; } relative = DoRotation(relative, 0, -90, 0); for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) { - if (victim->skeleton.joints[i].label == leftfoot || victim->skeleton.joints[i].label == rightfoot || victim->skeleton.joints[i].label == leftankle || victim->skeleton.joints[i].label == rightankle) + if (victim->skeleton.joints[i].label == leftfoot || victim->skeleton.joints[i].label == rightfoot || victim->skeleton.joints[i].label == leftankle || victim->skeleton.joints[i].label == rightankle) { victim->skeleton.joints[i].velocity += relative * damagemult * 80; + } } victim->jointVel(abdomen) += relative * damagemult * 200; victim->frameTarget = 0; @@ -3373,8 +3645,9 @@ void Person::DoAnimations() if (Animation::animations[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) { if (animTarget == spinkickreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2) { victim->spurt = 1; DoBlood(.2, 230); @@ -3417,8 +3690,9 @@ void Person::DoAnimations() if (animTarget == staffhitreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2) { victim->spurt = 1; DoBlood(.2, 230); @@ -3439,8 +3713,9 @@ void Person::DoAnimations() if (animTarget == staffspinhitreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2) { victim->spurt = 1; DoBlood(.2, 230); @@ -3493,17 +3768,21 @@ void Person::DoAnimations() bool doslice; doslice = 0; - if (weaponactive != -1 || creature == wolftype) + if (weaponactive != -1 || creature == wolftype) { doslice = 1; - if (creature == rabbittype && weaponactive != -1) - if (weapons[weaponids[0]].getType() == staff) + } + if (creature == rabbittype && weaponactive != -1) { + if (weapons[weaponids[0]].getType() == staff) { doslice = 0; + } + } if (doslice) { if (weaponactive != -1) { victim->DoBloodBig(2 / victim->armorhigh, 225); emit_sound_at(knifeslicesound, victim->coords); - if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) + if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) { weapons[weaponids[weaponactive]].bloody = 1; + } weapons[weaponids[weaponactive]].blooddrip += 3; } if (weaponactive == -1 && creature == wolftype) { @@ -3539,8 +3818,9 @@ void Person::DoAnimations() if (hasvictim && animTarget == knifeslashreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2) { victim->spurt = 1; DoBlood(.2, 230); @@ -3572,8 +3852,9 @@ void Person::DoAnimations() relative = facing * -1; relative.y = -3; Normalise(&relative); - if (victim->id == 0) + if (victim->id == 0) { relative /= 30; + } for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) { victim->skeleton.joints[i].velocity += relative * damagemult * 40; } @@ -3581,17 +3862,21 @@ void Person::DoAnimations() victim->permanentdamage = victim->damagetolerance - 1; bool doslice; doslice = 0; - if (weaponactive != -1 || creature == wolftype) + if (weaponactive != -1 || creature == wolftype) { doslice = 1; - if (creature == rabbittype && weaponactive != -1) - if (weapons[weaponids[0]].getType() == staff) + } + if (creature == rabbittype && weaponactive != -1) { + if (weapons[weaponids[0]].getType() == staff) { doslice = 0; + } + } if (doslice) { if (weaponactive != -1) { victim->DoBloodBig(200, 225); emit_sound_at(knifeslicesound, victim->coords); - if (bloodtoggle) + if (bloodtoggle) { weapons[weaponids[weaponactive]].bloody = 2; + } weapons[weaponids[weaponactive]].blooddrip += 5; } @@ -3607,14 +3892,16 @@ void Person::DoAnimations() if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) { if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) { escapednum = 0; - if (animTarget == knifefollowanim) + if (animTarget == knifefollowanim) { victim->DoBloodBig(200, 210); + } if (animTarget == knifesneakattackanim) { XYZ footvel, footpoint; footvel = 0; footpoint = weapons[weaponids[0]].tippoint; - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3); + } footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position); Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); @@ -3628,8 +3915,9 @@ void Person::DoAnimations() XYZ footvel, footpoint; footvel = 0; footpoint = weapons[weaponids[0]].tippoint; - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3); + } footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1; Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); @@ -3639,8 +3927,9 @@ void Person::DoAnimations() victim->bloodloss += 10000; victim->velocity = 0; emit_sound_at(fleshstabsound, victim->coords); - if (bloodtoggle) + if (bloodtoggle) { weapons[weaponids[weaponactive]].bloody = 2; + } weapons[weaponids[weaponactive]].blooddrip += 5; } } @@ -3659,15 +3948,17 @@ void Person::DoAnimations() } if (weaponactive != -1 && Animation::animations[victim->animTarget].attack != reversal) { emit_sound_at(fleshstabremovesound, victim->coords); - if (bloodtoggle) + if (bloodtoggle) { weapons[weaponids[weaponactive]].bloody = 2; + } weapons[weaponids[weaponactive]].blooddrip += 5; XYZ footvel, footpoint; footvel = 0; footpoint = weapons[weaponids[0]].tippoint; - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3); + } footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1; Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); @@ -3685,8 +3976,9 @@ void Person::DoAnimations() XYZ footvel, footpoint; footvel = 0; footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2; - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3); + } footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position); Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); @@ -3697,8 +3989,9 @@ void Person::DoAnimations() victim->bloodloss += 10000; victim->velocity = 0; emit_sound_at(fleshstabsound, victim->coords); - if (bloodtoggle) + if (bloodtoggle) { weapons[weaponids[weaponactive]].bloody = 2; + } weapons[weaponids[weaponactive]].blooddrip += 5; } } @@ -3711,15 +4004,17 @@ void Person::DoAnimations() } if (weaponactive != -1) { emit_sound_at(fleshstabremovesound, victim->coords); - if (bloodtoggle) + if (bloodtoggle) { weapons[weaponids[weaponactive]].bloody = 2; + } weapons[weaponids[weaponactive]].blooddrip += 5; XYZ footvel, footpoint; footvel = 0; footpoint = weapons[weaponids[0]].tippoint; - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3); + } footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1; Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); @@ -3730,8 +4025,9 @@ void Person::DoAnimations() if (animTarget == sweepreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) { escapednum = 0; - if (id == 0) + if (id == 0) { camerashake += .4; + } if (Random() % 2) { victim->spurt = 1; DoBlood(.2, 240); @@ -3743,17 +4039,21 @@ void Person::DoAnimations() } bool doslice; doslice = 0; - if (weaponactive != -1 || creature == wolftype) + if (weaponactive != -1 || creature == wolftype) { doslice = 1; - if (creature == rabbittype && weaponactive != -1) - if (weapons[weaponids[0]].getType() == staff) + } + if (creature == rabbittype && weaponactive != -1) { + if (weapons[weaponids[0]].getType() == staff) { doslice = 0; + } + } if (doslice) { if (weaponactive != -1) { victim->DoBloodBig(2 / victim->armorhead, 225); emit_sound_at(knifeslicesound, victim->coords); - if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) + if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) { weapons[weaponids[weaponactive]].bloody = 1; + } weapons[weaponids[weaponactive]].blooddrip += 3; } if (weaponactive == -1 && creature == wolftype) { @@ -3778,8 +4078,9 @@ void Person::DoAnimations() victim->skeleton.joints[i].velocity += relative * damagemult * 20; } victim->jointVel(head) += relative * damagemult * 200; - if (victim->damage < victim->damagetolerance - 100) + if (victim->damage < victim->damagetolerance - 100) { victim->velocity = relative * 200; + } victim->DoDamage(damagemult * 100 / victim->protectionhead); victim->velocity = 0; } @@ -3800,10 +4101,11 @@ void Person::DoAnimations() victim->jointVel(head) += relative * damagemult * 200; } - if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim)) + if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim)) { if (victim->damage > victim->damagetolerance && bonus != reverseko) { award_bonus(id, reverseko); } + } } //Animation end @@ -3845,9 +4147,9 @@ void Person::DoAnimations() if (animCurrent == crouchdrawrightanim) { animTarget = getCrouch(); } - if (weaponactive == -1) + if (weaponactive == -1) { weaponactive = 0; - else if (weaponactive == 0) { + } else if (weaponactive == 0) { weaponactive = -1; if (num_weapons == 2) { int buffer; @@ -3882,8 +4184,9 @@ void Person::DoAnimations() animTarget = getCrouch(); frameTarget = 1; coords += facing * .1; - if (!isnormal(coords.x)) + if (!isnormal(coords.x)) { coords = oldcoords; + } oldcoords = coords; targetoffset = 0; currentoffset = 0; @@ -3905,7 +4208,7 @@ void Person::DoAnimations() int closest = -1; float closestdist = -1; float distance; - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned i = 0; i < Person::players.size(); i++) { if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) { distance = distsq(&Person::players[i]->coords, &coords); @@ -3915,6 +4218,7 @@ void Person::DoAnimations() } } } + } if (closestdist > 0 && closest >= 0 && closestdist < 16) { victim = Person::players[closest]; animTarget = walljumprightkickanim; @@ -3923,8 +4227,9 @@ void Person::DoAnimations() Normalise(&rotatetarget); yaw = -asin(0 - rotatetarget.x); yaw *= 360 / 6.28; - if (rotatetarget.z < 0) + if (rotatetarget.z < 0) { yaw = 180 - yaw; + } targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; velocity = (victim->coords - coords) * 4; velocity.y += 2; @@ -3936,8 +4241,9 @@ void Person::DoAnimations() frameTarget = 3; velocity = facing * -8; velocity.y = 4; - if (id == 0) + if (id == 0) { resume_stream(whooshsound); + } } if (animTarget == walljumprightanim) { animTarget = rightflipanim; @@ -3955,15 +4261,16 @@ void Person::DoAnimations() velocity = facing * 8; velocity.y = 4; } - if (id == 0) + if (id == 0) { resume_stream(whooshsound); + } } if (animTarget == walljumpleftanim) { if (attackkeydown) { int closest = -1; float closestdist = -1; float distance; - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned i = 0; i < Person::players.size(); i++) { if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) { distance = distsq(&Person::players[i]->coords, &coords); @@ -3973,6 +4280,7 @@ void Person::DoAnimations() } } } + } if (closestdist > 0 && closest >= 0 && closestdist < 16) { victim = Person::players[closest]; animTarget = walljumpleftkickanim; @@ -3981,8 +4289,9 @@ void Person::DoAnimations() Normalise(&rotatetarget); yaw = -asin(0 - rotatetarget.x); yaw *= 360 / 6.28; - if (rotatetarget.z < 0) + if (rotatetarget.z < 0) { yaw = 180 - yaw; + } targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; velocity = (victim->coords - coords) * 4; velocity.y += 2; @@ -3997,8 +4306,9 @@ void Person::DoAnimations() velocity = DoRotation(facing, 0, -30, 0) * -8; velocity.y = 4; } - if (id == 0) + if (id == 0) { resume_stream(whooshsound); + } } if (animTarget == sneakattackanim) { animCurrent = getCrouch(); @@ -4012,16 +4322,18 @@ void Person::DoAnimations() transspeed = 1000000; targetheadyaw += 180; coords -= facing * .7; - if (onterrain) + if (onterrain) { coords.y = terrain.getHeight(coords.x, coords.z); + } lastfeint = 0; } if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) { animTarget = getIdle(); frameTarget = 0; - if (onterrain) + if (onterrain) { coords.y = terrain.getHeight(coords.x, coords.z); + } lastfeint = 0; } @@ -4038,13 +4350,14 @@ void Person::DoAnimations() tilt2 *= -1; transspeed = 1000000; targetheadyaw += 180; - if (!isnormal(coords.x)) + if (!isnormal(coords.x)) { coords = oldcoords; - if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim) + } + if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim) { oldcoords = coords + facing * .5; - else if (animCurrent == sweepreversalanim) + } else if (animCurrent == sweepreversalanim) { oldcoords = coords + facing * 1.1; - else if (animCurrent == upunchreversalanim) { + } else if (animCurrent == upunchreversalanim) { oldcoords = coords + facing * 1.5; targetyaw += 180; yaw += 180; @@ -4065,10 +4378,11 @@ void Person::DoAnimations() targettilt2 = 0; tilt2 = 0; } - if (onterrain) + if (onterrain) { oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z); - else + } else { oldcoords.y = ycoords; + } currentoffset = coords - oldcoords; targetoffset = 0; coords = oldcoords; @@ -4082,8 +4396,9 @@ void Person::DoAnimations() } if (Animation::animations[animTarget].attack == reversed) { escapednum++; - if (animTarget == sweepreversedanim) + if (animTarget == sweepreversedanim) { targetyaw += 90; + } animTarget = backhandspringanim; frameTarget = 2; emit_sound_at(landsound, coords, 128); @@ -4108,10 +4423,12 @@ void Person::DoAnimations() if (wasFlip()) { animTarget = jumpdownanim; } - if (wasLanding()) + if (wasLanding()) { animTarget = getIdle(); - if (wasLandhard()) + } + if (wasLandhard()) { animTarget = getIdle(); + } if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) { animTarget = getIdle(); oldcoords = coords; @@ -4119,8 +4436,9 @@ void Person::DoAnimations() coords.y = oldcoords.y; //coords+=DoRotation(Animation::animations[animCurrent].offset,0,yaw,0)*scale; targetoffset.y = coords.y; - if (onterrain) + if (onterrain) { targetoffset.y = terrain.getHeight(coords.x, coords.z); + } currentoffset = DoRotation(Animation::animations[animCurrent].offset * -1, 0, yaw, 0) * scale; currentoffset.y -= (coords.y - targetoffset.y); coords.y = targetoffset.y; @@ -4136,11 +4454,14 @@ void Person::DoAnimations() targetyaw = yaw; bool hasstaff; hasstaff = 0; - if (num_weapons > 0) - if (weapons[0].getType() == staff) + if (num_weapons > 0) { + if (weapons[0].getType() == staff) { hasstaff = 1; - if (!hasstaff) + } + } + if (!hasstaff) { DoDamage(35); + } RagDoll(0); lastfeint = 0; rabbitkickragdoll = 1; @@ -4158,8 +4479,9 @@ void Person::DoAnimations() escapednum++; animTarget = rollanim; coords += facing; - if (id == 0) + if (id == 0) { pause_sound(whooshsound); + } } lastfeint = 0; } @@ -4182,8 +4504,9 @@ void Person::DoAnimations() escapednum++; animTarget = rollanim; coords += facing * 2; - if (id == 0) + if (id == 0) { pause_sound(whooshsound); + } } lastfeint = 0; } @@ -4203,14 +4526,16 @@ void Person::DoAnimations() lastfeint = 0; } if (animCurrent == spinkickanim && victim->skeleton.free) { - if (creature == rabbittype) + if (creature == rabbittype) { animTarget = fightidleanim; + } } } target = 0; - if (isIdle() && !wasIdle()) + if (isIdle() && !wasIdle()) { normalsupdatedelay = 0; + } if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) { animTarget = jumpdownanim; @@ -4220,32 +4545,38 @@ void Person::DoAnimations() oldtarget = target; if (!transspeed && Animation::animations[animTarget].attack != 2 && Animation::animations[animTarget].attack != 3) { if (!isRun() || !wasRun()) { - if (targetFrame().speed > currentFrame().speed) + if (targetFrame().speed > currentFrame().speed) { target += multiplier * targetFrame().speed * speed * 2; - if (targetFrame().speed <= currentFrame().speed) + } + if (targetFrame().speed <= currentFrame().speed) { target += multiplier * currentFrame().speed * speed * 2; + } } if (isRun() && wasRun()) { float tempspeed; tempspeed = velspeed; - if (tempspeed < 10 * speedmult) + if (tempspeed < 10 * speedmult) { tempspeed = 10 * speedmult; + } /* FIXME - mixed of target and current here, is that intended? */ target += multiplier * Animation::animations[animTarget].frames[frameCurrent].speed * speed * 1.7 * tempspeed / (speed * 45 * scale); } - } else if (transspeed) + } else if (transspeed) { target += multiplier * transspeed * speed * 2; - else { + } else { if (!isRun() || !wasRun()) { - if (targetFrame().speed > currentFrame().speed) + if (targetFrame().speed > currentFrame().speed) { target += multiplier * targetFrame().speed * 2; - if (targetFrame().speed <= currentFrame().speed) + } + if (targetFrame().speed <= currentFrame().speed) { target += multiplier * currentFrame().speed * 2; + } } } - if (animCurrent != animTarget) + if (animCurrent != animTarget) { target = (target + oldtarget) / 2; + } if (target > 1) { frameCurrent = frameTarget; @@ -4277,12 +4608,15 @@ void Person::DoAnimations() } for (unsigned i = 0; i < skeleton.muscles.size(); i++) { if (skeleton.muscles[i].visible) { - if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) + if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) { skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100; - if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) + } + if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) { skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100; - if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) + } + if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) { skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100; + } } } @@ -4300,24 +4634,33 @@ void Person::DoAnimations() } for (unsigned i = 0; i < skeleton.muscles.size(); i++) { if (skeleton.muscles[i].visible) { - if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) + if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) { skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100; - if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) + } + if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) { skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100; - if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) + } + if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) { skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100; - if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) + } + if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) { skeleton.muscles[i].newrotate3 -= 360; - if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) + } + if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) { skeleton.muscles[i].newrotate3 += 360; - if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) + } + if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) { skeleton.muscles[i].newrotate2 -= 360; - if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) + } + if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) { skeleton.muscles[i].newrotate2 += 360; - if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) + } + if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) { skeleton.muscles[i].newrotate1 -= 360; - if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) + } + if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) { skeleton.muscles[i].newrotate1 += 360; + } } } } @@ -4342,8 +4685,9 @@ void Person::DoAnimations() } if (isLanding() && landhard) { - if (id == 0) + if (id == 0) { camerashake += .4; + } animTarget = getLandhard(); frameTarget = 0; target = 0; @@ -4377,23 +4721,29 @@ void Person::DoStuff() } crouchkeydowntime += multiplier; - if (!crouchkeydown) + if (!crouchkeydown) { crouchkeydowntime = 0; + } jumpkeydowntime += multiplier; - if (!jumpkeydown && skeleton.free) + if (!jumpkeydown && skeleton.free) { jumpkeydowntime = 0; + } - if (hostile || damage > 0 || bloodloss > 0) + if (hostile || damage > 0 || bloodloss > 0) { immobile = 0; + } - if (isIdle() || isRun()) + if (isIdle() || isRun()) { targetoffset = 0; + } - if (num_weapons == 1 && weaponactive != -1) + if (num_weapons == 1 && weaponactive != -1) { weaponstuck = -1; + } - if (id == 0) + if (id == 0) { blooddimamount -= multiplier * .3; + } speechdelay -= multiplier; texupdatedelay -= multiplier; interestdelay -= multiplier; @@ -4404,17 +4754,20 @@ void Person::DoStuff() hasvictim = 0; } - if (id == 0) + if (id == 0) { speed = 1.1 * speedmult; - else + } else { speed = 1.0 * speedmult; - if (!skeleton.free) + } + if (!skeleton.free) { rabbitkickragdoll = 0; + } speed *= speedmult; - if (id != 0 && (creature == rabbittype || difficulty != 2)) + if (id != 0 && (creature == rabbittype || difficulty != 2)) { superruntoggle = 0; + } if (id != 0 && creature == wolftype && difficulty == 2) { superruntoggle = 0; if (aitype != passivetype) { @@ -4423,8 +4776,9 @@ void Person::DoStuff() superruntoggle = 0; } } - if (scale < 0.2) + if (scale < 0.2) { superruntoggle = 0; + } if (animTarget == wolfrunninganim && !superruntoggle) { animTarget = getRun(); frameTarget = 0; @@ -4439,8 +4793,9 @@ void Person::DoStuff() if (onfire) { burnt += multiplier; deathbleeding = 1; - if (burnt > .6) + if (burnt > .6) { burnt = .6; + } OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3); if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) { @@ -4489,8 +4844,9 @@ void Person::DoStuff() bleeding -= multiplier * .3; if (bloodtoggle == 2) { skeleton.drawmodel.textureptr.bind(); - if ((bleeding <= 0) && (detail != 2)) + if ((bleeding <= 0) && (detail != 2)) { DoMipmaps(); + } } } @@ -4519,10 +4875,11 @@ void Person::DoStuff() } if (deathbleeding > 0 && dead != 2) { - if (deathbleeding < 5) + if (deathbleeding < 5) { bleeddelay -= deathbleeding * multiplier / 4; - else + } else { bleeddelay -= 5 * multiplier / 4; + } if (bleeddelay < 0 && bloodtoggle) { bleeddelay = 1; XYZ bloodvel; @@ -4539,8 +4896,9 @@ void Person::DoStuff() } bloodloss += deathbleeding * multiplier * 80; deathbleeding -= multiplier * 1.6; - if (deathbleeding < 0) + if (deathbleeding < 0) { deathbleeding = 0; + } if (bloodloss > damagetolerance && Animation::animations[animTarget].attack == neutral) { if (weaponactive != -1) { weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale); @@ -4548,8 +4906,9 @@ void Person::DoStuff() num_weapons--; if (num_weapons) { weaponids[0] = weaponids[num_weapons]; - if (weaponstuck == num_weapons) + if (weaponstuck == num_weapons) { weaponstuck = 0; + } } weaponactive = -1; for (unsigned i = 0; i < Person::players.size(); i++) { @@ -4607,17 +4966,20 @@ void Person::DoStuff() endy = skeleton.skinsize - 1; bleeding = 0; } - if (endx < startx) + if (endx < startx) { endx = startx; - if (endy < starty) + } + if (endy < starty) { endy = starty; + } for (int i = startx; i < endx; i++) { for (int j = starty; j < endy; j++) { if (Random() % 2 == 0) { color = Random() % 85 + 170; - if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2) + if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2) { skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2; + } skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0; skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0; } @@ -4630,16 +4992,18 @@ void Person::DoStuff() if (skeleton.free) { bleedx += 4 * direction / realtexdetail; - if (detail == 2) + if (detail == 2) { bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail; - else + } else { bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail; + } } else { bleedy -= 4 / realtexdetail; - if (detail == 2) + if (detail == 2) { bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail; - else + } else { bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail; + } } } @@ -4741,8 +5105,9 @@ void Person::DoStuff() footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1; footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords; } - if (animTarget == sleepanim) + if (animTarget == sleepanim) { footvel = DoRotation(footvel, 0, 90, 0); + } Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3); } } @@ -4783,8 +5148,9 @@ void Person::DoStuff() righthandmorphness = 0; targetrighthandmorphness = 1; righthandmorphend = 1; - if (Random() % 2 == 0) + if (Random() % 2 == 0) { twitchdelay3 = (float)(abs(Random() % 40)) / 5; + } } if (righthandmorphstart == 1 && righthandmorphend == 1) { righthandmorphness = 0; @@ -4809,10 +5175,11 @@ void Person::DoStuff() } if (!dead) { if (creature == rabbittype) { - if (howactive < typesleeping) + if (howactive < typesleeping) { twitchdelay2 -= multiplier * 1.5; - else + } else { twitchdelay2 -= multiplier * 0.5; + } if (howactive <= typesleeping) { if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) { tailmorphness = 0; @@ -4836,20 +5203,22 @@ void Person::DoStuff() } if (creature == wolftype) { twitchdelay2 -= multiplier * 1.5; - if (tailmorphend != 0) + if (tailmorphend != 0) { if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) { tailmorphness = 0; targettailmorphness = 1; tailmorphend = 0; twitchdelay2 = .1; } - if (tailmorphend != 5) + } + if (tailmorphend != 5) { if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) { tailmorphness = 0; targettailmorphness = 1; tailmorphend = 5; twitchdelay2 = .1; } + } if (twitchdelay2 <= 0) { if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) { tailmorphness = 0; @@ -4886,18 +5255,21 @@ void Person::DoStuff() if (dead == 1 || howactive == typesleeping) { unconscioustime += multiplier; //If unconscious, close eyes and mouth - if (righthandmorphend != 0) + if (righthandmorphend != 0) { righthandmorphness = 0; + } righthandmorphend = 0; targetrighthandmorphness = 1; - if (lefthandmorphend != 0) + if (lefthandmorphend != 0) { lefthandmorphness = 0; + } lefthandmorphend = 0; targetlefthandmorphness = 1; - if (headmorphend != 3 && headmorphend != 5) + if (headmorphend != 3 && headmorphend != 5) { headmorphness = 0; + } headmorphend = 3; targetheadmorphness = 1; } @@ -4921,25 +5293,29 @@ void Person::DoStuff() if (dead == 2 || howactive > typesleeping) { //If dead, open mouth and hands - if (righthandmorphend != 0) + if (righthandmorphend != 0) { righthandmorphness = 0; + } righthandmorphend = 0; targetrighthandmorphness = 1; - if (lefthandmorphend != 0) + if (lefthandmorphend != 0) { lefthandmorphness = 0; + } lefthandmorphend = 0; targetlefthandmorphness = 1; - if (headmorphend != 2) + if (headmorphend != 2) { headmorphness = 0; + } headmorphend = 2; targetheadmorphness = 1; } if (stunned > 0 && !dead && headmorphend != 2) { - if (headmorphend != 4) + if (headmorphend != 4) { headmorphness = 0; + } headmorphend = 4; targetheadmorphness = 1; } @@ -4961,8 +5337,9 @@ void Person::DoStuff() num_weapons--; if (num_weapons) { weaponids[0] = weaponids[num_weapons]; - if (weaponstuck == num_weapons) + if (weaponstuck == num_weapons) { weaponstuck = 0; + } } weaponactive = -1; for (unsigned i = 0; i < Person::players.size(); i++) { @@ -4985,12 +5362,15 @@ void Person::DoStuff() permanentdamage -= multiplier * 4; } } - if (damage < 0) + if (damage < 0) { damage = 0; - if (permanentdamage < 0) + } + if (permanentdamage < 0) { permanentdamage = 0; - if (superpermanentdamage < 0) + } + if (superpermanentdamage < 0) { superpermanentdamage = 0; + } if (permanentdamage < superpermanentdamage) { permanentdamage = superpermanentdamage; } @@ -5014,8 +5394,9 @@ void Person::DoStuff() num_weapons--; if (num_weapons) { weaponids[0] = weaponids[num_weapons]; - if (weaponstuck == num_weapons) + if (weaponstuck == num_weapons) { weaponstuck = 0; + } } weaponactive = -1; for (unsigned i = 0; i < Person::players.size(); i++) { @@ -5029,8 +5410,9 @@ void Person::DoStuff() award_bonus(0, Wolfbonus); } - if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance) + if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance) { award_bonus(id, touchofdeath); + } if (id != 0 && unconscioustime > .1) { numafterkill++; } @@ -5043,24 +5425,28 @@ void Person::DoStuff() } if (skeleton.free == 1) { - if (id == 0) + if (id == 0) { pause_sound(whooshsound); + } if (!dead) { //If knocked over, open hands and close mouth - if (righthandmorphend != 0) + if (righthandmorphend != 0) { righthandmorphness = 0; + } righthandmorphend = 0; targetrighthandmorphness = 1; - if (lefthandmorphend != 0) + if (lefthandmorphend != 0) { lefthandmorphness = 0; + } lefthandmorphend = 0; targetlefthandmorphness = 1; if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) { - if (headmorphend != 0) + if (headmorphend != 0) { headmorphness = 0; + } headmorphend = 0; targetheadmorphness = 1; } @@ -5069,8 +5455,9 @@ void Person::DoStuff() skeleton.DoGravity(&scale); float damageamount; damageamount = skeleton.DoConstraints(&coords, &scale) * 5; - if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1)) + if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1)) { award_bonus(id, deepimpact); + } DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3)); XYZ average; @@ -5101,8 +5488,9 @@ void Person::DoStuff() skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier; if (skeleton.longdead > 2000) { if (skeleton.longdead > 6000) { - if (id == 0) + if (id == 0) { pause_sound(whooshsound); + } skeleton.free = 3; DrawSkeleton(); skeleton.free = 2; @@ -5127,8 +5515,9 @@ void Person::DoStuff() if (dead == 2 && bloodloss >= damagetolerance) { XYZ headpoint; headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords; - if (bleeding <= 0) + if (bleeding <= 0) { DoBlood(1, 255); + } if (bloodtoggle && !bled) { terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0); for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) { @@ -5151,16 +5540,19 @@ void Person::DoStuff() startpoint = coords; endpoint = coords; endpoint.y -= .7; - if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1) + if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1) { canrecover = 0; - if (velocity.y < -30) + } + if (velocity.y < -30) { canrecover = 0; + } for (unsigned int i = 0; i < Object::objects.size(); i++) { if (Object::objects[i]->type != treeleavestype && Object::objects[i]->type != bushtype && Object::objects[i]->type != firetype) { colviewer = startpoint; coltarget = endpoint; - if (Object::objects[i]->model.LineCheck(&colviewer, &coltarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) + if (Object::objects[i]->model.LineCheck(&colviewer, &coltarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) { canrecover = 0; + } } } if (canrecover) { @@ -5185,8 +5577,9 @@ void Person::DoStuff() targetyaw = -asin(0 - terrainnormal.x); targetyaw *= 360 / 6.28; - if (terrainnormal.z < 0) + if (terrainnormal.z < 0) { targetyaw = 180 - targetyaw; + } yaw = targetyaw; frameTarget = 0; @@ -5210,8 +5603,9 @@ void Person::DoStuff() if (findLength(&average) < 10 && !dead && skeleton.free) { skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier; if (skeleton.longdead > (damage + 500) * 1.5) { - if (id == 0) + if (id == 0) { pause_sound(whooshsound); + } skeleton.free = 0; velocity = 0; XYZ middle; @@ -5234,8 +5628,9 @@ void Person::DoStuff() targetyaw = -asin(0 - terrainnormal.x); targetyaw *= 360 / 6.28; - if (terrainnormal.z < 0) + if (terrainnormal.z < 0) { targetyaw = 180 - targetyaw; + } yaw = targetyaw; targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1; @@ -5260,35 +5655,42 @@ void Person::DoStuff() if (id == 0) { if (rightkeydown) { targetyaw -= 90; - if (forwardkeydown) + if (forwardkeydown) { targetyaw += 45; - if (backkeydown) + } + if (backkeydown) { targetyaw -= 45; + } } if (leftkeydown) { targetyaw += 90; - if (forwardkeydown) + if (forwardkeydown) { targetyaw -= 45; - if (backkeydown) + } + if (backkeydown) { targetyaw += 45; + } } if (backkeydown) { - if (!leftkeydown && !rightkeydown) + if (!leftkeydown && !rightkeydown) { targetyaw += 180; + } } targetyaw += 180; } } - if (abs(targettilt2) > 50) + if (abs(targettilt2) > 50) { targettilt2 = 0; + } animCurrent = tempanim; frameCurrent = 0; target = 0; tilt2 = targettilt2; - if (middle.y > 0 && animTarget != rollanim) + if (middle.y > 0 && animTarget != rollanim) { targetoffset.y = middle.y + 1; + } for (unsigned i = 0; i < skeleton.joints.size(); i++) { tempanimation.frames[0].joints[i].position = skeleton.joints[i].position; @@ -5299,9 +5701,11 @@ void Person::DoStuff() bool hasstaff; hasstaff = 0; - if (num_weapons > 0) - if (weapons[0].getType() == staff) + if (num_weapons > 0) { + if (weapons[0].getType() == staff) { hasstaff = 1; + } + } if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) { if (velocity.y > -30) { XYZ tempvelocity; @@ -5309,8 +5713,9 @@ void Person::DoStuff() Normalise(&tempvelocity); targetyaw = -asin(0 - tempvelocity.x); targetyaw *= 360 / 6.28; - if (velocity.z < 0) + if (velocity.z < 0) { targetyaw = 180 - targetyaw; + } //targetyaw+=180; skeleton.free = 0; @@ -5339,14 +5744,15 @@ void Person::DoStuff() targettilt2 = 0; } } - if (skeleton.freefall == 0) + if (skeleton.freefall == 0) { freefall = 0; + } } - if (aitype != passivetype || skeleton.free == 1) - if (findLengthfast(&velocity) > .1) + if (aitype != passivetype || skeleton.free == 1) { + if (findLengthfast(&velocity) > .1) { for (unsigned int i = 0; i < Object::objects.size(); i++) { - if (Object::objects[i]->type == firetype) + if (Object::objects[i]->type == firetype) { if (distsqflat(&coords, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 12 && distsq(&coords, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 49) { if (onfire) { if (!Object::objects[i]->onfire) { @@ -5360,7 +5766,8 @@ void Person::DoStuff() } } } - if (Object::objects[i]->type == bushtype) + } + if (Object::objects[i]->type == bushtype) { if (distsqflat(&coords, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 12 && distsq(&coords, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 49) { if (onfire) { if (!Object::objects[i]->onfire) { @@ -5385,12 +5792,14 @@ void Person::DoStuff() } int howmany = 0; - if (environment == grassyenvironment) + if (environment == grassyenvironment) { howmany = findLength(&velocity) * 4; - if (environment == snowyenvironment) + } + if (environment == snowyenvironment) { howmany = findLength(&velocity) * 2; - if (detail == 2) - if (environment != desertenvironment) + } + if (detail == 2) { + if (environment != desertenvironment) { for (int j = 0; j < howmany; j++) { tempvel.x = float(abs(Random() % 100) - 50) / 20; tempvel.y = float(abs(Random() % 100) - 50) / 20; @@ -5403,9 +5812,11 @@ void Person::DoStuff() Sprite::MakeSprite(splintersprite, pos, tempvel * .5 + velocity * float(abs(Random() % 100)) / 100, 165 / 255 + float(abs(Random() % 100) - 50) / 400, 0, 0, .2 + float(abs(Random() % 100) - 50) / 1300, 1); Sprite::setLastSpriteSpecial(1); } + } + } howmany = findLength(&velocity) * 4; - if (detail == 2) - if (environment == snowyenvironment) + if (detail == 2) { + if (environment == snowyenvironment) { for (int j = 0; j < howmany; j++) { tempvel.x = float(abs(Random() % 100) - 50) / 20; tempvel.y = float(abs(Random() % 100) - 50) / 20; @@ -5418,16 +5829,19 @@ void Person::DoStuff() Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1); Sprite::setLastSpriteSpecial(2); } + } + } } Object::objects[i]->rotx += velocity.x * multiplier * 6; Object::objects[i]->roty += velocity.z * multiplier * 6; Object::objects[i]->messedwith = .5; } + } XYZ tempcoord; if (Object::objects[i]->type == treeleavestype && environment != desertenvironment) { - if (Object::objects[i]->pitch == 0) + if (Object::objects[i]->pitch == 0) { tempcoord = coords; - else { + } else { tempcoord = coords - Object::objects[i]->position; tempcoord = DoRotation(tempcoord, 0, -Object::objects[i]->yaw, 0); tempcoord = DoRotation(tempcoord, -Object::objects[i]->pitch, 0, 0); @@ -5445,12 +5859,14 @@ void Person::DoStuff() } int howmany = 0; - if (environment == grassyenvironment) + if (environment == grassyenvironment) { howmany = findLength(&velocity) * 4; - if (environment == snowyenvironment) + } + if (environment == snowyenvironment) { howmany = findLength(&velocity) * 2; - if (detail == 2) - if (environment != desertenvironment) + } + if (detail == 2) { + if (environment != desertenvironment) { for (int j = 0; j < howmany; j++) { tempvel.x = float(abs(Random() % 100) - 50) / 20; tempvel.y = float(abs(Random() % 100) - 50) / 20; @@ -5464,9 +5880,11 @@ void Person::DoStuff() Sprite::MakeSprite(splintersprite, pos, tempvel * .5 + velocity * float(abs(Random() % 100)) / 100, 165 / 255 + float(abs(Random() % 100) - 50) / 400, 0, 0, .2 + float(abs(Random() % 100) - 50) / 1300, 1); Sprite::setLastSpriteSpecial(1); } + } + } howmany = findLength(&velocity) * 4; - if (detail == 2) - if (environment == snowyenvironment) + if (detail == 2) { + if (environment == snowyenvironment) { for (int j = 0; j < howmany; j++) { tempvel.x = float(abs(Random() % 100) - 50) / 20; tempvel.y = float(abs(Random() % 100) - 50) / 20; @@ -5480,37 +5898,49 @@ void Person::DoStuff() Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1); Sprite::setLastSpriteSpecial(2); } + } + } } Object::objects[i]->messedwith = .5; } } } + } + } if (!skeleton.free) { bool play; play = 0; - if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype) + if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype) { play = 1; - if (hasvictim) - if (aitype != passivetype && victim->skeleton.free && !victim->dead) + } + if (hasvictim) { + if (aitype != passivetype && victim->skeleton.free && !victim->dead) { play = 1; - if (Tutorial::active && id != 0) + } + } + if (Tutorial::active && id != 0) { play = 0; + } if (play && aitype != playercontrolled) { int whichsound = -1; if (speechdelay <= 0) { unsigned int i = abs(Random() % 4); if (creature == rabbittype) { - if (i == 0) + if (i == 0) { whichsound = rabbitchitter; - if (i == 1) + } + if (i == 1) { whichsound = rabbitchitter2; + } } if (creature == wolftype) { - if (i == 0) + if (i == 0) { whichsound = growlsound; - if (i == 1) + } + if (i == 1) { whichsound = growl2sound; + } } } speechdelay = .3; @@ -5520,15 +5950,19 @@ void Person::DoStuff() } } - if (animTarget == staggerbackhighanim) + if (animTarget == staggerbackhighanim) { staggerdelay = 1; - if (animTarget == staggerbackhardanim) + } + if (animTarget == staggerbackhardanim) { staggerdelay = 1; + } staggerdelay -= multiplier; - if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) + if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) { hasvictim = 1; - if (velocity.y < -30 && animTarget == jumpdownanim) + } + if (velocity.y < -30 && animTarget == jumpdownanim) { RagDoll(0); + } if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) { animTarget = getIdle(); frameTarget = 0; @@ -5677,7 +6111,7 @@ void Person::DoStuff() } } - if (!dead && animTarget != hurtidleanim) + if (!dead && animTarget != hurtidleanim) { if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) { if (headmorphend != 4 || headmorphness == targetheadmorphness) { headmorphend = 4; @@ -5685,6 +6119,7 @@ void Person::DoStuff() targetheadmorphness = 1; } } + } if (weaponactive != -1) { if (weapons[weaponids[weaponactive]].getType() != staff) { @@ -5701,8 +6136,9 @@ void Person::DoStuff() terrainnormal = terrain.getNormal(coords.x, coords.z); if (Animation::animations[animTarget].attack != reversal) { - if (!isnormal(coords.x)) + if (!isnormal(coords.x)) { coords = oldcoords; + } oldcoords = coords; } @@ -5716,46 +6152,56 @@ void Person::DoStuff() if (isRun() || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) { - if (onterrain) + if (onterrain) { targettilt2 = -facing.y * 20; - else + } else { targettilt2 = 0; + } } onterrain = 0; - if (!isRun() && !Animation::animations[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim) + if (!isRun() && !Animation::animations[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim) { targettilt2 = 0; + } if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) { flatvelocity = velocity; flatvelocity.y = 0; flatvelspeed = findLength(&flatvelocity); targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity); targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity); - if (velocity.y < 0) + if (velocity.y < 0) { targettilt2 *= -1; - if (velocity.y < 0) + } + if (velocity.y < 0) { targettilt *= -1; - if (targettilt > 25) + } + if (targettilt > 25) { targettilt = 25; - if (targettilt < -25) + } + if (targettilt < -25) { targettilt = -25; + } } - if (targettilt2 > 45) + if (targettilt2 > 45) { targettilt2 = 45; - if (targettilt2 < -45) + } + if (targettilt2 < -45) { targettilt2 = -45; - if (abs(tilt2 - targettilt2) < multiplier * 400) + } + if (abs(tilt2 - targettilt2) < multiplier * 400) { tilt2 = targettilt2; - else if (tilt2 > targettilt2) { + } else if (tilt2 > targettilt2) { tilt2 -= multiplier * 400; } else if (tilt2 < targettilt2) { tilt2 += multiplier * 400; } if (!Animation::animations[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) { - if (tilt2 > 25) + if (tilt2 > 25) { tilt2 = 25; - if (tilt2 < -25) + } + if (tilt2 < -25) { tilt2 = -25; + } } if (!isnormal(targettilt) && targettilt) { @@ -5791,8 +6237,9 @@ void Person::DoStuff() velocity.y += gravity * multiplier * 20; ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z)); velspeed = findLength(&velocity); - if (velspeed < speed * 30 * scale) + if (velspeed < speed * 30 * scale) { velspeed = speed * 30 * scale; + } velocity = flatfacing * velspeed; } } else if (isRun()) { @@ -5934,12 +6381,14 @@ void Person::DoStuff() velocity.y += gravity * multiplier; } - if (animTarget != climbanim && animTarget != hanganim && !isWallJump()) + if (animTarget != climbanim && animTarget != hanganim && !isWallJump()) { coords += velocity * multiplier; + } if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) { - if (isFlip() && targetFrame().label == 7) + if (isFlip() && targetFrame().label == 7) { RagDoll(0); + } if (animTarget == jumpupanim) { jumppower = -4; @@ -5955,8 +6404,9 @@ void Person::DoStuff() } if (animTarget == jumpdownanim || isFlip()) { - if (isFlip()) + if (isFlip()) { jumppower = -4; + } animTarget = getLanding(); emit_sound_at(landsound, coords, 128.); @@ -5966,8 +6416,9 @@ void Person::DoStuff() } } - if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump()) + if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump()) { coords.y += gravity * multiplier * 2; + } if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) { coords.y = terrain.getHeight(coords.x, coords.z); onterrain = 1; @@ -6008,8 +6459,9 @@ void Person::DoStuff() } } - if (skiddingdelay < 0) + if (skiddingdelay < 0) { skiddingdelay += multiplier; + } if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) { skiddingdelay = -1; if (!onterrain || environment == grassyenvironment) { @@ -6024,8 +6476,9 @@ void Person::DoStuff() Normalise(&terrainnormal); targetyaw = -asin(0 - terrainnormal.x); targetyaw *= 360 / 6.28; - if (terrainnormal.z < 0) + if (terrainnormal.z < 0) { targetyaw = 180 - targetyaw; + } targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70; } @@ -6116,12 +6569,15 @@ int Person::DrawSkeleton() XYZ terrainlight; float terrainheight; float distance; - if (!isnormal(yaw)) + if (!isnormal(yaw)) { yaw = 0; - if (!isnormal(tilt)) + } + if (!isnormal(tilt)) { tilt = 0; - if (!isnormal(tilt2)) + } + if (!isnormal(tilt2)) { tilt2 = 0; + } oldplayerdetail = playerdetail; playerdetail = 0; if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) { @@ -6133,8 +6589,9 @@ int Person::DrawSkeleton() if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) { playerdetail = 1; } - if (id == 0) + if (id == 0) { playerdetail = 1; + } if (playerdetail != oldplayerdetail) { updatedelay = 0; normalsupdatedelay = 0; @@ -6164,30 +6621,34 @@ int Person::DrawSkeleton() if (onterrain && (cond1 && cond2) && !skeleton.free) { IKHelper(this, 1); - if (creature == wolftype) + if (creature == wolftype) { IKHelper(this, 1); + } } if (onterrain && (cond1 && !cond2) && !skeleton.free) { IKHelper(this, target); - if (creature == wolftype) + if (creature == wolftype) { IKHelper(this, target); + } } if (onterrain && (!cond1 && cond2) && !skeleton.free) { IKHelper(this, 1 - target); - if (creature == wolftype) + if (creature == wolftype) { IKHelper(this, 1 - target); + } } } - if (!skeleton.free && (!Animation::animations[animTarget].attack && animTarget != getupfrombackanim && ((animTarget != rollanim && !isFlip()) || targetFrame().label == 6) && animTarget != getupfromfrontanim && animTarget != wolfrunninganim && animTarget != rabbitrunninganim && animTarget != backhandspringanim && animTarget != walljumpfrontanim && animTarget != hurtidleanim && !isLandhard() && !isSleeping())) + if (!skeleton.free && (!Animation::animations[animTarget].attack && animTarget != getupfrombackanim && ((animTarget != rollanim && !isFlip()) || targetFrame().label == 6) && animTarget != getupfromfrontanim && animTarget != wolfrunninganim && animTarget != rabbitrunninganim && animTarget != backhandspringanim && animTarget != walljumpfrontanim && animTarget != hurtidleanim && !isLandhard() && !isSleeping())) { DoHead(); - else { + } else { targetheadyaw = -targetyaw; targetheadpitch = 0; - if (Animation::animations[animTarget].attack == 3) + if (Animation::animations[animTarget].attack == 3) { targetheadyaw += 180; + } } for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) { skeleton.drawmodel.vertex[i] = 0; @@ -6236,16 +6697,19 @@ int Person::DrawSkeleton() start = tailmorphstart; endthing = tailmorphend; } - if (calcrot) + if (calcrot) { skeleton.FindRotationMuscle(i, animTarget); + } mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - if (!skeleton.free) + if (!skeleton.free) { glRotatef(tilt2, 1, 0, 0); - if (!skeleton.free) + } + if (!skeleton.free) { glRotatef(tilt, 0, 0, 1); + } glTranslatef(mid.x, mid.y, mid.z); @@ -6264,22 +6728,26 @@ int Person::DrawSkeleton() XYZ& v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]]; glMatrixMode(GL_MODELVIEW); glPushMatrix(); - if (p1 == abdomen || p2 == abdomen) + if (p1 == abdomen || p2 == abdomen) { glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x, (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y, (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z); - if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) + } + if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) { glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x, (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y, (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z); - if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) + } + if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) { glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x, (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y, (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z); - if (p1 == head || p2 == head) + } + if (p1 == head || p2 == head) { glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x, (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y, (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z); + } glGetFloatv(GL_MODELVIEW_MATRIX, M); skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale; skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale; @@ -6292,22 +6760,26 @@ int Person::DrawSkeleton() XYZ& v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]]; glMatrixMode(GL_MODELVIEW); glPushMatrix(); - if (p1 == abdomen || p2 == abdomen) + if (p1 == abdomen || p2 == abdomen) { glTranslatef(v0.x * proportionbody.x, v0.y * proportionbody.y, v0.z * proportionbody.z); - if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) + } + if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) { glTranslatef(v0.x * proportionarms.x, v0.y * proportionarms.y, v0.z * proportionarms.z); - if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) + } + if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) { glTranslatef(v0.x * proportionlegs.x, v0.y * proportionlegs.y, v0.z * proportionlegs.z); - if (p1 == head || p2 == head) + } + if (p1 == head || p2 == head) { glTranslatef(v0.x * proportionhead.x, v0.y * proportionhead.y, v0.z * proportionhead.z); + } glGetFloatv(GL_MODELVIEW_MATRIX, M); skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale; @@ -6324,10 +6796,12 @@ int Person::DrawSkeleton() glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - if (!skeleton.free) + if (!skeleton.free) { glRotatef(tilt2, 1, 0, 0); - if (!skeleton.free) + } + if (!skeleton.free) { glRotatef(tilt, 0, 0, 1); + } glTranslatef(mid.x, mid.y, mid.z); skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1; glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0); @@ -6342,22 +6816,26 @@ int Person::DrawSkeleton() XYZ& v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]]; glMatrixMode(GL_MODELVIEW); glPushMatrix(); - if (p1 == abdomen || p2 == abdomen) + if (p1 == abdomen || p2 == abdomen) { glTranslatef(v0.x * proportionbody.x, v0.y * proportionbody.y, v0.z * proportionbody.z); - if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) + } + if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) { glTranslatef(v0.x * proportionarms.x, v0.y * proportionarms.y, v0.z * proportionarms.z); - if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) + } + if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) { glTranslatef(v0.x * proportionlegs.x, v0.y * proportionlegs.y, v0.z * proportionlegs.z); - if (p1 == head || p2 == head) + } + if (p1 == head || p2 == head) { glTranslatef(v0.x * proportionhead.x, v0.y * proportionhead.y, v0.z * proportionhead.z); + } glGetFloatv(GL_MODELVIEW_MATRIX, M); skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale; skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale; @@ -6370,17 +6848,22 @@ int Person::DrawSkeleton() } if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) { normalsupdatedelay = 1; - if (playerdetail || skeleton.free == 3) + if (playerdetail || skeleton.free == 3) { skeleton.drawmodel.CalculateNormals(0); - if (!playerdetail || skeleton.free == 3) + } + if (!playerdetail || skeleton.free == 3) { skeleton.drawmodellow.CalculateNormals(0); - if (skeleton.clothes) + } + if (skeleton.clothes) { skeleton.drawmodelclothes.CalculateNormals(0); + } } else { - if (playerdetail || skeleton.free == 3) + if (playerdetail || skeleton.free == 3) { skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm(); - if (!playerdetail || skeleton.free == 3) + } + if (!playerdetail || skeleton.free == 3) { skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm(); + } if (skeleton.clothes) { skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm(); } @@ -6388,14 +6871,18 @@ int Person::DrawSkeleton() } framemult = .01; updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1); - if (updatedelaychange > -realmultiplier * 30) + if (updatedelaychange > -realmultiplier * 30) { updatedelaychange = -realmultiplier * 30; - if (updatedelaychange > -framemult * 4) + } + if (updatedelaychange > -framemult * 4) { updatedelaychange = -framemult * 4; - if (skeleton.free == 1) + } + if (skeleton.free == 1) { updatedelaychange *= 6; - if (id == 0) + } + if (id == 0) { updatedelaychange *= 8; + } updatedelay += updatedelaychange; glMatrixMode(GL_MODELVIEW); @@ -6440,14 +6927,17 @@ int Person::DrawSkeleton() terrainlight = terrain.getLighting(coords.x, coords.z); distance = distsq(&viewer, &coords); distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance; - if (distance > 1) + if (distance > 1) { distance = 1; + } if (distance > 0) { terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1; - if (terrainheight < 1) + if (terrainheight < 1) { terrainheight = 1; - if (terrainheight > 1.7) + } + if (terrainheight > 1.7) { terrainheight = 1.7; + } glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance); glDisable(GL_BLEND); @@ -6465,11 +6955,12 @@ int Person::DrawSkeleton() glDepthMask(0); glEnable(GL_LIGHTING); glEnable(GL_BLEND); - if (canattack && cananger) + if (canattack && cananger) { if (Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed) { glDisable(GL_TEXTURE_2D); glColor4f(1, 0, 0, 0.8); } + } glMatrixMode(GL_TEXTURE); glPushMatrix(); glTranslatef(0, -smoketex, 0); @@ -6477,20 +6968,22 @@ int Person::DrawSkeleton() } if (playerdetail) { if (!showpoints) { - if (Tutorial::active && (id != 0)) + if (Tutorial::active && (id != 0)) { skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture); - else + } else { skeleton.drawmodel.draw(); + } } } if (!playerdetail) { - if (Tutorial::active && (id != 0)) + if (Tutorial::active && (id != 0)) { skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture); - else + } else { skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr); + } } - if (!(Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed)) + if (!(Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed)) { if (Tutorial::active && id != 0) { glPopMatrix(); glMatrixMode(GL_MODELVIEW); @@ -6499,30 +6992,34 @@ int Person::DrawSkeleton() glDepthMask(0); glEnable(GL_LIGHTING); glEnable(GL_BLEND); - if (canattack && cananger) + if (canattack && cananger) { if (Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed) { glDisable(GL_TEXTURE_2D); glColor4f(1, 0, 0, 0.8); } + } glMatrixMode(GL_TEXTURE); glPushMatrix(); glTranslatef(0, -smoketex * .6, 0); glTranslatef(smoketex * .6, 0, 0); if (playerdetail) { if (!showpoints) { - if (Tutorial::active && (id != 0)) + if (Tutorial::active && (id != 0)) { skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture); - else + } else { skeleton.drawmodel.draw(); + } } } if (!playerdetail) { - if (Tutorial::active && (id != 0)) + if (Tutorial::active && (id != 0)) { skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture); - else + } else { skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr); + } } } + } if (Tutorial::active && id != 0) { glPopMatrix(); @@ -6532,10 +7029,12 @@ int Person::DrawSkeleton() if (skeleton.clothes) { glDepthMask(0); glEnable(GL_BLEND); - if (!immediate) + if (!immediate) { skeleton.drawmodelclothes.draw(); - if (immediate) + } + if (immediate) { skeleton.drawmodelclothes.drawimmediate(); + } glDepthMask(1); } } @@ -6557,8 +7056,9 @@ int Person::DrawSkeleton() } } weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2; - if (creature == wolftype) + if (creature == wolftype) { weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3); + } } if (weapons[i].getType() == staff) { for (unsigned j = 0; j < skeleton.muscles.size(); j++) { @@ -6579,17 +7079,21 @@ int Person::DrawSkeleton() vec2 = (jointPos(rightwrist) - jointPos(rightshoulder)); CrossProduct(&vec1, &vec2, &tempnormthing); Normalise(&tempnormthing); - if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim) + if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim) { weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow)); + } } } if (weaponactive != k && weaponstuck != k) { - if (weapons[i].getType() == knife) + if (weapons[i].getType() == knife) { weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35; - if (weapons[i].getType() == sword) + } + if (weapons[i].getType() == sword) { weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33; - if (weapons[i].getType() == staff) + } + if (weapons[i].getType() == staff) { weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33; + } for (unsigned j = 0; j < skeleton.muscles.size(); j++) { if ((skeleton.muscles[j].parent1->label == abdomen || skeleton.muscles[j].parent2->label == abdomen) && (skeleton.muscles[j].parent1->label == neck || skeleton.muscles[j].parent2->label == neck) && skeleton.muscles[j].vertices.size() > 0) { weaponrotatemuscle = j; @@ -6597,10 +7101,11 @@ int Person::DrawSkeleton() } } if (weaponstuck == k) { - if (weaponstuckwhere == 0) + if (weaponstuckwhere == 0) { weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8; - else + } else { weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8; + } for (unsigned j = 0; j < skeleton.muscles.size(); j++) { if ((skeleton.muscles[j].parent1->label == abdomen || skeleton.muscles[j].parent2->label == abdomen) && (skeleton.muscles[j].parent1->label == neck || skeleton.muscles[j].parent2->label == neck) && skeleton.muscles[j].vertices.size() > 0) { weaponrotatemuscle = j; @@ -6647,8 +7152,9 @@ int Person::DrawSkeleton() weapons[i].rotation3 = 0; weapons[i].smallrotation = -90; weapons[i].smallrotation2 = 0; - if (temppoint1.x > temppoint2.x) + if (temppoint1.x > temppoint2.x) { weapons[i].rotation1 = 360 - weapons[i].rotation1; + } } if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) { XYZ temppoint1, temppoint2; @@ -6666,8 +7172,9 @@ int Person::DrawSkeleton() weapons[i].rotation3 = 0; weapons[i].smallrotation = 90; weapons[i].smallrotation2 = 0; - if (temppoint1.x > temppoint2.x) + if (temppoint1.x > temppoint2.x) { weapons[i].rotation1 = 360 - weapons[i].rotation1; + } } if (animTarget == knifethrowanim) { weapons[i].smallrotation = 90; @@ -6710,8 +7217,9 @@ int Person::DrawSkeleton() weapons[i].rotation3 = 0; weapons[i].smallrotation = 90; weapons[i].smallrotation2 = 0; - if (temppoint1.x > temppoint2.x) + if (temppoint1.x > temppoint2.x) { weapons[i].rotation1 = 360 - weapons[i].rotation1; + } } } if (weapons[i].getType() == staff) { @@ -6733,8 +7241,9 @@ int Person::DrawSkeleton() weapons[i].rotation3 = 0; weapons[i].smallrotation = 90; weapons[i].smallrotation2 = 0; - if (temppoint1.x > temppoint2.x) + if (temppoint1.x > temppoint2.x) { weapons[i].rotation1 = 360 - weapons[i].rotation1; + } } } } @@ -6753,10 +7262,11 @@ int Person::DrawSkeleton() } } if (weaponstuck == k) { - if (weaponstuckwhere == 0) + if (weaponstuckwhere == 0) { weapons[i].smallrotation = 180; - else + } else { weapons[i].smallrotation = 0; + } weapons[i].smallrotation2 = 10; } } @@ -6764,14 +7274,18 @@ int Person::DrawSkeleton() } calcrot = 0; - if (skeleton.free) + if (skeleton.free) { calcrot = 1; - if (Animation::animations[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isWallJump()) + } + if (Animation::animations[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isWallJump()) { calcrot = 1; - if (animCurrent != animTarget) + } + if (animCurrent != animTarget) { calcrot = 1; - if (skeleton.free == 2) + } + if (skeleton.free == 2) { calcrot = 0; + } return 0; } @@ -6793,10 +7307,12 @@ int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, oldp1 = *p1; *p1 = *p1 - *move; - if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius) + if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius) { return -1; - if (*rotate) + } + if (*rotate) { *p1 = DoRotation(*p1, 0, -*rotate, 0); + } for (int i = 0; i < 4; i++) { for (unsigned int j = 0; j < model->Triangles.size(); j++) { if (model->Triangles[j].facenormal.y <= slopethreshold) { @@ -6804,20 +7320,24 @@ int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, distance = abs((model->Triangles[j].facenormal.x * p1->x) + (model->Triangles[j].facenormal.y * p1->y) + (model->Triangles[j].facenormal.z * p1->z) - ((model->Triangles[j].facenormal.x * model->vertex[model->Triangles[j].vertex[0]].x) + (model->Triangles[j].facenormal.y * model->vertex[model->Triangles[j].vertex[0]].y) + (model->Triangles[j].facenormal.z * model->vertex[model->Triangles[j].vertex[0]].z))); if (distance < radius) { point = *p1 - model->Triangles[j].facenormal * distance; - if (PointInTriangle(&point, model->Triangles[j].facenormal, &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]])) + if (PointInTriangle(&point, model->Triangles[j].facenormal, &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]])) { intersecting = 1; - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], p1, &radius); - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]], p1, &radius); - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[2]], p1, &radius); + } end = *p1 - point; if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) { start = *p1; @@ -6826,8 +7346,9 @@ int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, if (LineFacetd(&start, &end, &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]], &model->Triangles[j].facenormal, &point)) { p1->y = point.y + radius; if ((animTarget == jumpdownanim || isFlip())) { - if (isFlip() && (frameTarget < 5 || targetFrame().label == 7 || targetFrame().label == 4)) + if (isFlip() && (frameTarget < 5 || targetFrame().label == 7 || targetFrame().label == 4)) { RagDoll(0); + } if (animTarget == jumpupanim) { jumppower = -4; @@ -6843,8 +7364,9 @@ int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, } if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) { - if (isFlip()) + if (isFlip()) { jumppower = -4; + } animTarget = getLanding(); emit_sound_at(landsound, coords, 128.); @@ -6874,21 +7396,26 @@ int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, distance = abs((model->Triangles[j].facenormal.x * start.x) + (model->Triangles[j].facenormal.y * start.y) + (model->Triangles[j].facenormal.z * start.z) - ((model->Triangles[j].facenormal.x * v0.x) + (model->Triangles[j].facenormal.y * v0.y) + (model->Triangles[j].facenormal.z * v0.z))); if (distance < radius * .5) { point = start - model->Triangles[j].facenormal * distance; - if (PointInTriangle(&point, model->Triangles[j].facenormal, &v0, &v1, &v2)) + if (PointInTriangle(&point, model->Triangles[j].facenormal, &v0, &v1, &v2)) { intersecting = 1; - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2); - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2); - if (!intersecting) + } + if (!intersecting) { intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2); + } end = *p1 - point; if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) { if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) { start = velocity; velocity -= DoRotation(model->Triangles[j].facenormal, 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->Triangles[j].facenormal, 0, *rotate, 0))); //(distance-radius*.5)/multiplier; - if (findLengthfast(&start) < findLengthfast(&velocity)) + if (findLengthfast(&start) < findLengthfast(&velocity)) { velocity = start; + } } *p1 += model->Triangles[j].facenormal * (distance - radius * .5); } @@ -6901,11 +7428,13 @@ int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, } } } - if (*rotate) + if (*rotate) { *p = DoRotation(*p, 0, *rotate, 0); + } *p = *p + *move; - if (*rotate) + if (*rotate) { *p1 = DoRotation(*p1, 0, *rotate, 0); + } *p1 += *move; return firstintersecting; } @@ -6927,21 +7456,27 @@ int findPathDist(int start, int end) for (int j = 0; j < Game::numpathpoints; j++) { if (j != last && j != last2 && j != last3 && j != last4) { connected = 0; - if (Game::numpathpointconnect[j]) + if (Game::numpathpointconnect[j]) { for (int k = 0; k < Game::numpathpointconnect[j]; k++) { - if (Game::pathpointconnect[j][k] == last) + if (Game::pathpointconnect[j][k] == last) { connected = 1; + } } - if (!connected) - if (Game::numpathpointconnect[last]) + } + if (!connected) { + if (Game::numpathpointconnect[last]) { for (int k = 0; k < Game::numpathpointconnect[last]; k++) { - if (Game::pathpointconnect[last][k] == j) + if (Game::pathpointconnect[last][k] == j) { connected = 1; + } } - if (connected) + } + } + if (connected) { if (closest == -1 || Random() % 2 == 0) { closest = j; } + } } } last4 = last3; @@ -6996,36 +7531,46 @@ bool Person::addClothes(const int& clothesId) float tintg = clothestintg[clothesId]; float tintb = clothestintb[clothesId]; - if (tintr > 1) + if (tintr > 1) { tintr = 1; - if (tintg > 1) + } + if (tintg > 1) { tintg = 1; - if (tintb > 1) + } + if (tintb > 1) { tintb = 1; + } - if (tintr < 0) + if (tintr < 0) { tintr = 0; - if (tintg < 0) + } + if (tintg < 0) { tintg = 0; - if (tintb < 0) + } + if (tintb < 0) { tintb = 0; + } int bytesPerPixel = texture.bpp / 8; int tempnum = 0; alphanum = 255; for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) { - if (bytesPerPixel == 3) + if (bytesPerPixel == 3) { alphanum = 255; - else if ((i + 1) % 4 == 0) + } else if ((i + 1) % 4 == 0) { alphanum = texture.data[i]; + } if ((i + 1) % 4 || bytesPerPixel == 3) { - if ((i % 4) == 0) + if ((i % 4) == 0) { texture.data[i] *= tintr; - if ((i % 4) == 1) + } + if ((i % 4) == 1) { texture.data[i] *= tintg; - if ((i % 4) == 2) + } + if ((i % 4) == 2) { texture.data[i] *= tintb; + } array[tempnum] = (float)array[tempnum] * (1 - alphanum / 255) + (float)texture.data[i] * (alphanum / 255); tempnum++; } @@ -7041,14 +7586,16 @@ void Person::doAI() if (aitype != playercontrolled && !Dialog::inDialog()) { jumpclimb = 0; //disable movement in editor - if (Game::editorenabled) + if (Game::editorenabled) { stunned = 1; + } pause = 0; if (distsqflat(&Person::players[0]->coords, &coords) < 30 && Person::players[0]->coords.y > coords.y + 2 && - !Person::players[0]->onterrain) + !Person::players[0]->onterrain) { pause = 1; + } //pathfinding if (aitype == pathfindtype) { @@ -7070,13 +7617,14 @@ void Person::doAI() for (int j = 0; j < Game::numpathpoints; j++) { for (int k = 0; k < Game::numpathpointconnect[j]; k++) { DistancePointLine(&finalfinaltarget, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint); - if (sq(tempdist) < closestdistance) + if (sq(tempdist) < closestdistance) { if (findDistance(&colpoint, &Game::pathpoint[j]) + findDistance(&colpoint, &Game::pathpoint[Game::pathpointconnect[j][k]]) < findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) { closestdistance = sq(tempdist); closest = j; finaltarget = colpoint; } + } } } finalpathfindpoint = closest; @@ -7090,15 +7638,16 @@ void Person::doAI() closestdistance = -1; if (lastpathfindpoint == -1) { for (int j = 0; j < Game::numpathpoints; j++) { - if (j != lastpathfindpoint) + if (j != lastpathfindpoint) { if (closest == -1 || (distsq(&coords, &Game::pathpoint[j]) < closestdistance)) { closestdistance = distsq(&coords, &Game::pathpoint[j]); closest = j; } + } } targetpathfindpoint = closest; - for (int j = 0; j < Game::numpathpoints; j++) - if (j != lastpathfindpoint) + for (int j = 0; j < Game::numpathpoints; j++) { + if (j != lastpathfindpoint) { for (int k = 0; k < Game::numpathpointconnect[j]; k++) { DistancePointLine(&coords, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint); if (sq(tempdist) < closestdistance) { @@ -7109,23 +7658,32 @@ void Person::doAI() } } } + } + } targetpathfindpoint = closest; } else { - for (int j = 0; j < Game::numpathpoints; j++) + for (int j = 0; j < Game::numpathpoints; j++) { if (j != lastpathfindpoint && j != lastpathfindpoint2 && j != lastpathfindpoint3 && j != lastpathfindpoint4) { bool connected = 0; - if (Game::numpathpointconnect[j]) - for (int k = 0; k < Game::numpathpointconnect[j]; k++) - if (Game::pathpointconnect[j][k] == lastpathfindpoint) + if (Game::numpathpointconnect[j]) { + for (int k = 0; k < Game::numpathpointconnect[j]; k++) { + if (Game::pathpointconnect[j][k] == lastpathfindpoint) { connected = 1; - if (!connected) - if (Game::numpathpointconnect[lastpathfindpoint]) - for (int k = 0; k < Game::numpathpointconnect[lastpathfindpoint]; k++) - if (Game::pathpointconnect[lastpathfindpoint][k] == j) + } + } + } + if (!connected) { + if (Game::numpathpointconnect[lastpathfindpoint]) { + for (int k = 0; k < Game::numpathpointconnect[lastpathfindpoint]; k++) { + if (Game::pathpointconnect[lastpathfindpoint][k] == j) { connected = 1; + } + } + } + } if (connected) { tempdist = findPathDist(j, finalpathfindpoint); if (closest == -1 || tempdist < closestdistance) { @@ -7134,6 +7692,7 @@ void Person::doAI() } } } + } targetpathfindpoint = closest; } } @@ -7148,12 +7707,15 @@ void Person::doAI() lastpathfindpoint3 = lastpathfindpoint2; lastpathfindpoint2 = lastpathfindpoint; lastpathfindpoint = targetpathfindpoint; - if (lastpathfindpoint2 == -1) + if (lastpathfindpoint2 == -1) { lastpathfindpoint2 = lastpathfindpoint; - if (lastpathfindpoint3 == -1) + } + if (lastpathfindpoint3 == -1) { lastpathfindpoint3 = lastpathfindpoint2; - if (lastpathfindpoint4 == -1) + } + if (lastpathfindpoint4 == -1) { lastpathfindpoint4 = lastpathfindpoint3; + } targetpathfindpoint = -1; } if (distsqflat(&coords, &finalfinaltarget) < @@ -7171,13 +7733,16 @@ void Person::doAI() attackkeydown = 0; throwkeydown = 0; - if (avoidcollided > .8 && !jumpkeydown && collided < .8) + if (avoidcollided > .8 && !jumpkeydown && collided < .8) { targetyaw += 90 * (whichdirection * 2 - 1); + } - if (collided < 1 || animTarget != jumpupanim) + if (collided < 1 || animTarget != jumpupanim) { jumpkeydown = 0; - if ((collided > .8 && jumppower >= 5)) + } + if ((collided > .8 && jumppower >= 5)) { jumpkeydown = 1; + } if ((!Tutorial::active || cananger) && hostile && @@ -7187,21 +7752,23 @@ void Person::doAI() if (distsq(&coords, &Person::players[0]->coords) < 12 && Animation::animations[Person::players[0]->animTarget].height != lowheight && !Game::editorenabled && - (Person::players[0]->coords.y < coords.y + 5 || Person::players[0]->onterrain)) + (Person::players[0]->coords.y < coords.y + 5 || Person::players[0]->onterrain)) { aitype = attacktypecutoff; + } if (distsq(&coords, &Person::players[0]->coords) < 30 && Animation::animations[Person::players[0]->animTarget].height == highheight && - !Game::editorenabled) + !Game::editorenabled) { aitype = attacktypecutoff; + } if (losupdatedelay < 0 && !Game::editorenabled && occluded < 2) { losupdatedelay = .2; - for (unsigned j = 0; j < Person::players.size(); j++) - if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) - if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) - if (distsq(&coords, &Person::players[j]->coords) < 400) - if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) - if (Person::players[j]->coords.y < coords.y + 5 || Person::players[j]->onterrain) + for (unsigned j = 0; j < Person::players.size(); j++) { + if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) { + if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) { + if (distsq(&coords, &Person::players[j]->coords) < 400) { + if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) { + if (Person::players[j]->coords.y < coords.y + 5 || Person::players[j]->onterrain) { if (!Person::players[j]->isWallJump() && -1 == Object::checkcollide(DoRotation(jointPos(head), 0, yaw, 0) * scale + coords, DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0) * Person::players[j]->scale + Person::players[j]->coords) || (Person::players[j]->animTarget == hanganim && normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) { @@ -7210,25 +7777,34 @@ void Person::doAI() lastseen = Person::players[j]->coords; lastseentime = 12; } + } + } + } + } + } + } } } - if (aitype == attacktypecutoff && Game::musictype != 2) + if (aitype == attacktypecutoff && Game::musictype != 2) { if (creature != wolftype) { stunned = .6; surprised = .6; } + } } - if (aitype != passivetype && Game::leveltime > .5) + if (aitype != passivetype && Game::leveltime > .5) { howactive = typeactive; + } if (aitype == passivetype) { aiupdatedelay -= multiplier; losupdatedelay -= multiplier; lastseentime += multiplier; pausetime -= multiplier; - if (lastseentime > 1) + if (lastseentime > 1) { lastseentime = 1; + } if (aiupdatedelay < 0) { if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) { @@ -7237,18 +7813,21 @@ void Person::doAI() aiupdatedelay = .05; if (distsqflat(&coords, &waypoints[waypoint]) < 1) { - if (waypointtype[waypoint] == wppause) + if (waypointtype[waypoint] == wppause) { pausetime = 4; + } waypoint++; - if (waypoint > numwaypoints - 1) + if (waypoint > numwaypoints - 1) { waypoint = 0; + } } } - if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) + if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) { forwardkeydown = 1; - else + } else { forwardkeydown = 0; + } leftkeydown = 0; backkeydown = 0; rightkeydown = 0; @@ -7257,40 +7836,47 @@ void Person::doAI() throwkeydown = 0; if (avoidcollided > .8 && !jumpkeydown && collided < .8) { - if (!avoidsomething) + if (!avoidsomething) { targetyaw += 90 * (whichdirection * 2 - 1); - else { + } else { XYZ leftpos, rightpos; float leftdist, rightdist; leftpos = coords + DoRotation(facing, 0, 90, 0); rightpos = coords - DoRotation(facing, 0, 90, 0); leftdist = distsq(&leftpos, &avoidwhere); rightdist = distsq(&rightpos, &avoidwhere); - if (leftdist < rightdist) + if (leftdist < rightdist) { targetyaw += 90; - else + } else { targetyaw -= 90; + } } } } - if (collided < 1 || animTarget != jumpupanim) + if (collided < 1 || animTarget != jumpupanim) { jumpkeydown = 0; - if ((collided > .8 && jumppower >= 5)) + } + if ((collided > .8 && jumppower >= 5)) { jumpkeydown = 1; + } //hearing sounds if (!Game::editorenabled) { - if (howactive <= typesleeping) - if (numenvsounds > 0 && (!Tutorial::active || cananger) && hostile) + if (howactive <= typesleeping) { + if (numenvsounds > 0 && (!Tutorial::active || cananger) && hostile) { for (int j = 0; j < numenvsounds; j++) { float vol = howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j]; - if (vol > 0 && distsq(&coords, &envsound[j]) < 2 * (vol + vol * (creature == rabbittype) * 3)) + if (vol > 0 && distsq(&coords, &envsound[j]) < 2 * (vol + vol * (creature == rabbittype) * 3)) { aitype = attacktypecutoff; + } } + } + } if (aitype != passivetype) { - if (howactive == typesleeping) + if (howactive == typesleeping) { setTargetAnimation(getupfromfrontanim); + } howactive = typeactive; } } @@ -7301,11 +7887,13 @@ void Person::doAI() distsq(&coords, &Person::players[0]->coords) < 400 && occluded < 25) { if (distsq(&coords, &Person::players[0]->coords) < 12 && - Animation::animations[Person::players[0]->animTarget].height != lowheight && !Game::editorenabled) + Animation::animations[Person::players[0]->animTarget].height != lowheight && !Game::editorenabled) { aitype = attacktypecutoff; + } if (distsq(&coords, &Person::players[0]->coords) < 30 && - Animation::animations[Person::players[0]->animTarget].height == highheight && !Game::editorenabled) + Animation::animations[Person::players[0]->animTarget].height == highheight && !Game::editorenabled) { aitype = attacktypecutoff; + } //wolf smell if (creature == wolftype) { @@ -7314,19 +7902,24 @@ void Person::doAI() if (j == 0 || (Person::players[j]->dead && Person::players[j]->bloodloss > 0)) { float smelldistance = 50; if (j == 0 && Person::players[j]->num_weapons > 0) { - if (weapons[Person::players[j]->weaponids[0]].bloody) + if (weapons[Person::players[j]->weaponids[0]].bloody) { smelldistance = 100; - if (Person::players[j]->num_weapons == 2) - if (weapons[Person::players[j]->weaponids[1]].bloody) + } + if (Person::players[j]->num_weapons == 2) { + if (weapons[Person::players[j]->weaponids[1]].bloody) { smelldistance = 100; + } + } } - if (j != 0) + if (j != 0) { smelldistance = 100; + } windsmell = windvector; Normalise(&windsmell); windsmell = windsmell * 2 + Person::players[j]->coords; - if (distsq(&coords, &windsmell) < smelldistance && !Game::editorenabled) + if (distsq(&coords, &windsmell) < smelldistance && !Game::editorenabled) { aitype = attacktypecutoff; + } } } } @@ -7335,9 +7928,9 @@ void Person::doAI() losupdatedelay = .2; for (unsigned j = 0; j < Person::players.size(); j++) { if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) { - if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) - if (distsq(&coords, &Person::players[j]->coords) < 400) - if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) + if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) { + if (distsq(&coords, &Person::players[j]->coords) < 400) { + if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) { if ((-1 == Object::checkcollide( DoRotation(jointPos(head), 0, yaw, 0) * scale + @@ -7349,11 +7942,15 @@ void Person::doAI() (Person::players[j]->animTarget == hanganim && normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) { lastseentime -= .2; - if (j == 0 && Animation::animations[Person::players[j]->animTarget].height == lowheight) + if (j == 0 && Animation::animations[Person::players[j]->animTarget].height == lowheight) { lastseentime -= .4; - else + } else { lastseentime -= .6; + } } + } + } + } if (lastseentime <= 0) { aitype = searchtype; lastchecktime = 12; @@ -7383,8 +7980,9 @@ void Person::doAI() if (aitype == searchtype) { aiupdatedelay -= multiplier; losupdatedelay -= multiplier; - if (!pause) + if (!pause) { lastseentime -= multiplier; + } lastchecktime -= multiplier; if (isRun() && !onground) { @@ -7394,8 +7992,9 @@ void Person::doAI() XYZ test = coords + facing; test.y -= 10; j = Object::checkcollide(test2, test, laststanding); - if (j == -1) + if (j == -1) { j = Object::checkcollide(test2, test); + } if (j == -1) { velocity = 0; setTargetAnimation(getStop()); @@ -7410,8 +8009,9 @@ void Person::doAI() lastpathfindpoint2 = -1; lastpathfindpoint3 = -1; lastpathfindpoint4 = -1; - } else + } else { laststanding = j; + } } } //check out last seen location @@ -7437,33 +8037,37 @@ void Person::doAI() throwkeydown = 0; if (avoidcollided > .8 && !jumpkeydown && collided < .8) { - if (!avoidsomething) + if (!avoidsomething) { targetyaw += 90 * (whichdirection * 2 - 1); - else { + } else { XYZ leftpos, rightpos; float leftdist, rightdist; leftpos = coords + DoRotation(facing, 0, 90, 0); rightpos = coords - DoRotation(facing, 0, 90, 0); leftdist = distsq(&leftpos, &avoidwhere); rightdist = distsq(&rightpos, &avoidwhere); - if (leftdist < rightdist) + if (leftdist < rightdist) { targetyaw += 90; - else + } else { targetyaw -= 90; + } } } } - if (collided < 1 || animTarget != jumpupanim) + if (collided < 1 || animTarget != jumpupanim) { jumpkeydown = 0; - if ((collided > .8 && jumppower >= 5)) + } + if ((collided > .8 && jumppower >= 5)) { jumpkeydown = 1; + } - if (numenvsounds > 0 && ((!Tutorial::active || cananger) && hostile)) + if (numenvsounds > 0 && ((!Tutorial::active || cananger) && hostile)) { for (int k = 0; k < numenvsounds; k++) { if (distsq(&coords, &envsound[k]) < 2 * (envsoundvol[k] + envsoundvol[k] * (creature == rabbittype) * 3)) { aitype = attacktypecutoff; } } + } if (!Person::players[0]->dead && losupdatedelay < 0 && @@ -7475,10 +8079,10 @@ void Person::doAI() aitype = attacktypecutoff; lastseentime = 1; } - if (abs(Random() % 2) || Animation::animations[animTarget].height != lowheight) + if (abs(Random() % 2) || Animation::animations[animTarget].height != lowheight) { //TODO: factor out canSeePlayer() - if (distsq(&coords, &Person::players[0]->coords) < 400) - if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) + if (distsq(&coords, &Person::players[0]->coords) < 400) { + if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) { if ((Object::checkcollide( DoRotation(jointPos(head), 0, yaw, 0) * scale + @@ -7494,6 +8098,9 @@ void Person::doAI() aitype = attacktypecutoff; lastseentime = 1; } + } + } + } } //player escaped if (lastseentime < 0) { @@ -7510,8 +8117,9 @@ void Person::doAI() } } - if (aitype != gethelptype) + if (aitype != gethelptype) { runninghowlong = 0; + } //get help from buddies if (aitype == gethelptype) { @@ -7554,8 +8162,9 @@ void Person::doAI() XYZ flatfacing = Person::players[ally]->coords; facing.y += jointPos(head).y * scale; flatfacing.y += Person::players[ally]->jointPos(head).y * Person::players[ally]->scale; - if (-1 != Object::checkcollide(facing, flatfacing)) + if (-1 != Object::checkcollide(facing, flatfacing)) { lastseentime -= .1; + } //no available ally, run back to player if (ally <= 0 || @@ -7585,19 +8194,20 @@ void Person::doAI() } if (avoidcollided > .8 && !jumpkeydown && collided < .8) { - if (!avoidsomething) + if (!avoidsomething) { targetyaw += 90 * (whichdirection * 2 - 1); - else { + } else { XYZ leftpos, rightpos; float leftdist, rightdist; leftpos = coords + DoRotation(facing, 0, 90, 0); rightpos = coords - DoRotation(facing, 0, 90, 0); leftdist = distsq(&leftpos, &avoidwhere); rightdist = distsq(&rightpos, &avoidwhere); - if (leftdist < rightdist) + if (leftdist < rightdist) { targetyaw += 90; - else + } else { targetyaw -= 90; + } } } } @@ -7608,10 +8218,12 @@ void Person::doAI() crouchkeydown = 0; attackkeydown = 0; } - if (collided < 1 || animTarget != jumpupanim) + if (collided < 1 || animTarget != jumpupanim) { jumpkeydown = 0; - if (collided > .8 && jumppower >= 5) + } + if (collided > .8 && jumppower >= 5) { jumpkeydown = 1; + } } //retreiving a weapon on the ground @@ -7626,7 +8238,7 @@ void Person::doAI() if (ally < 0) { int closest = -1; float closestdist = -1; - for (unsigned k = 0; k < weapons.size(); k++) + for (unsigned k = 0; k < weapons.size(); k++) { if (weapons[k].owner == -1) { float distance = distsq(&coords, &weapons[k].position); if (closestdist == -1 || distance < closestdist) { @@ -7635,20 +8247,23 @@ void Person::doAI() } closest = k; } - if (closest != -1) + } + if (closest != -1) { ally = closest; - else + } else { ally = -1; + } } lastseentime = 12; - if (!Person::players[0]->dead && ((!Tutorial::active || cananger) && hostile)) + if (!Person::players[0]->dead && ((!Tutorial::active || cananger) && hostile)) { if (ally < 0 || weaponactive != -1 || lastchecktime <= 0) { aitype = attacktypecutoff; lastseentime = 1; } - if (!Person::players[0]->dead) + } + if (!Person::players[0]->dead) { if (ally >= 0) { if (weapons[ally].owner != -1 || distsq(&coords, &weapons[ally].position) > 16) { @@ -7662,22 +8277,24 @@ void Person::doAI() forwardkeydown = 1; if (avoidcollided > .8 && !jumpkeydown && collided < .8) { - if (!avoidsomething) + if (!avoidsomething) { targetyaw += 90 * (whichdirection * 2 - 1); - else { + } else { XYZ leftpos, rightpos; float leftdist, rightdist; leftpos = coords + DoRotation(facing, 0, 90, 0); rightpos = coords - DoRotation(facing, 0, 90, 0); leftdist = distsq(&leftpos, &avoidwhere); rightdist = distsq(&rightpos, &avoidwhere); - if (leftdist < rightdist) + if (leftdist < rightdist) { targetyaw += 90; - else + } else { targetyaw -= 90; + } } } } + } leftkeydown = 0; backkeydown = 0; @@ -7686,20 +8303,23 @@ void Person::doAI() throwkeydown = 1; crouchkeydown = 0; if (animTarget != crouchremoveknifeanim && - animTarget != removeknifeanim) + animTarget != removeknifeanim) { throwtogglekeydown = 0; + } drawkeydown = 0; } - if (collided < 1 || animTarget != jumpupanim) + if (collided < 1 || animTarget != jumpupanim) { jumpkeydown = 0; - if ((collided > .8 && jumppower >= 5)) + } + if ((collided > .8 && jumppower >= 5)) { jumpkeydown = 1; + } } if (aitype == attacktypecutoff) { aiupdatedelay -= multiplier; //dodge or reverse rabbit kicks, knife throws, flips - if (damage < damagetolerance * 2 / 3) + if (damage < damagetolerance * 2 / 3) { if ((Person::players[0]->animTarget == rabbitkickanim || Person::players[0]->animTarget == knifethrowanim || (Person::players[0]->isFlip() && @@ -7707,8 +8327,9 @@ void Person::doAI() !Person::players[0]->skeleton.free && (aiupdatedelay < .1)) { attackkeydown = 0; - if (isIdle()) + if (isIdle()) { crouchkeydown = 1; + } if (Person::players[0]->animTarget != rabbitkickanim && Person::players[0]->weaponactive != -1) { if (weapons[Person::players[0]->weaponids[0]].getType() == knife) { if (isIdle() || isCrouch() || isRun() || isFlip()) { @@ -7728,19 +8349,22 @@ void Person::doAI() forwardkeydown = 0; aiupdatedelay = .02; } + } //get confused by flips if (Person::players[0]->isFlip() && !Person::players[0]->skeleton.free && Person::players[0]->animTarget != walljumprightkickanim && Person::players[0]->animTarget != walljumpleftkickanim) { - if (distsq(&Person::players[0]->coords, &coords) < 25) - if ((1 - damage / damagetolerance) > .5) + if (distsq(&Person::players[0]->coords, &coords) < 25) { + if ((1 - damage / damagetolerance) > .5) { stunned = 1; + } + } } //go for weapon on the ground - if (wentforweapon < 3) - for (unsigned k = 0; k < weapons.size(); k++) - if (creature != wolftype) + if (wentforweapon < 3) { + for (unsigned k = 0; k < weapons.size(); k++) { + if (creature != wolftype) { if (num_weapons == 0 && weapons[k].owner == -1 && weapons[k].velocity.x == 0 && @@ -7753,9 +8377,12 @@ void Person::doAI() ally = -1; } } + } + } + } //dodge/reverse walljump kicks - if (damage < damagetolerance / 2) - if (Animation::animations[animTarget].height != highheight) + if (damage < damagetolerance / 2) { + if (Animation::animations[animTarget].height != highheight) { if (damage < damagetolerance * .5 && ((Person::players[0]->animTarget == walljumprightkickanim || Person::players[0]->animTarget == walljumpleftkickanim) && @@ -7765,16 +8392,19 @@ void Person::doAI() difficulty != 2)))) { crouchkeydown = 1; } + } + } //walked off a ledge (?) - if (isRun() && !onground) + if (isRun() && !onground) { if (coords.y > terrain.getHeight(coords.x, coords.z) + 10) { XYZ test2 = coords + facing; test2.y += 5; XYZ test = coords + facing; test.y -= 10; j = Object::checkcollide(test2, test, laststanding); - if (j == -1) + if (j == -1) { j = Object::checkcollide(test2, test); + } if (j == -1) { velocity = 0; setTargetAnimation(getStop()); @@ -7788,9 +8418,11 @@ void Person::doAI() lastpathfindpoint2 = -1; lastpathfindpoint3 = -1; lastpathfindpoint4 = -1; - } else + } else { laststanding = j; + } } + } //lose sight of player in the air (?) if (Person::players[0]->coords.y > coords.y + 5 && Animation::animations[Person::players[0]->animTarget].height != highheight && @@ -7812,37 +8444,41 @@ void Person::doAI() animTarget != backhandspringanim && animTarget != dodgebackanim) { //draw weapon - if (weaponactive == -1 && num_weapons > 0) + if (weaponactive == -1 && num_weapons > 0) { drawkeydown = Random() % 2; - else + } else { drawkeydown = 0; + } rabbitkickenabled = Random() % 2; //chase player XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity; XYZ targetpoint = Person::players[0]->coords; if (distsq(&Person::players[0]->coords, &coords) < - distsq(&rotatetarget, &coords)) + distsq(&rotatetarget, &coords)) { targetpoint += Person::players[0]->velocity * findDistance(&Person::players[0]->coords, &coords) / findLength(&velocity); + } targetyaw = roughDirectionTo(coords, targetpoint); lookyaw = targetyaw; aiupdatedelay = .2 + fabs((float)(Random() % 100) / 1000); - if (distsq(&coords, &Person::players[0]->coords) > 5 && (Person::players[0]->weaponactive == -1 || weaponactive != -1)) + if (distsq(&coords, &Person::players[0]->coords) > 5 && (Person::players[0]->weaponactive == -1 || weaponactive != -1)) { forwardkeydown = 1; - else if ((distsq(&coords, &Person::players[0]->coords) > 16 || - distsq(&coords, &Person::players[0]->coords) < 9) && - Person::players[0]->weaponactive != -1) + } else if ((distsq(&coords, &Person::players[0]->coords) > 16 || + distsq(&coords, &Person::players[0]->coords) < 9) && + Person::players[0]->weaponactive != -1) { forwardkeydown = 1; - else if (Random() % 6 == 0 || (creature == wolftype && Random() % 3 == 0)) + } else if (Random() % 6 == 0 || (creature == wolftype && Random() % 3 == 0)) { forwardkeydown = 1; - else + } else { forwardkeydown = 0; + } //chill out around the corpse if (Person::players[0]->dead) { forwardkeydown = 0; - if (Random() % 10 == 0) + if (Random() % 10 == 0) { forwardkeydown = 1; + } if (Random() % 100 == 0) { aitype = pathfindtype; finalfinaltarget = waypoints[waypoint]; @@ -7860,15 +8496,18 @@ void Person::doAI() crouchkeydown = 0; throwkeydown = 0; - if (avoidcollided > .8 && !jumpkeydown && collided < .8) + if (avoidcollided > .8 && !jumpkeydown && collided < .8) { targetyaw += 90 * (whichdirection * 2 - 1); + } //attack!!! - if (Random() % 2 == 0 || weaponactive != -1 || creature == wolftype) + if (Random() % 2 == 0 || weaponactive != -1 || creature == wolftype) { attackkeydown = 1; - else + } else { attackkeydown = 0; - if (isRun() && Random() % 6 && distsq(&coords, &Person::players[0]->coords) > 7) + } + if (isRun() && Random() % 6 && distsq(&coords, &Person::players[0]->coords) > 7) { attackkeydown = 0; + } //TODO: wat if (aitype != playercontrolled && @@ -7876,7 +8515,7 @@ void Person::doAI() isCrouch() || isRun())) { int target = -2; - for (unsigned j = 0; j < Person::players.size(); j++) + for (unsigned j = 0; j < Person::players.size(); j++) { if (j != id && !Person::players[j]->skeleton.free && Person::players[j]->hasvictim && (Tutorial::active && reversaltrain || @@ -7891,7 +8530,7 @@ void Person::doAI() Person::players[j]->animTarget == swordslashanim && weaponactive != -1 || Person::players[j]->animTarget == staffhitanim || - Person::players[j]->animTarget == staffspinhitanim)) + Person::players[j]->animTarget == staffspinhitanim)) { if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 4 && Person::players[j]->victim == Person::players[id] && (Person::players[j]->animTarget == sweepanim || @@ -7911,38 +8550,49 @@ void Person::doAI() target = j; } } - if (target >= 0) + } + } + if (target >= 0) { Person::players[target]->Reverse(); + } } - if (collided < 1) + if (collided < 1) { jumpkeydown = 0; + } if (collided > .8 && jumppower >= 5 || distsq(&coords, &Person::players[0]->coords) > 400 && onterrain && - creature == rabbittype) + creature == rabbittype) { jumpkeydown = 1; + } //TODO: why are we controlling the human? - if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) + if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) { Person::players[0]->jumpkeydown = 0; + } if (Person::players[0]->animTarget == jumpdownanim && - distsq(&Person::players[0]->coords, &coords) < 40) + distsq(&Person::players[0]->coords, &coords) < 40) { crouchkeydown = 1; - if (jumpkeydown) + } + if (jumpkeydown) { attackkeydown = 0; + } - if (Tutorial::active) - if (!canattack) + if (Tutorial::active) { + if (!canattack) { attackkeydown = 0; + } + } XYZ facing = coords; XYZ flatfacing = Person::players[0]->coords; facing.y += jointPos(head).y * scale; flatfacing.y += Person::players[0]->jointPos(head).y * Person::players[0]->scale; - if (occluded >= 2) + if (occluded >= 2) { if (-1 != Object::checkcollide(facing, flatfacing)) { - if (!pause) + if (!pause) { lastseentime -= .2; + } if (lastseentime <= 0 && (creature != wolftype || weaponstuck == -1)) { @@ -7951,25 +8601,30 @@ void Person::doAI() lastseen = Person::players[0]->coords; lastseentime = 12; } - } else + } else { lastseentime = 1; + } + } } } if (Animation::animations[Person::players[0]->animTarget].height == highheight && (aitype == attacktypecutoff || - aitype == searchtype)) + aitype == searchtype)) { if (Person::players[0]->coords.y > terrain.getHeight(Person::players[0]->coords.x, Person::players[0]->coords.z) + 10) { XYZ test = Person::players[0]->coords; test.y -= 40; - if (-1 == Object::checkcollide(Person::players[0]->coords, test)) + if (-1 == Object::checkcollide(Person::players[0]->coords, test)) { stunned = 1; + } } + } //stunned if (aitype == passivetype && !(numwaypoints > 1) || stunned > 0 || pause && damage > superpermanentdamage) { - if (pause) + if (pause) { lastseentime = 1; + } targetyaw = yaw; forwardkeydown = 0; leftkeydown = 0; diff --git a/Source/Objects/Weapons.cpp b/Source/Objects/Weapons.cpp index 42ee250..dc41e11 100644 --- a/Source/Objects/Weapons.cpp +++ b/Source/Objects/Weapons.cpp @@ -175,8 +175,9 @@ void Weapon::doStuff(int i) Person::players[owner]->num_weapons--; if (Person::players[owner]->num_weapons) { Person::players[owner]->weaponids[0] = Person::players[owner]->weaponids[Person::players[owner]->num_weapons]; - if (Person::players[owner]->weaponstuck == Person::players[owner]->num_weapons) + if (Person::players[owner]->weaponstuck == Person::players[owner]->num_weapons) { Person::players[owner]->weaponstuck = 0; + } } } owner = -1; @@ -205,12 +206,13 @@ void Weapon::doStuff(int i) Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .1, 1, Random() % 360); normalrot = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0); velocity = 0; - if (type == knife) + if (type == knife) { position = colpoint - normalrot * .1; - else if (type == sword) + } else if (type == sword) { position = colpoint - normalrot * .2; - else if (type == staff) + } else if (type == staff) { position = colpoint - normalrot * .2; + } XYZ temppoint1, temppoint2; float distance; @@ -223,8 +225,9 @@ void Weapon::doStuff(int i) temppoint2.y = 0; rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2)); rotation1 *= 360 / 6.28; - if (temppoint1.x > temppoint2.x) + if (temppoint1.x > temppoint2.x) { rotation1 = 360 - rotation1; + } rotation3 = 0; smallrotation = 90; @@ -268,14 +271,16 @@ void Weapon::doStuff(int i) Person::players[j]->aitype = attacktypecutoff; } else { - if (j != 0) + if (j != 0) { numthrowkill++; + } Person::players[j]->num_weapons++; Person::players[j]->weaponstuck = Person::players[j]->num_weapons - 1; - if (normaldotproduct(Person::players[j]->facing, velocity) > 0) + if (normaldotproduct(Person::players[j]->facing, velocity) > 0) { Person::players[j]->weaponstuckwhere = 1; - else + } else { Person::players[j]->weaponstuckwhere = 0; + } Person::players[j]->weaponids[Person::players[j]->num_weapons - 1] = i; @@ -284,20 +289,25 @@ void Weapon::doStuff(int i) Person::players[j]->jointVel(neck) += velocity * 2; Person::players[j]->jointVel(rightshoulder) += velocity * 2; Person::players[j]->jointVel(leftshoulder) += velocity * 2; - if (bloodtoggle && !Tutorial::active) + if (bloodtoggle && !Tutorial::active) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3); - if (Tutorial::active) + } + if (Tutorial::active) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .8, .3); + } footvel = tippoint - position; Normalise(&footvel); - if (bloodtoggle && !Tutorial::active) + if (bloodtoggle && !Tutorial::active) { Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * -1, 1, 0, 0, .6, 1); + } if (!Tutorial::active) { - if (Person::players[j]->weaponstuckwhere == 0) + if (Person::players[j]->weaponstuckwhere == 0) { Person::players[j]->DoBloodBig(2, 205); - if (Person::players[j]->weaponstuckwhere == 1) + } + if (Person::players[j]->weaponstuckwhere == 1) { Person::players[j]->DoBloodBig(2, 200); + } Person::players[j]->damage += 200 / Person::players[j]->armorhigh; Person::players[j]->deathbleeding = 1; Person::players[j]->bloodloss += (200 + abs((float)(Random() % 40)) - 20) / Person::players[j]->armorhigh; @@ -308,10 +318,11 @@ void Weapon::doStuff(int i) emit_sound_at(fleshstabsound, position, 128.); - if (Animation::animations[Person::players[0]->animTarget].height == highheight) + if (Animation::animations[Person::players[0]->animTarget].height == highheight) { award_bonus(0, ninja); - else + } else { award_bonus(0, Bullseyebonus); + } } } else { missed = 1; @@ -364,14 +375,17 @@ void Weapon::doStuff(int i) XYZ terrainlight; terrainlight = terrain.getLighting(position.x, position.z); if (environment == snowyenvironment) { - if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, position, velocity, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7); + } } else if (environment == grassyenvironment) { - if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, position, velocity, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5); + } } else if (environment == desertenvironment) { - if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, position, velocity, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7); + } } bloody = 0; @@ -404,8 +418,9 @@ void Weapon::doStuff(int i) bigtilt = 0; bigtilt2 = 0; bigrotation = 0; - if (temppoint1.x > temppoint2.x) + if (temppoint1.x > temppoint2.x) { rotation1 = 360 - rotation1; + } } } @@ -489,22 +504,25 @@ void Weapon::doStuff(int i) position += terrainnormal * .002; bounceness = terrainnormal * findLength(&velocity) * (abs(normaldotproduct(velocity, terrainnormal))); - if (findLengthfast(&velocity) < findLengthfast(&bounceness)) + if (findLengthfast(&velocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(velocity, terrainnormal)); velocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { velocity *= 1 - friction * frictionness; - else + } else { velocity = 0; + } velocity += bounceness * elasticity; if (findLengthfast(&bounceness) > 1) { int whichsound; - if (type == staff) + if (type == staff) { whichsound = footstepsound3 + abs(Random() % 2); - else + } else { whichsound = clank1sound + abs(Random() % 4); + } emit_sound_at(whichsound, position, 128 * findLengthfast(&bounceness)); } } @@ -519,27 +537,30 @@ void Weapon::doStuff(int i) tippoint += terrainnormal * .002; bounceness = terrainnormal * findLength(&tipvelocity) * (abs(normaldotproduct(tipvelocity, terrainnormal))); - if (findLengthfast(&tipvelocity) < findLengthfast(&bounceness)) + if (findLengthfast(&tipvelocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(tipvelocity, terrainnormal)); tipvelocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { tipvelocity *= 1 - friction * frictionness; - else + } else { tipvelocity = 0; + } tipvelocity += bounceness * elasticity; if (findLengthfast(&bounceness) > 1) { int whichsound; - if (type == staff) + if (type == staff) { whichsound = footstepsound3 + abs(Random() % 2); - else + } else { whichsound = clank1sound + abs(Random() % 4); + } emit_sound_at(whichsound, position, 128 * findLengthfast(&bounceness)); } } - if ((Object::objects[k]->type != boxtype && Object::objects[k]->type != platformtype && Object::objects[k]->type != walltype && Object::objects[k]->type != weirdtype) || Object::objects[k]->pitch != 0) + if ((Object::objects[k]->type != boxtype && Object::objects[k]->type != platformtype && Object::objects[k]->type != walltype && Object::objects[k]->type != weirdtype) || Object::objects[k]->pitch != 0) { for (int m = 0; m < 2; m++) { mid = (position * (21 + (float)m * 10) + tippoint * (19 - (float)m * 10)) / 40; oldmid2 = mid; @@ -555,22 +576,25 @@ void Weapon::doStuff(int i) ReflectVector(&velocity, &terrainnormal); bounceness = terrainnormal * findLength(&velocity) * (abs(normaldotproduct(velocity, terrainnormal))); - if (findLengthfast(&velocity) < findLengthfast(&bounceness)) + if (findLengthfast(&velocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(velocity, terrainnormal)); velocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { velocity *= 1 - friction * frictionness; - else + } else { velocity = 0; + } velocity += bounceness * elasticity; if (findLengthfast(&bounceness) > 1) { int whichsound; - if (type == staff) + if (type == staff) { whichsound = footstepsound3 + abs(Random() % 2); - else + } else { whichsound = clank1sound + abs(Random() % 4); + } emit_sound_at(whichsound, mid, 128 * findLengthfast(&bounceness)); } position += (mid - oldmid2) * (20 / (1 + (float)m * 10)); @@ -590,28 +614,31 @@ void Weapon::doStuff(int i) ReflectVector(&tipvelocity, &terrainnormal); bounceness = terrainnormal * findLength(&tipvelocity) * (abs(normaldotproduct(tipvelocity, terrainnormal))); - if (findLengthfast(&tipvelocity) < findLengthfast(&bounceness)) + if (findLengthfast(&tipvelocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(tipvelocity, terrainnormal)); tipvelocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { tipvelocity *= 1 - friction * frictionness; - else + } else { tipvelocity = 0; + } tipvelocity += bounceness * elasticity; if (findLengthfast(&bounceness) > 1) { int whichsound; - if (type == staff) + if (type == staff) { whichsound = footstepsound3 + abs(Random() % 2); - else + } else { whichsound = clank1sound + abs(Random() % 4); + } emit_sound_at(whichsound, mid, 128 * findLengthfast(&bounceness)); } tippoint += (mid - oldmid2) * (20 / (1 + (float)m * 10)); } } - else { + } else { start = position; end = tippoint; whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw); @@ -657,35 +684,40 @@ void Weapon::doStuff(int i) whichhit = terrain.lineTerrain(oldposition, position, &colpoint); if (whichhit != -1 || position.y < terrain.getHeight(position.x, position.z)) { hitsomething = 1; - if (whichhit != -1) + if (whichhit != -1) { position = colpoint * terrain.scale; - else + } else { position.y = terrain.getHeight(position.x, position.z); + } terrainnormal = terrain.getNormal(position.x, position.z); ReflectVector(&velocity, &terrainnormal); position += terrainnormal * .002; bounceness = terrainnormal * findLength(&velocity) * (abs(normaldotproduct(velocity, terrainnormal))); - if (findLengthfast(&velocity) < findLengthfast(&bounceness)) + if (findLengthfast(&velocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(velocity, terrainnormal)); velocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { velocity *= 1 - friction * frictionness; - else + } else { velocity = 0; - if (terrain.getOpacity(position.x, position.z) < .2) + } + if (terrain.getOpacity(position.x, position.z) < .2) { velocity += bounceness * elasticity * .3; - else + } else { velocity += bounceness * elasticity; + } if (findLengthfast(&bounceness) > 1) { int whichsound; if (terrain.getOpacity(position.x, position.z) > .2) { - if (type == staff) + if (type == staff) { whichsound = footstepsound3 + abs(Random() % 2); - else + } else { whichsound = clank1sound + abs(Random() % 4); + } } else { whichsound = footstepsound + abs(Random() % 2); } @@ -696,49 +728,57 @@ void Weapon::doStuff(int i) XYZ terrainlight; terrainlight = terrain.getLighting(position.x, position.z); if (environment == snowyenvironment) { - if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, position, velocity, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7); + } } else if (environment == grassyenvironment) { - if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, position, velocity, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5); + } } else if (environment == desertenvironment) { - if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&position, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, position, velocity, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7); + } } } } } whichhit = terrain.lineTerrain(oldtippoint, tippoint, &colpoint); if (whichhit != -1 || tippoint.y < terrain.getHeight(tippoint.x, tippoint.z)) { - if (whichhit != -1) + if (whichhit != -1) { tippoint = colpoint * terrain.scale; - else + } else { tippoint.y = terrain.getHeight(tippoint.x, tippoint.z); + } terrainnormal = terrain.getNormal(tippoint.x, tippoint.z); ReflectVector(&tipvelocity, &terrainnormal); tippoint += terrainnormal * .002; bounceness = terrainnormal * findLength(&tipvelocity) * (abs(normaldotproduct(tipvelocity, terrainnormal))); - if (findLengthfast(&tipvelocity) < findLengthfast(&bounceness)) + if (findLengthfast(&tipvelocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(tipvelocity, terrainnormal)); tipvelocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { tipvelocity *= 1 - friction * frictionness; - else + } else { tipvelocity = 0; - if (terrain.getOpacity(tippoint.x, tippoint.z) < .2) + } + if (terrain.getOpacity(tippoint.x, tippoint.z) < .2) { tipvelocity += bounceness * elasticity * .3; - else + } else { tipvelocity += bounceness * elasticity; + } if (findLengthfast(&bounceness) > 1) { int whichsound; if (terrain.getOpacity(tippoint.x, tippoint.z) > .2) { - if (type == staff) + if (type == staff) { whichsound = footstepsound3 + abs(Random() % 2); - else + } else { whichsound = clank1sound + abs(Random() % 4); + } } else { whichsound = footstepsound + abs(Random() % 2); } @@ -749,14 +789,17 @@ void Weapon::doStuff(int i) XYZ terrainlight; terrainlight = terrain.getLighting(tippoint.x, tippoint.z); if (environment == snowyenvironment) { - if (distsq(&tippoint, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&tippoint, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, tippoint, tipvelocity, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7); + } } else if (environment == grassyenvironment) { - if (distsq(&tippoint, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&tippoint, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, tippoint, tipvelocity, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5); + } } else if (environment == desertenvironment) { - if (distsq(&tippoint, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&tippoint, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, tippoint, tipvelocity, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7); + } } } } @@ -775,26 +818,31 @@ void Weapon::doStuff(int i) ReflectVector(&velocity, &terrainnormal); //mid+=terrainnormal*.002; bounceness = terrainnormal * findLength(&velocity) * (abs(normaldotproduct(velocity, terrainnormal))); - if (findLengthfast(&velocity) < findLengthfast(&bounceness)) + if (findLengthfast(&velocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(velocity, terrainnormal)); velocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { velocity *= 1 - friction * frictionness; - else + } else { velocity = 0; - if (terrain.getOpacity(mid.x, mid.z) < .2) + } + if (terrain.getOpacity(mid.x, mid.z) < .2) { velocity += bounceness * elasticity * .3; - else + } else { velocity += bounceness * elasticity; + } if (findLengthfast(&bounceness) > 1) { int whichsound; if (terrain.getOpacity(mid.x, mid.z) > .2) { - if (type == staff) + if (type == staff) { whichsound = footstepsound3 + abs(Random() % 2); - if (type != staff) + } + if (type != staff) { whichsound = clank1sound + abs(Random() % 4); + } } else { whichsound = footstepsound + abs(Random() % 2); } @@ -818,26 +866,31 @@ void Weapon::doStuff(int i) ReflectVector(&tipvelocity, &terrainnormal); //mid+=terrainnormal*.002; bounceness = terrainnormal * findLength(&tipvelocity) * (abs(normaldotproduct(tipvelocity, terrainnormal))); - if (findLengthfast(&tipvelocity) < findLengthfast(&bounceness)) + if (findLengthfast(&tipvelocity) < findLengthfast(&bounceness)) { bounceness = 0; + } frictionness = abs(normaldotproduct(tipvelocity, terrainnormal)); tipvelocity -= bounceness; - if (1 - friction * frictionness > 0) + if (1 - friction * frictionness > 0) { tipvelocity *= 1 - friction * frictionness; - else + } else { tipvelocity = 0; - if (terrain.getOpacity(mid.x, mid.z) < .2) + } + if (terrain.getOpacity(mid.x, mid.z) < .2) { tipvelocity += bounceness * elasticity * .3; - else + } else { tipvelocity += bounceness * elasticity; + } if (findLengthfast(&bounceness) > 1) { int whichsound; if (terrain.getOpacity(mid.x, mid.z) > .2) { - if (type == staff) + if (type == staff) { whichsound = footstepsound3 + abs(Random() % 2); - if (type != staff) + } + if (type != staff) { whichsound = clank1sound + abs(Random() % 4); + } } else { whichsound = footstepsound + abs(Random() % 2); } @@ -871,8 +924,9 @@ void Weapon::doStuff(int i) bigtilt = 0; bigtilt2 = 0; bigrotation = 0; - if (temppoint1.x > temppoint2.x) + if (temppoint1.x > temppoint2.x) { rotation1 = 360 - rotation1; + } //Stop moving if (findLengthfast(&velocity) < .3 && findLengthfast(&tipvelocity) < .3 && hitsomething) { @@ -890,10 +944,12 @@ void Weapon::doStuff(int i) if (blooddrip && bloody) { blooddripdelay -= blooddrip * multiplier / 2; blooddrip -= multiplier; - if (blooddrip < 0) + if (blooddrip < 0) { blooddrip = 0; - if (blooddrip > 5) + } + if (blooddrip > 5) { blooddrip = 5; + } if (blooddripdelay < 0 && bloodtoggle) { blooddripdelay = 1; XYZ bloodvel; @@ -963,14 +1019,17 @@ void Weapon::draw() bool draw = false; if (owner == -1) { draw = true; - if (velocity.x && !physics) + if (velocity.x && !physics) { drawhowmany = 10; - else + } else { drawhowmany = 1; + } } else { - if (Person::players[owner]->occluded < 25) - if ((frustum.SphereInFrustum(Person::players[owner]->coords.x, Person::players[owner]->coords.y + Person::players[owner]->scale * 3, Person::players[owner]->coords.z, Person::players[owner]->scale * 8) && distsq(&viewer, &Person::players[owner]->coords) < viewdistance * viewdistance) || Person::players[owner]->skeleton.free == 3) + if (Person::players[owner]->occluded < 25) { + if ((frustum.SphereInFrustum(Person::players[owner]->coords.x, Person::players[owner]->coords.y + Person::players[owner]->scale * 3, Person::players[owner]->coords.z, Person::players[owner]->scale * 8) && distsq(&viewer, &Person::players[owner]->coords) < viewdistance * viewdistance) || Person::players[owner]->skeleton.free == 3) { draw = true; + } + } if ( (Person::players[owner]->animTarget == knifeslashstartanim || Person::players[owner]->animTarget == swordsneakattackanim || @@ -1012,10 +1071,11 @@ void Weapon::draw() glMatrixMode(GL_MODELVIEW); glPushMatrix(); glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, j / drawhowmany); - if (owner == -1) + if (owner == -1) { glTranslatef(position.x * (((float)(j)) / drawhowmany) + lastdrawnposition.x * (1 - ((float)(j)) / drawhowmany), position.y * (((float)(j)) / drawhowmany) + lastdrawnposition.y * (1 - ((float)(j)) / drawhowmany), position.z * (((float)(j)) / drawhowmany) + lastdrawnposition.z * (1 - ((float)(j)) / drawhowmany)); - else + } else { glTranslatef(position.x * (((float)(j)) / drawhowmany) + lastdrawnposition.x * (1 - ((float)(j)) / drawhowmany), position.y * (((float)(j)) / drawhowmany) - .02 + lastdrawnposition.y * (1 - ((float)(j)) / drawhowmany), position.z * (((float)(j)) / drawhowmany) + lastdrawnposition.z * (1 - ((float)(j)) / drawhowmany)); + } glRotatef(bigrotation * (((float)(j)) / drawhowmany) + lastdrawnbigrotation * (1 - ((float)(j)) / drawhowmany), 0, 1, 0); glRotatef(bigtilt2 * (((float)(j)) / drawhowmany) + lastdrawnbigtilt2 * (1 - ((float)(j)) / drawhowmany), 1, 0, 0); glRotatef(bigtilt * (((float)(j)) / drawhowmany) + lastdrawnbigtilt * (1 - ((float)(j)) / drawhowmany), 0, 0, 1); @@ -1037,23 +1097,29 @@ void Weapon::draw() glEnable(GL_LIGHTING); switch (type) { case knife: - if (!bloody || !bloodtoggle) + if (!bloody || !bloodtoggle) { throwingknifemodel.drawdifftex(knifetextureptr); + } if (bloodtoggle) { - if (bloody == 1) + if (bloody == 1) { throwingknifemodel.drawdifftex(lightbloodknifetextureptr); - if (bloody == 2) + } + if (bloody == 2) { throwingknifemodel.drawdifftex(bloodknifetextureptr); + } } break; case sword: - if (!bloody || !bloodtoggle) + if (!bloody || !bloodtoggle) { swordmodel.drawdifftex(swordtextureptr); + } if (bloodtoggle) { - if (bloody == 1) + if (bloody == 1) { swordmodel.drawdifftex(lightbloodswordtextureptr); - if (bloody == 2) + } + if (bloody == 2) { swordmodel.drawdifftex(bloodswordtextureptr); + } } break; case staff: @@ -1074,8 +1140,9 @@ void Weapon::draw() lastdrawnbigtilt2 = bigtilt2; lastdrawnsmallrotation = smallrotation; lastdrawnsmallrotation2 = smallrotation2; - if (owner != -1) + if (owner != -1) { lastdrawnanim = Person::players[owner]->animCurrent; + } } if (owner != -1) { glMatrixMode(GL_MODELVIEW); diff --git a/Source/Tutorial.cpp b/Source/Tutorial.cpp index 3d5fed1..4a03437 100644 --- a/Source/Tutorial.cpp +++ b/Source/Tutorial.cpp @@ -92,14 +92,18 @@ void Tutorial::Do(float multiplier) for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) { if (Random() % 2 == 0) { - if (!Person::players[1]->skeleton.free) + if (!Person::players[1]->skeleton.free) { temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2; - if (Person::players[1]->skeleton.free) + } + if (Person::players[1]->skeleton.free) { temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2; - if (!Person::players[1]->skeleton.free) + } + if (!Person::players[1]->skeleton.free) { temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords; - if (Person::players[1]->skeleton.free) + } + if (Person::players[1]->skeleton.free) { temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords; + } Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); } } @@ -123,8 +127,9 @@ void Tutorial::Do(float multiplier) if (bonus == cannon) { bonus = Slicebonus; againbonus = 1; - } else + } else { againbonus = 0; + } break; case 27: maxtime = 4; @@ -297,10 +302,11 @@ void Tutorial::Do(float multiplier) Person::players[1]->num_weapons = 1; Person::players[1]->weaponids[0] = 0; - if (Person::players[0]->weaponactive != -1) + if (Person::players[0]->weaponactive != -1) { weapons[Person::players[0]->weaponids[Person::players[0]->weaponactive]].setType(staff); - else + } else { weapons[0].setType(staff); + } break; case 49: canattack = 0; @@ -330,14 +336,18 @@ void Tutorial::Do(float multiplier) for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) { if (Random() % 2 == 0) { - if (!Person::players[1]->skeleton.free) + if (!Person::players[1]->skeleton.free) { temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2; - if (Person::players[1]->skeleton.free) + } + if (Person::players[1]->skeleton.free) { temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2; - if (!Person::players[1]->skeleton.free) + } + if (!Person::players[1]->skeleton.free) { temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords; - if (Person::players[1]->skeleton.free) + } + if (Person::players[1]->skeleton.free) { temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords; + } Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); } } @@ -354,96 +364,118 @@ void Tutorial::Do(float multiplier) default: break; } - if (stage <= 51) + if (stage <= 51) { stagetime = 0; + } } //Tutorial success if (stagetime < maxtime - 3) { switch (stage) { case 3: - if (Game::deltah || Game::deltav) + if (Game::deltah || Game::deltav) { success += multiplier; + } break; case 4: - if (Person::players[0]->forwardkeydown || Person::players[0]->backkeydown || Person::players[0]->leftkeydown || Person::players[0]->rightkeydown) + if (Person::players[0]->forwardkeydown || Person::players[0]->backkeydown || Person::players[0]->leftkeydown || Person::players[0]->rightkeydown) { success += multiplier; + } break; case 5: - if (Person::players[0]->jumpkeydown) + if (Person::players[0]->jumpkeydown) { success = 1; + } break; case 6: - if (Person::players[0]->isCrouch()) + if (Person::players[0]->isCrouch()) { success = 1; + } break; case 7: - if (Person::players[0]->animTarget == rollanim) + if (Person::players[0]->animTarget == rollanim) { success = 1; + } break; case 8: - if (Person::players[0]->animTarget == sneakanim) + if (Person::players[0]->animTarget == sneakanim) { success += multiplier; + } break; case 9: - if (Person::players[0]->animTarget == rabbitrunninganim || Person::players[0]->animTarget == wolfrunninganim) + if (Person::players[0]->animTarget == rabbitrunninganim || Person::players[0]->animTarget == wolfrunninganim) { success += multiplier; + } break; case 11: - if (Person::players[0]->isWallJump()) + if (Person::players[0]->isWallJump()) { success = 1; + } break; case 12: - if (Person::players[0]->animTarget == flipanim) + if (Person::players[0]->animTarget == flipanim) { success = 1; + } break; case 15: - if (Person::players[0]->animTarget == upunchanim || Person::players[0]->animTarget == winduppunchanim) + if (Person::players[0]->animTarget == upunchanim || Person::players[0]->animTarget == winduppunchanim) { success = 1; + } break; case 16: - if (Person::players[0]->animTarget == winduppunchanim) + if (Person::players[0]->animTarget == winduppunchanim) { success = 1; + } break; case 17: - if (Person::players[0]->animTarget == spinkickanim) + if (Person::players[0]->animTarget == spinkickanim) { success = 1; + } break; case 18: - if (Person::players[0]->animTarget == sweepanim) + if (Person::players[0]->animTarget == sweepanim) { success = 1; + } break; case 19: - if (Person::players[0]->animTarget == dropkickanim) + if (Person::players[0]->animTarget == dropkickanim) { success = 1; + } break; case 20: - if (Person::players[0]->animTarget == rabbitkickanim) + if (Person::players[0]->animTarget == rabbitkickanim) { success = 1; + } break; case 21: - if (bonus == cannon) + if (bonus == cannon) { success = 1; + } break; case 22: - if (bonus == spinecrusher) + if (bonus == spinecrusher) { success = 1; + } break; case 23: - if (Person::players[0]->animTarget == walljumprightkickanim || Person::players[0]->animTarget == walljumpleftkickanim) + if (Person::players[0]->animTarget == walljumprightkickanim || Person::players[0]->animTarget == walljumpleftkickanim) { success = 1; + } break; case 24: - if (Person::players[0]->animTarget == rabbittacklinganim) + if (Person::players[0]->animTarget == rabbittacklinganim) { success = 1; + } break; case 25: - if (Person::players[0]->animTarget == backhandspringanim) + if (Person::players[0]->animTarget == backhandspringanim) { success = 1; + } break; case 28: - if (Animation::animations[Person::players[0]->animTarget].attack == reversed && Person::players[0]->feint) + if (Animation::animations[Person::players[0]->animTarget].attack == reversed && Person::players[0]->feint) { success = 1; + } break; case 29: if (Person::players[0]->escapednum == 2) { @@ -809,14 +841,18 @@ void Tutorial::DoStuff(float multiplier) for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) { if (Random() % 2 == 0) { - if (!Person::players[1]->skeleton.free) + if (!Person::players[1]->skeleton.free) { temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2; - if (Person::players[1]->skeleton.free) + } + if (Person::players[1]->skeleton.free) { temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2; - if (!Person::players[1]->skeleton.free) + } + if (!Person::players[1]->skeleton.free) { temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords; - if (Person::players[1]->skeleton.free) + } + if (Person::players[1]->skeleton.free) { temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords; + } Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); } } @@ -825,14 +861,18 @@ void Tutorial::DoStuff(float multiplier) for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) { Person::players[1]->skeleton.joints[i].velocity = 0; if (Random() % 2 == 0) { - if (!Person::players[1]->skeleton.free) + if (!Person::players[1]->skeleton.free) { temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2; - if (Person::players[1]->skeleton.free) + } + if (Person::players[1]->skeleton.free) { temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2; - if (!Person::players[1]->skeleton.free) + } + if (!Person::players[1]->skeleton.free) { temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords; - if (Person::players[1]->skeleton.free) + } + if (Person::players[1]->skeleton.free) { temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords; + } Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); } } diff --git a/Source/User/Account.cpp b/Source/User/Account.cpp index 52f863e..82072fc 100644 --- a/Source/User/Account.cpp +++ b/Source/User/Account.cpp @@ -224,13 +224,16 @@ void Account::winCampaignLevel(int choice, float score, float time) void Account::winLevel(int level, float score, float time) { if (!devtools) { - if (score > highscore[level]) + if (score > highscore[level]) { highscore[level] = score; - if (time < fasttime[level] || fasttime[level] == 0) + } + if (time < fasttime[level] || fasttime[level] == 0) { fasttime[level] = time; + } } - if (progress < level + 1) + if (progress < level + 1) { progress = level + 1; + } } void Account::loadFile(string filename) diff --git a/Source/User/Settings.cpp b/Source/User/Settings.cpp index e3f709e..8b12b62 100644 --- a/Source/User/Settings.cpp +++ b/Source/User/Settings.cpp @@ -70,18 +70,24 @@ void DefaultSettings() void SaveSettings() { - if (newdetail < 0) + if (newdetail < 0) { newdetail = 0; - if (newdetail > 2) + } + if (newdetail > 2) { newdetail = 2; - if (newscreenwidth > 3000) + } + if (newscreenwidth > 3000) { newscreenwidth = screenwidth; - if (newscreenwidth < 0) + } + if (newscreenwidth < 0) { newscreenwidth = screenwidth; - if (newscreenheight > 3000) + } + if (newscreenheight > 3000) { newscreenheight = screenheight; - if (newscreenheight < 0) + } + if (newscreenheight < 0) { newscreenheight = screenheight; + } errno = 0; ofstream opstream(Folders::getConfigFilePath()); if (opstream.fail()) { @@ -121,8 +127,9 @@ void SaveSettings() opstream << "\nInvert mouse:\n"; opstream << invertmouse; opstream << "\nGamespeed:\n"; - if (oldgamespeed == 0) + if (oldgamespeed == 0) { oldgamespeed = 1; + } opstream << oldgamespeed; opstream << "\nDamage effects(blackout, doublevision):\n"; opstream << damageeffects; @@ -187,8 +194,9 @@ bool LoadSettings() // skip blank lines // assume lines starting with spaces are all blank - if (strlen(setting) == 0 || setting[0] == ' ' || setting[0] == '\t') + if (strlen(setting) == 0 || setting[0] == ' ' || setting[0] == '\t') { continue; + } //~ printf("setting : %s\n",setting); if (ipstream.eof() || ipstream.fail()) { @@ -302,14 +310,18 @@ bool LoadSettings() ipstream.close(); - if (detail > 2) + if (detail > 2) { detail = 2; - if (detail < 0) + } + if (detail < 0) { detail = 0; - if (screenwidth < 0) + } + if (screenwidth < 0) { screenwidth = 1024; - if (screenheight < 0) + } + if (screenheight < 0) { screenheight = 768; + } newdetail = detail; return true; diff --git a/Source/Utils/Folders.cpp b/Source/Utils/Folders.cpp index 2bf9bda..751da93 100644 --- a/Source/Utils/Folders.cpp +++ b/Source/Utils/Folders.cpp @@ -106,11 +106,13 @@ std::string Folders::getGenericDirectory(const char* ENVVAR, const std::string& const char* Folders::getHomeDirectory() { const char* homedir = getenv("HOME"); - if (homedir != NULL) + if (homedir != NULL) { return homedir; + } struct passwd* pw = getpwuid(getuid()); - if (pw != NULL) + if (pw != NULL) { return pw->pw_dir; + } return NULL; } #endif diff --git a/Source/Utils/ImageIO.cpp b/Source/Utils/ImageIO.cpp index cff8dd1..124f1b7 100644 --- a/Source/Utils/ImageIO.cpp +++ b/Source/Utils/ImageIO.cpp @@ -163,15 +163,18 @@ static bool load_png(const char* file_name, ImageRec& tex) } png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (png_ptr == NULL) + if (png_ptr == NULL) { goto png_done; + } info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == NULL) + if (info_ptr == NULL) { goto png_done; + } - if (setjmp(png_jmpbuf(png_ptr))) + if (setjmp(png_jmpbuf(png_ptr))) { goto png_done; + } png_init_io(png_ptr, fp); png_read_png(png_ptr, info_ptr, @@ -180,19 +183,23 @@ static bool load_png(const char* file_name, ImageRec& tex) png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL); - if (bit_depth != 8) // transform SHOULD handle this... + if (bit_depth != 8) { // transform SHOULD handle this... goto png_done; + } - if (color_type & PNG_COLOR_MASK_PALETTE) // !!! FIXME? + if (color_type & PNG_COLOR_MASK_PALETTE) { // !!! FIXME? goto png_done; + } - if ((color_type & PNG_COLOR_MASK_COLOR) == 0) // !!! FIXME? + if ((color_type & PNG_COLOR_MASK_COLOR) == 0) { // !!! FIXME? goto png_done; + } hasalpha = ((color_type & PNG_COLOR_MASK_ALPHA) != 0); row_pointers = png_get_rows(png_ptr, info_ptr); - if (!row_pointers) + if (!row_pointers) { goto png_done; + } if (!hasalpha) { png_byte* dst = tex.data; @@ -212,8 +219,9 @@ static bool load_png(const char* file_name, ImageRec& tex) else { png_byte* dst = tex.data; int pitch = width * 4; - for (int i = height - 1; i >= 0; i--, dst += pitch) + for (int i = height - 1; i >= 0; i--, dst += pitch) { memcpy(dst, row_pointers[i], pitch); + } } tex.sizeX = width; @@ -226,8 +234,9 @@ png_done: cerr << "There was a problem loading " << file_name << endl; } png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - if (fp) + if (fp) { fclose(fp); + } return (retval); } @@ -247,33 +256,40 @@ static bool save_screenshot_png(const char* file_name) png_bytep* row_pointers = new png_bytep[kContextHeight]; png_bytep screenshot = new png_byte[kContextWidth * kContextHeight * 3]; - if ((!screenshot) || (!row_pointers)) + if ((!screenshot) || (!row_pointers)) { goto save_png_done; + } glGetError(); glReadPixels(0, 0, kContextWidth, kContextHeight, GL_RGB, GL_UNSIGNED_BYTE, screenshot); - if (glGetError() != GL_NO_ERROR) + if (glGetError() != GL_NO_ERROR) { goto save_png_done; + } - for (int i = 0; i < kContextHeight; i++) + for (int i = 0; i < kContextHeight; i++) { row_pointers[i] = screenshot + ((kContextWidth * ((kContextHeight - 1) - i)) * 3); + } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (png_ptr == NULL) + if (png_ptr == NULL) { goto save_png_done; + } info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == NULL) + if (info_ptr == NULL) { goto save_png_done; + } - if (setjmp(png_jmpbuf(png_ptr))) + if (setjmp(png_jmpbuf(png_ptr))) { goto save_png_done; + } png_init_io(png_ptr, fp); - if (setjmp(png_jmpbuf(png_ptr))) + if (setjmp(png_jmpbuf(png_ptr))) { goto save_png_done; + } png_set_IHDR(png_ptr, info_ptr, kContextWidth, kContextHeight, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, @@ -281,13 +297,15 @@ static bool save_screenshot_png(const char* file_name) png_write_info(png_ptr, info_ptr); - if (setjmp(png_jmpbuf(png_ptr))) + if (setjmp(png_jmpbuf(png_ptr))) { goto save_png_done; + } png_write_image(png_ptr, row_pointers); - if (setjmp(png_jmpbuf(png_ptr))) + if (setjmp(png_jmpbuf(png_ptr))) { goto save_png_done; + } png_write_end(png_ptr, NULL); retval = true; @@ -296,9 +314,11 @@ save_png_done: png_destroy_write_struct(&png_ptr, &info_ptr); delete[] screenshot; delete[] row_pointers; - if (fp) + if (fp) { fclose(fp); - if (!retval) + } + if (!retval) { unlink(file_name); + } return retval; } diff --git a/Source/main.cpp b/Source/main.cpp index 169809a..3e37f64 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -154,8 +154,9 @@ SDL_bool sdlEventProc(const SDL_Event& e) if ((e.key.keysym.scancode == SDL_SCANCODE_G) && (e.key.keysym.mod & KMOD_CTRL)) { SDL_bool mode = SDL_TRUE; - if ((SDL_GetWindowFlags(sdlwindow) & SDL_WINDOW_FULLSCREEN) == 0) + if ((SDL_GetWindowFlags(sdlwindow) & SDL_WINDOW_FULLSCREEN) == 0) { mode = (SDL_GetWindowGrab(sdlwindow) ? SDL_FALSE : SDL_TRUE); + } SDL_SetWindowGrab(sdlwindow, mode); SDL_SetRelativeMouseMode(mode); } else if ((e.key.keysym.scancode == SDL_SCANCODE_RETURN) && (e.key.keysym.mod & KMOD_ALT)) { @@ -181,11 +182,12 @@ bool SetUp() DefaultSettings(); - if (!SDL_WasInit(SDL_INIT_VIDEO)) + if (!SDL_WasInit(SDL_INIT_VIDEO)) { if (SDL_Init(SDL_INIT_VIDEO) == -1) { fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); return false; } + } if (!LoadSettings()) { fprintf(stderr, "Failed to load config, creating default\n"); SaveSettings(); @@ -200,10 +202,12 @@ bool SetUp() for (int displayIdx = 0; displayIdx < SDL_GetNumVideoDisplays(); ++displayIdx) { for (int i = 0; i < SDL_GetNumDisplayModes(displayIdx); ++i) { SDL_DisplayMode mode; - if (SDL_GetDisplayMode(displayIdx, i, &mode) == -1) + if (SDL_GetDisplayMode(displayIdx, i, &mode) == -1) { continue; - if ((mode.w < 640) || (mode.h < 480)) + } + if ((mode.w < 640) || (mode.h < 480)) { continue; // sane lower limit. + } pair resolution(mode.w, mode.h); resolutions.insert(resolution); } @@ -278,8 +282,9 @@ bool SetUp() return false; } - if (SDL_GL_SetSwapInterval(-1) == -1) // try swap_tear first. + if (SDL_GL_SetSwapInterval(-1) == -1) { // try swap_tear first. SDL_GL_SetSwapInterval(1); + } SDL_ShowCursor(0); if (!commandLineOptions[NOMOUSEGRAB].last()->type()) { @@ -318,14 +323,16 @@ static void DoMouse() deltav *= usermousesensitivity; mousecoordh += deltah; mousecoordv += deltav; - if (mousecoordh < 0) + if (mousecoordh < 0) { mousecoordh = 0; - else if (mousecoordh >= kContextWidth) + } else if (mousecoordh >= kContextWidth) { mousecoordh = kContextWidth - 1; - if (mousecoordv < 0) + } + if (mousecoordv < 0) { mousecoordv = 0; - else if (mousecoordv >= kContextHeight) + } else if (mousecoordv >= kContextHeight) { mousecoordv = kContextHeight - 1; + } } } @@ -338,25 +345,30 @@ void DoFrameRate(int update) AbsoluteTime currTime = UpTime(); double deltaTime = (float)AbsoluteDeltaToDuration(currTime, frametime); - if (0 > deltaTime) // if negative microseconds + if (0 > deltaTime) { // if negative microseconds deltaTime /= -1000000.0; - else // else milliseconds + } else { // else milliseconds deltaTime /= 1000.0; + } multiplier = deltaTime; - if (multiplier < .001) + if (multiplier < .001) { multiplier = .001; - if (multiplier > 10) + } + if (multiplier > 10) { multiplier = 10; - if (update) + } + if (update) { frametime = currTime; // reset for next time interval + } deltaTime = (float)AbsoluteDeltaToDuration(currTime, time); - if (0 > deltaTime) // if negative microseconds + if (0 > deltaTime) { // if negative microseconds deltaTime /= -1000000.0; - else // else milliseconds + } else { // else milliseconds deltaTime /= 1000.0; + } frames++; if (0.001 <= deltaTime) { // has update interval passed if (update) { @@ -373,26 +385,32 @@ void DoUpdate() static float oldmult; DoFrameRate(1); - if (multiplier > .6) + if (multiplier > .6) { multiplier = .6; + } fps = 1 / multiplier; count = multiplier * sps; - if (count < 2) + if (count < 2) { count = 2; + } realmultiplier = multiplier; multiplier *= gamespeed; - if (difficulty == 1) + if (difficulty == 1) { multiplier *= .9; - if (difficulty == 0) + } + if (difficulty == 0) { multiplier *= .8; + } - if (loading == 4) + if (loading == 4) { multiplier *= .00001; - if (slomo && !mainmenu) + } + if (slomo && !mainmenu) { multiplier *= slomospeed; + } oldmult = multiplier; multiplier /= (float)count; @@ -478,15 +496,16 @@ static char* findBinaryInPath(const char* bin, char* envr) do { size_t size; ptr = strchr(start, ':'); /* find next $PATH separator. */ - if (ptr) + if (ptr) { *ptr = '\0'; - + } size = strlen(start) + strlen(bin) + 2; if (size > alloc_size) { char* x = (char*)realloc(exe, size); if (x == NULL) { - if (exe != NULL) + if (exe != NULL) { free(exe); + } return (NULL); } /* if */ @@ -496,8 +515,9 @@ static char* findBinaryInPath(const char* bin, char* envr) /* build full binary path... */ strcpy(exe, start); - if ((exe[0] == '\0') || (exe[strlen(exe) - 1] != '/')) + if ((exe[0] == '\0') || (exe[strlen(exe) - 1] != '/')) { strcat(exe, "/"); + } strcat(exe, bin); if (access(exe, X_OK) == 0) { /* Exists as executable? We're done. */ @@ -508,8 +528,9 @@ static char* findBinaryInPath(const char* bin, char* envr) start = ptr + 1; /* start points to beginning of next element. */ } while (ptr != NULL); - if (exe != NULL) + if (exe != NULL) { free(exe); + } return (NULL); /* doesn't exist in path. */ } /* findBinaryInPath */ @@ -522,17 +543,20 @@ char* calcBaseDir(const char* argv0) if (strchr(argv0, '/')) { retval = strdup(argv0); - if (retval) + if (retval) { *((char*)strrchr(retval, '/')) = '\0'; + } return (retval); } envr = getenv("PATH"); - if (!envr) + if (!envr) { return NULL; + } envr = strdup(envr); - if (!envr) + if (!envr) { return NULL; + } retval = findBinaryInPath(argv0, envr); free(envr); return (retval);