From 8b6e8f3ad7390309795eb35c0959264cb7924402 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Tue, 10 Jan 2017 00:50:38 +0100 Subject: [PATCH] Applied clang-format on all files --- Source/Animation/Animation.cpp | 22 +- Source/Animation/Joint.cpp | 28 +- Source/Animation/Muscle.cpp | 36 +- Source/Animation/Skeleton.cpp | 245 +++--- Source/Audio/Sounds.cpp | 56 +- Source/Audio/openal_wrapper.cpp | 135 ++-- Source/Devtools/ConsoleCmds.cpp | 159 ++-- Source/Environment/Lights.cpp | 43 +- Source/Environment/Skybox.cpp | 84 +-- Source/Environment/Terrain.cpp | 53 +- Source/Game.cpp | 78 +- Source/GameDraw.cpp | 209 +++--- Source/GameInitDispose.cpp | 50 +- Source/GameTick.cpp | 1239 +++++++++++++++---------------- Source/Globals.cpp | 18 +- Source/Graphic/Decal.cpp | 49 +- Source/Graphic/Models.cpp | 74 +- Source/Graphic/Sprite.cpp | 200 ++--- Source/Graphic/Stereo.cpp | 200 +++-- Source/Graphic/Text.cpp | 35 +- Source/Graphic/Texture.cpp | 22 +- Source/Level/Awards.cpp | 11 +- Source/Level/Campaign.cpp | 31 +- Source/Level/Dialog.cpp | 22 +- Source/Level/Hotspot.cpp | 16 +- Source/MacCompatibility.cpp | 34 +- Source/Math/Frustum.cpp | 10 +- Source/Math/XYZ.cpp | 80 +- Source/Menu/Menu.cpp | 1206 +++++++++++++++--------------- Source/Objects/Object.cpp | 119 +-- Source/Objects/Person.cpp | 1183 +++++++++++++++-------------- Source/Objects/Weapons.cpp | 94 ++- Source/Tutorial.cpp | 38 +- Source/User/Account.cpp | 39 +- Source/User/Settings.cpp | 91 ++- Source/Utils/Folders.cpp | 16 +- Source/Utils/ImageIO.cpp | 69 +- Source/Utils/Input.cpp | 2 +- Source/WinDefs.cpp | 15 +- Source/main.cpp | 211 +++--- 40 files changed, 3164 insertions(+), 3158 deletions(-) diff --git a/Source/Animation/Animation.cpp b/Source/Animation/Animation.cpp index 8ee1fd6..a8ad6e1 100644 --- a/Source/Animation/Animation.cpp +++ b/Source/Animation/Animation.cpp @@ -27,7 +27,9 @@ std::vector Animation::animations; void Animation::loadAll() { -#define DECLARE_ANIM(id, file, height, attack, ...) if (id < loadable_anim_end) animations.emplace_back(file, height, attack); +#define DECLARE_ANIM(id, file, height, attack, ...) \ + if (id < loadable_anim_end) \ + animations.emplace_back(file, height, attack); #include "Animation.def" #undef DECLARE_ANIM } @@ -70,27 +72,27 @@ void AnimationFrame::loadWeaponTarget(FILE* tfile) funpackf(tfile, "Bf Bf Bf", &weapontarget.x, &weapontarget.y, &weapontarget.z); } -Animation::Animation(): - height(lowheight), - attack(neutral), - numjoints(0) +Animation::Animation() + : height(lowheight) + , attack(neutral) + , numjoints(0) { } /* EFFECT * load an animation from file */ -Animation::Animation(const std::string& filename, anim_height_type aheight, anim_attack_type aattack): - Animation() +Animation::Animation(const std::string& filename, anim_height_type aheight, anim_attack_type aattack) + : Animation() { - FILE *tfile; + FILE* tfile; int numframes; unsigned i; LOGFUNC; // Changing the filename into something the OS can understand - std::string filepath = Folders::getResourcePath("Animations/"+filename); + std::string filepath = Folders::getResourcePath("Animations/" + filename); LOG(std::string("Loading animation...") + filepath); @@ -100,7 +102,7 @@ Animation::Animation(const std::string& filename, anim_height_type aheight, anim Game::LoadingScreen(); // read file in binary mode - tfile = Folders::openMandatoryFile( filepath, "rb" ); + tfile = Folders::openMandatoryFile(filepath, "rb"); // read numframes, joints to know how much memory to allocate funpackf(tfile, "Bi Bi", &numframes, &numjoints); diff --git a/Source/Animation/Joint.cpp b/Source/Animation/Joint.cpp index f615bfe..8d7caf9 100644 --- a/Source/Animation/Joint.cpp +++ b/Source/Animation/Joint.cpp @@ -22,20 +22,20 @@ along with Lugaru. If not, see . #include "Utils/binio.h" -Joint::Joint() : - blurred(0), - length(0), - mass(0), - lower(false), - hasparent(false), - locked(false), - modelnum(0), - visible(false), - parent(nullptr), - sametwist(false), - label(head), - hasgun(0), - delay(0) +Joint::Joint() + : blurred(0) + , length(0) + , mass(0) + , lower(false) + , hasparent(false) + , locked(false) + , modelnum(0) + , visible(false) + , parent(nullptr) + , sametwist(false) + , label(head) + , hasgun(0) + , delay(0) { } diff --git a/Source/Animation/Muscle.cpp b/Source/Animation/Muscle.cpp index 6ccad18..da43de4 100644 --- a/Source/Animation/Muscle.cpp +++ b/Source/Animation/Muscle.cpp @@ -25,19 +25,28 @@ along with Lugaru. If not, see . extern float multiplier; extern bool freeze; -Muscle::Muscle() : - length(0), - targetlength(0), - parent1(0), - parent2(0), - maxlength(0), - minlength(0), - type(boneconnect), - visible(false), - rotate1(0), rotate2(0), rotate3(0), - lastrotate1(0), lastrotate2(0), lastrotate3(0), - oldrotate1(0), oldrotate2(0), oldrotate3(0), - newrotate1(0), newrotate2(0), newrotate3(0), +Muscle::Muscle() + : length(0) + , targetlength(0) + , parent1(0) + , parent2(0) + , maxlength(0) + , minlength(0) + , type(boneconnect) + , visible(false) + , rotate1(0) + , rotate2(0) + , rotate3(0) + , lastrotate1(0) + , lastrotate2(0) + , lastrotate3(0) + , oldrotate1(0) + , oldrotate2(0) + , oldrotate3(0) + , newrotate1(0) + , newrotate2(0) + , newrotate3(0) + , strength(0) { @@ -97,7 +106,6 @@ void Muscle::loadVerticesClothes(FILE* tfile, int vertexNum) } } - /* EFFECT * sets strength, length, * parent1->position, parent2->position, diff --git a/Source/Animation/Skeleton.cpp b/Source/Animation/Skeleton.cpp index 19150fb..b665625 100644 --- a/Source/Animation/Skeleton.cpp +++ b/Source/Animation/Skeleton.cpp @@ -23,8 +23,8 @@ along with Lugaru. If not, see . #include "Animation/Animation.hpp" #include "Audio/openal_wrapper.hpp" #include "Game.hpp" -#include "Utils/Folders.hpp" #include "Tutorial.hpp" +#include "Utils/Folders.hpp" extern float multiplier; extern float gravity; @@ -37,20 +37,20 @@ extern int detail; extern int whichjointstartarray[26]; extern int whichjointendarray[26]; -Skeleton::Skeleton() : - selected(0), - id(0), - num_models(0), - clothes(false), - spinny(false), - skinsize(0), - checkdelay(0), - longdead(0), - broken(false), - free(0), - oldfree(0), - freetime(0), - freefall(false) +Skeleton::Skeleton() + : selected(0) + , id(0) + , num_models(0) + , clothes(false) + , spinny(false) + , skinsize(0) + , checkdelay(0) + , longdead(0) + , broken(false) + , free(0) + , oldfree(0) + , freetime(0) + , freefall(false) { memset(forwardjoints, 0, sizeof(forwardjoints)); memset(lowforwardjoints, 0, sizeof(lowforwardjoints)); @@ -105,7 +105,7 @@ void Skeleton::FindForwards() * Person/Person::DoStuff * Person/IKHelper */ -float Skeleton::DoConstraints(XYZ *coords, float *scale) +float Skeleton::DoConstraints(XYZ* coords, float* scale) { const float elasticity = .3; XYZ bounceness; @@ -136,20 +136,20 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) joints[i].position = joints[i].position + joints[i].velocity * multiplier; switch (joints[i].label) { - case head: - groundlevel = .8; - break; - case righthand: - case rightwrist: - case rightelbow: - case lefthand: - case leftwrist: - case leftelbow: - groundlevel = .2; - break; - default: - groundlevel = .15; - break; + case head: + groundlevel = .8; + break; + case righthand: + case rightwrist: + case rightelbow: + case lefthand: + case leftwrist: + case leftelbow: + groundlevel = .2; + break; + default: + groundlevel = .15; + break; } joints[i].position.y -= groundlevel; @@ -294,7 +294,6 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) joints[i].velocity = joints[i].oldvelocity; } - if (joints[i].locked == 0) if (findLengthfast(&joints[i].velocity) < 1) joints[i].locked = 1; @@ -315,7 +314,6 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) } 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) broken = 1; @@ -386,7 +384,6 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) } joints[i].velocity += bounceness * elasticity; - if (!joints[i].locked) if (findLengthfast(&joints[i].velocity) < 1) { joints[i].locked = 1; @@ -405,7 +402,6 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) } multiplier = tempmult; - for (unsigned int m = 0; m < terrain.patchobjects[whichpatchx][whichpatchz].size(); m++) { unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m]; if (Object::objects[k]->possible) { @@ -427,20 +423,20 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) for (i = 0; i < joints.size(); i++) { switch (joints[i].label) { - case head: - groundlevel = .8; - break; - case righthand: - case rightwrist: - case rightelbow: - case lefthand: - case leftwrist: - case leftelbow: - groundlevel = .2; - break; - default: - groundlevel = .15; - break; + case head: + groundlevel = .8; + break; + case righthand: + case rightwrist: + case rightelbow: + case lefthand: + case leftwrist: + case leftelbow: + groundlevel = .2; + break; + default: + groundlevel = .15; + break; } joints[i].position.y += groundlevel; joints[i].mass = 1; @@ -470,19 +466,16 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) * USES: * Person/Person::DoStuff */ -void Skeleton::DoGravity(float *scale) +void Skeleton::DoGravity(float* scale) { for (unsigned i = 0; i < joints.size(); i++) { if ( - ( - ((joints[i].label != leftknee) && (joints[i].label != rightknee)) || - (lowforward.y > -.1) || - (joints[i].mass < 5) - ) && ( - ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) || - (forward.y < .3) - ) - ) { + ( + ((joints[i].label != leftknee) && (joints[i].label != rightknee)) || + (lowforward.y > -.1) || + (joints[i].mass < 5)) && + (((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) || + (forward.y < .3))) { joints[i].velocity.y += gravity * multiplier / (*scale); } } @@ -527,39 +520,39 @@ void Skeleton::FindRotationMuscle(int which, int animation) const int label1 = muscles[which].parent1->label; const int label2 = muscles[which].parent2->label; switch (label1) { - case head: - fwd = specialforward[0]; - break; - case rightshoulder: - case rightelbow: - case rightwrist: - case righthand: - fwd = specialforward[1]; - break; - case leftshoulder: - case leftelbow: - case leftwrist: - case lefthand: - fwd = specialforward[2]; - break; - case righthip: - case rightknee: - case rightankle: - case rightfoot: - fwd = specialforward[3]; - break; - case lefthip: - case leftknee: - case leftankle: - case leftfoot: - fwd = specialforward[4]; - break; - default: - if (muscles[which].parent1->lower) - fwd = lowforward; - else - fwd = forward; - break; + case head: + fwd = specialforward[0]; + break; + case rightshoulder: + case rightelbow: + case rightwrist: + case righthand: + fwd = specialforward[1]; + break; + case leftshoulder: + case leftelbow: + case leftwrist: + case lefthand: + fwd = specialforward[2]; + break; + case righthip: + case rightknee: + case rightankle: + case rightfoot: + fwd = specialforward[3]; + break; + case lefthip: + case leftknee: + case leftankle: + case leftfoot: + fwd = specialforward[4]; + break; + default: + if (muscles[which].parent1->lower) + fwd = lowforward; + else + fwd = forward; + break; } if (animation == hanganim) { @@ -601,15 +594,15 @@ void Skeleton::FindRotationMuscle(int which, int animation) * load skeleton * takes filenames for three skeleton files and various models */ -void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename, - const std::string& modelfilename, const std::string& model2filename, +void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename, + const std::string& modelfilename, const std::string& model2filename, const std::string& model3filename, const std::string& model4filename, const std::string& model5filename, const std::string& model6filename, const std::string& model7filename, const std::string& modellowfilename, const std::string& modelclothesfilename, bool clothes) { GLfloat M[16]; - FILE *tfile; + FILE* tfile; float lSize; int j, num_joints, num_muscles; @@ -677,7 +670,7 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil // load skeleton - tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" ); + tfile = Folders::openMandatoryFile(Folders::getResourcePath(filename), "rb"); // read num_joints funpackf(tfile, "Bi", &num_joints); @@ -748,24 +741,18 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil // load ??? - tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" ); + tfile = Folders::openMandatoryFile(Folders::getResourcePath(lowfilename), "rb"); // skip joints section fseek(tfile, sizeof(num_joints), SEEK_CUR); for (int i = 0; i < num_joints; i++) { // skip joint info - lSize = sizeof(XYZ) - + sizeof(float) - + sizeof(float) - + 1 //sizeof(bool) - + 1 //sizeof(bool) - + sizeof(int) - + 1 //sizeof(bool) - + 1 //sizeof(bool) - + sizeof(int) - + sizeof(int) - + 1 //sizeof(bool) + lSize = sizeof(XYZ) + sizeof(float) + sizeof(float) + 1 //sizeof(bool) + + 1 //sizeof(bool) + + sizeof(int) + 1 //sizeof(bool) + + 1 //sizeof(bool) + + sizeof(int) + sizeof(int) + 1 //sizeof(bool) + sizeof(int); fseek(tfile, lSize, SEEK_CUR); } @@ -775,22 +762,17 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil for (int i = 0; i < num_muscles; i++) { // skip muscle info - lSize = sizeof(float) - + sizeof(float) - + sizeof(float) - + sizeof(float) - + sizeof(float) - + sizeof(int); + lSize = sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(int); fseek(tfile, lSize, SEEK_CUR); muscles[i].loadVerticesLow(tfile, modellow.vertexNum); // skip more stuff lSize = 1; //sizeof(bool); - fseek ( tfile, lSize, SEEK_CUR); + fseek(tfile, lSize, SEEK_CUR); lSize = sizeof(int); - fseek ( tfile, lSize, SEEK_CUR); - fseek ( tfile, lSize, SEEK_CUR); + fseek(tfile, lSize, SEEK_CUR); + fseek(tfile, lSize, SEEK_CUR); } for (j = 0; j < num_muscles; j++) { @@ -823,24 +805,18 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil // load clothes if (clothes) { - tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" ); + tfile = Folders::openMandatoryFile(Folders::getResourcePath(clothesfilename), "rb"); // skip num_joints fseek(tfile, sizeof(num_joints), SEEK_CUR); for (int i = 0; i < num_joints; i++) { // skip joint info - lSize = sizeof(XYZ) - + sizeof(float) - + sizeof(float) - + 1 //sizeof(bool) - + 1 //sizeof(bool) - + sizeof(int) - + 1 //sizeof(bool) - + 1 //sizeof(bool) - + sizeof(int) - + sizeof(int) - + 1 //sizeof(bool) + lSize = sizeof(XYZ) + sizeof(float) + sizeof(float) + 1 //sizeof(bool) + + 1 //sizeof(bool) + + sizeof(int) + 1 //sizeof(bool) + + 1 //sizeof(bool) + + sizeof(int) + sizeof(int) + 1 //sizeof(bool) + sizeof(int); fseek(tfile, lSize, SEEK_CUR); } @@ -850,22 +826,17 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil for (int i = 0; i < num_muscles; i++) { // skip muscle info - lSize = sizeof(float) - + sizeof(float) - + sizeof(float) - + sizeof(float) - + sizeof(float) - + sizeof(int); + lSize = sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(int); fseek(tfile, lSize, SEEK_CUR); muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum); // skip more stuff lSize = 1; //sizeof(bool); - fseek ( tfile, lSize, SEEK_CUR); + fseek(tfile, lSize, SEEK_CUR); lSize = sizeof(int); - fseek ( tfile, lSize, SEEK_CUR); - fseek ( tfile, lSize, SEEK_CUR); + fseek(tfile, lSize, SEEK_CUR); + fseek(tfile, lSize, SEEK_CUR); } // ??? diff --git a/Source/Audio/Sounds.cpp b/Source/Audio/Sounds.cpp index 94989a1..a259864 100644 --- a/Source/Audio/Sounds.cpp +++ b/Source/Audio/Sounds.cpp @@ -22,7 +22,7 @@ along with Lugaru. If not, see . #include "Audio/openal_wrapper.hpp" #include "Utils/Folders.hpp" -struct OPENAL_SAMPLE *samp[sounds_count]; +struct OPENAL_SAMPLE* samp[sounds_count]; extern XYZ envsound[30]; extern float envsoundvol[30]; @@ -33,7 +33,7 @@ int footstepsound, footstepsound2, footstepsound3, footstepsound4; int channels[100]; -static const char *sound_data[sounds_count] = { +static const char* sound_data[sounds_count] = { #define DECLARE_SOUND(id, filename) filename, #include "Sounds.def" #undef DECLARE_SOUND @@ -44,14 +44,14 @@ static const char *sound_data[sounds_count] = { static int snd_mode(int snd) { switch (snd) { - case alarmsound: - case consolefailsound: - case consolesuccesssound: - case firestartsound: - case fireendsound: - return OPENAL_2D; - default: - return OPENAL_HW3D; + case alarmsound: + case consolefailsound: + case consolesuccesssound: + case firestartsound: + case fireendsound: + return OPENAL_2D; + default: + return OPENAL_HW3D; } } @@ -82,42 +82,42 @@ void addEnvSound(XYZ coords, float vol, float life) numenvsounds++; } -void emit_sound_at(int soundid, const XYZ &pos, float vol) +void emit_sound_at(int soundid, const XYZ& pos, float vol) { - PlaySoundEx (soundid, samp[soundid], NULL, true); - OPENAL_3D_SetAttributes_ (channels[soundid], pos); - OPENAL_SetVolume (channels[soundid], vol); - OPENAL_SetPaused (channels[soundid], false); + PlaySoundEx(soundid, samp[soundid], NULL, true); + OPENAL_3D_SetAttributes_(channels[soundid], pos); + OPENAL_SetVolume(channels[soundid], vol); + OPENAL_SetPaused(channels[soundid], false); } void emit_sound_np(int soundid, float vol) { - PlaySoundEx (soundid, samp[soundid], NULL, true); - OPENAL_SetVolume (channels[soundid], vol); - OPENAL_SetPaused (channels[soundid], false); + PlaySoundEx(soundid, samp[soundid], NULL, true); + OPENAL_SetVolume(channels[soundid], vol); + OPENAL_SetPaused(channels[soundid], false); } -void emit_stream_at(int soundid, const XYZ &pos, float vol) +void emit_stream_at(int soundid, const XYZ& pos, float vol) { - PlayStreamEx (soundid, samp[soundid], NULL, true); - OPENAL_3D_SetAttributes_ (channels[soundid], pos); - OPENAL_SetVolume (channels[soundid], vol); - OPENAL_SetPaused (channels[soundid], false); + PlayStreamEx(soundid, samp[soundid], NULL, true); + OPENAL_3D_SetAttributes_(channels[soundid], pos); + OPENAL_SetVolume(channels[soundid], vol); + OPENAL_SetPaused(channels[soundid], false); } void emit_stream_np(int soundid, float vol) { - PlayStreamEx (soundid, samp[soundid], NULL, true); - OPENAL_SetVolume (channels[soundid], vol); - OPENAL_SetPaused (channels[soundid], false); + PlayStreamEx(soundid, samp[soundid], NULL, true); + OPENAL_SetVolume(channels[soundid], vol); + OPENAL_SetPaused(channels[soundid], false); } void resume_stream(int soundid) { - OPENAL_SetPaused (channels[soundid], false); + OPENAL_SetPaused(channels[soundid], false); } void pause_sound(int soundid) { - OPENAL_SetPaused (channels[soundid], true); + OPENAL_SetPaused(channels[soundid], true); } diff --git a/Source/Audio/openal_wrapper.cpp b/Source/Audio/openal_wrapper.cpp index e8203af..d728e5a 100644 --- a/Source/Audio/openal_wrapper.cpp +++ b/Source/Audio/openal_wrapper.cpp @@ -34,35 +34,37 @@ extern float slomofreq; // FMOD uses a Left Handed Coordinate system, OpenAL uses a Right Handed // one...so we just need to flip the sign on the Z axis when appropriate. -typedef struct { +typedef struct +{ ALuint sid; - OPENAL_SAMPLE *sample; + OPENAL_SAMPLE* sample; bool startpaused; float position[3]; } OPENAL_Channels; -typedef struct OPENAL_SAMPLE { - char *name; - ALuint bid; // buffer id. +typedef struct OPENAL_SAMPLE +{ + char* name; + ALuint bid; // buffer id. int mode; int is2d; } OPENAL_SAMPLE; static size_t num_channels = 0; -static OPENAL_Channels *impl_channels = NULL; +static OPENAL_Channels* impl_channels = NULL; static bool initialized = false; static float listener_position[3]; static void set_channel_position(const int channel, const float x, const float y, const float z) { - OPENAL_Channels *chan = &impl_channels[channel]; + OPENAL_Channels* chan = &impl_channels[channel]; chan->position[0] = x; chan->position[1] = y; chan->position[2] = z; - OPENAL_SAMPLE *sptr = chan->sample; + OPENAL_SAMPLE* sptr = chan->sample; if (sptr == NULL) return; @@ -78,8 +80,7 @@ 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) +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) return; @@ -97,12 +98,12 @@ AL_API void OPENAL_3D_Listener_SetAttributes(const float *pos, const float *, fl // adjust existing positions... for (unsigned i = 0; i < num_channels; i++) { - const float *p = impl_channels[i].position; + const float* p = impl_channels[i].position; set_channel_position(i, p[0], p[1], p[2]); } } -AL_API signed char OPENAL_3D_SetAttributes(int channel, const float *pos) +AL_API signed char OPENAL_3D_SetAttributes(int channel, const float* pos) { if (!initialized) return false; @@ -117,7 +118,7 @@ AL_API signed char OPENAL_3D_SetAttributes(int channel, const float *pos) return true; } -AL_API signed char OPENAL_3D_SetAttributes_(int channel, const XYZ &pos) +AL_API signed char OPENAL_3D_SetAttributes_(int channel, const XYZ& pos) { if (!initialized) return false; @@ -136,15 +137,15 @@ AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned in if (maxsoftwarechannels == 0) return false; - if (flags != 0) // unsupported. + if (flags != 0) // unsupported. return false; - ALCdevice *dev = alcOpenDevice(NULL); + ALCdevice* dev = alcOpenDevice(NULL); if (!dev) return false; ALint caps[] = { ALC_FREQUENCY, mixrate, 0 }; - ALCcontext *ctx = alcCreateContext(dev, caps); + ALCcontext* ctx = alcCreateContext(dev, caps); if (!ctx) { alcCloseDevice(dev); return false; @@ -154,17 +155,17 @@ AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned in alcProcessContext(ctx); if (commandLineOptions[OPENALINFO]) { - printf("AL_VENDOR: %s\n", (char *) alGetString(AL_VENDOR)); - printf("AL_RENDERER: %s\n", (char *) alGetString(AL_RENDERER)); - printf("AL_VERSION: %s\n", (char *) alGetString(AL_VERSION)); - printf("AL_EXTENSIONS: %s\n", (char *) alGetString(AL_EXTENSIONS)); + printf("AL_VENDOR: %s\n", (char*)alGetString(AL_VENDOR)); + printf("AL_RENDERER: %s\n", (char*)alGetString(AL_RENDERER)); + printf("AL_VERSION: %s\n", (char*)alGetString(AL_VERSION)); + printf("AL_EXTENSIONS: %s\n", (char*)alGetString(AL_EXTENSIONS)); } num_channels = maxsoftwarechannels; impl_channels = new OPENAL_Channels[maxsoftwarechannels]; - memset(impl_channels, '\0', sizeof (OPENAL_Channels) * num_channels); + memset(impl_channels, '\0', sizeof(OPENAL_Channels) * num_channels); for (unsigned i = 0; i < num_channels; i++) - alGenSources(1, &impl_channels[i].sid); // !!! FIXME: verify this didn't fail! + alGenSources(1, &impl_channels[i].sid); // !!! FIXME: verify this didn't fail! initialized = true; return true; @@ -175,14 +176,14 @@ AL_API void OPENAL_Close() if (!initialized) return; - ALCcontext *ctx = alcGetCurrentContext(); + ALCcontext* ctx = alcGetCurrentContext(); if (ctx) { for (unsigned i = 0; i < num_channels; i++) { alSourceStop(impl_channels[i].sid); alSourcei(impl_channels[i].sid, AL_BUFFER, 0); alDeleteSources(1, &impl_channels[i].sid); } - ALCdevice *dev = alcGetContextsDevice(ctx); + ALCdevice* dev = alcGetContextsDevice(ctx); alcMakeContextCurrent(NULL); alcSuspendContext(ctx); alcDestroyContext(ctx); @@ -196,7 +197,7 @@ AL_API void OPENAL_Close() initialized = false; } -static OPENAL_SAMPLE *OPENAL_GetCurrentSample(int channel) +static OPENAL_SAMPLE* OPENAL_GetCurrentSample(int channel) { if (!initialized) return NULL; @@ -212,11 +213,11 @@ static signed char OPENAL_GetPaused(int channel) if ((channel < 0) || (channel >= (int)num_channels)) return false; if (impl_channels[channel].startpaused) - return(true); + return (true); ALint state = 0; alGetSourceiv(impl_channels[channel].sid, AL_SOURCE_STATE, &state); - return((state == AL_PAUSED) ? true : false); + return ((state == AL_PAUSED) ? true : false); } static unsigned int OPENAL_GetLoopMode(int channel) @@ -228,7 +229,7 @@ static unsigned int OPENAL_GetLoopMode(int channel) ALint loop = 0; alGetSourceiv(impl_channels[channel].sid, AL_LOOPING, &loop); if (loop) - return(OPENAL_LOOP_NORMAL); + return (OPENAL_LOOP_NORMAL); return OPENAL_LOOP_OFF; } @@ -240,10 +241,10 @@ static signed char OPENAL_IsPlaying(int channel) return false; ALint state = 0; alGetSourceiv(impl_channels[channel].sid, AL_SOURCE_STATE, &state); - return((state == AL_PLAYING) ? true : false); + return ((state == AL_PLAYING) ? true : false); } -static int OPENAL_PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused) +static int OPENAL_PlaySoundEx(int channel, OPENAL_SAMPLE* sptr, OPENAL_DSPUNIT* dsp, signed char startpaused) { if (!initialized) return -1; @@ -276,8 +277,7 @@ static int OPENAL_PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT * return channel; } - -static void *decode_to_pcm(const char *_fname, ALenum &format, ALsizei &size, ALuint &freq) +static void* decode_to_pcm(const char* _fname, ALenum& format, ALsizei& size, ALuint& freq) { #ifdef __POWERPC__ const int bigendian = 1; @@ -286,21 +286,21 @@ static void *decode_to_pcm(const char *_fname, ALenum &format, ALsizei &size, AL #endif // !!! FIXME: if it's not Ogg, we don't have a decoder. I'm lazy. :/ - char *fname = (char *) alloca(strlen(_fname) + 16); + char* fname = (char*)alloca(strlen(_fname) + 16); strcpy(fname, _fname); - char *ptr = strchr(fname, '.'); + char* ptr = strchr(fname, '.'); if (ptr) *ptr = '\0'; strcat(fname, ".ogg"); // just in case... - FILE *io = fopen(fname, "rb"); + FILE* io = fopen(fname, "rb"); if (io == NULL) return NULL; - ALubyte *retval = NULL; + ALubyte* retval = NULL; -#if 0 // untested, so disable this! +#if 0 // untested, so disable this! // Can we just feed it to the AL compressed? if (alIsExtensionPresent((const ALubyte *) "AL_EXT_vorbis")) { format = alGetEnumValue((const ALubyte *) "AL_FORMAT_VORBIS_EXT"); @@ -321,10 +321,10 @@ static void *decode_to_pcm(const char *_fname, ALenum &format, ALsizei &size, AL // Uncompress and feed to the AL. OggVorbis_File vf; - memset(&vf, '\0', sizeof (vf)); + memset(&vf, '\0', sizeof(vf)); if (ov_open(io, &vf, NULL, 0) == 0) { int bitstream = 0; - vorbis_info *info = ov_info(&vf, -1); + vorbis_info* info = ov_info(&vf, -1); size = 0; format = (info->channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; freq = info->rate; @@ -337,13 +337,13 @@ static void *decode_to_pcm(const char *_fname, ALenum &format, ALsizei &size, AL char buf[1024 * 16]; long rc = 0; size_t allocated = 64 * 1024; - retval = (ALubyte *) malloc(allocated); - while ( (rc = ov_read(&vf, buf, sizeof (buf), bigendian, 2, 1, &bitstream)) != 0 ) { + retval = (ALubyte*)malloc(allocated); + while ((rc = ov_read(&vf, buf, sizeof(buf), bigendian, 2, 1, &bitstream)) != 0) { if (rc > 0) { size += rc; if (size >= (int)allocated) { allocated *= 2; - ALubyte *tmp = (ALubyte *) realloc(retval, allocated); + ALubyte* tmp = (ALubyte*)realloc(retval, allocated); if (tmp == NULL) { free(retval); retval = NULL; @@ -362,25 +362,24 @@ static void *decode_to_pcm(const char *_fname, ALenum &format, ALsizei &size, AL return NULL; } - -AL_API OPENAL_SAMPLE *OPENAL_Sample_Load(int index, const char *name_or_data, unsigned int mode, int offset, int length) +AL_API OPENAL_SAMPLE* OPENAL_Sample_Load(int index, const char* name_or_data, unsigned int mode, int offset, int length) { if (!initialized) return NULL; if (index != OPENAL_FREE) - return NULL; // this is all the game does... + return NULL; // this is all the game does... if (offset != 0) - return NULL; // this is all the game does... + return NULL; // this is all the game does... if (length != 0) - return NULL; // this is all the game does... + return NULL; // this is all the game does... if ((mode != OPENAL_HW3D) && (mode != OPENAL_2D)) - return NULL; // this is all the game does... + return NULL; // this is all the game does... - OPENAL_SAMPLE *retval = NULL; + 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); + void* data = decode_to_pcm(name_or_data, format, size, frequency); if (data == NULL) return NULL; @@ -399,10 +398,10 @@ AL_API OPENAL_SAMPLE *OPENAL_Sample_Load(int index, const char *name_or_data, un } free(data); - return(retval); + return (retval); } -AL_API void OPENAL_Sample_Free(OPENAL_SAMPLE *sptr) +AL_API void OPENAL_Sample_Free(OPENAL_SAMPLE* sptr) { if (!initialized) return; @@ -420,7 +419,7 @@ AL_API void OPENAL_Sample_Free(OPENAL_SAMPLE *sptr) } } -static signed char OPENAL_Sample_SetMode(OPENAL_SAMPLE *sptr, unsigned int mode) +static signed char OPENAL_Sample_SetMode(OPENAL_SAMPLE* sptr, unsigned int mode) { if (!initialized) return false; @@ -445,7 +444,7 @@ AL_API signed char OPENAL_SetFrequency(int channel, bool slomo) if ((channel < 0) || (channel >= (int)num_channels)) return false; if (slomo) - alSourcef(impl_channels[channel].sid, AL_PITCH, ((ALfloat) slomofreq) / 44100.0f); + alSourcef(impl_channels[channel].sid, AL_PITCH, ((ALfloat)slomofreq) / 44100.0f); else alSourcef(impl_channels[channel].sid, AL_PITCH, 1.0f); return true; @@ -469,7 +468,7 @@ AL_API signed char OPENAL_SetVolume(int channel, int vol) vol = 0; else if (vol > 255) vol = 255; - ALfloat gain = ((ALfloat) vol) / 255.0f; + ALfloat gain = ((ALfloat)vol) / 255.0f; alSourcef(impl_channels[channel].sid, AL_GAIN, gain); return true; } @@ -507,7 +506,7 @@ AL_API void OPENAL_SetSFXMasterVolume(int volume) { if (!initialized) return; - ALfloat gain = ((ALfloat) volume) / 255.0f; + ALfloat gain = ((ALfloat)volume) / 255.0f; alListenerf(AL_GAIN, gain); } @@ -529,24 +528,24 @@ AL_API signed char OPENAL_StopSound(int channel) return true; } -static OPENAL_SAMPLE *OPENAL_Stream_GetSample(OPENAL_STREAM *stream) +static OPENAL_SAMPLE* OPENAL_Stream_GetSample(OPENAL_STREAM* stream) { if (!initialized) return NULL; - return (OPENAL_SAMPLE *) stream; + return (OPENAL_SAMPLE*)stream; } -static int OPENAL_Stream_PlayEx(int channel, OPENAL_STREAM *stream, OPENAL_DSPUNIT *dsp, signed char startpaused) +static int OPENAL_Stream_PlayEx(int channel, OPENAL_STREAM* stream, OPENAL_DSPUNIT* dsp, signed char startpaused) { - return OPENAL_PlaySoundEx(channel, (OPENAL_SAMPLE *) stream, dsp, startpaused); + return OPENAL_PlaySoundEx(channel, (OPENAL_SAMPLE*)stream, dsp, startpaused); } -static signed char OPENAL_Stream_Stop(OPENAL_STREAM *stream) +static signed char OPENAL_Stream_Stop(OPENAL_STREAM* stream) { if (!initialized) return false; for (unsigned i = 0; i < num_channels; i++) { - if (impl_channels[i].sample == (OPENAL_SAMPLE *) stream) { + if (impl_channels[i].sample == (OPENAL_SAMPLE*)stream) { alSourceStop(impl_channels[i].sid); impl_channels[i].startpaused = false; } @@ -554,9 +553,9 @@ static signed char OPENAL_Stream_Stop(OPENAL_STREAM *stream) return true; } -AL_API signed char OPENAL_Stream_SetMode(OPENAL_STREAM *stream, unsigned int mode) +AL_API signed char OPENAL_Stream_SetMode(OPENAL_STREAM* stream, unsigned int mode) { - return OPENAL_Sample_SetMode((OPENAL_SAMPLE *) stream, mode); + return OPENAL_Sample_SetMode((OPENAL_SAMPLE*)stream, mode); } AL_API void OPENAL_Update() @@ -568,9 +567,9 @@ AL_API void OPENAL_Update() extern int channels[]; -extern "C" void PlaySoundEx(int chan, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused) +extern "C" void PlaySoundEx(int chan, OPENAL_SAMPLE* sptr, OPENAL_DSPUNIT* dsp, signed char startpaused) { - const OPENAL_SAMPLE * currSample = OPENAL_GetCurrentSample(channels[chan]); + const OPENAL_SAMPLE* currSample = OPENAL_GetCurrentSample(channels[chan]); if (currSample && currSample == samp[chan]) { if (OPENAL_GetPaused(channels[chan])) { OPENAL_StopSound(channels[chan]); @@ -591,9 +590,9 @@ extern "C" void PlaySoundEx(int chan, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, } } -extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused) +extern "C" void PlayStreamEx(int chan, OPENAL_STREAM* sptr, OPENAL_DSPUNIT* dsp, signed char startpaused) { - const OPENAL_SAMPLE * currSample = OPENAL_GetCurrentSample(channels[chan]); + const OPENAL_SAMPLE* currSample = OPENAL_GetCurrentSample(channels[chan]); if (currSample && currSample == OPENAL_Stream_GetSample(sptr)) { OPENAL_StopSound(channels[chan]); OPENAL_Stream_Stop(sptr); diff --git a/Source/Devtools/ConsoleCmds.cpp b/Source/Devtools/ConsoleCmds.cpp index f3ac22c..f9a7068 100644 --- a/Source/Devtools/ConsoleCmds.cpp +++ b/Source/Devtools/ConsoleCmds.cpp @@ -23,19 +23,19 @@ along with Lugaru. If not, see . #include "Game.hpp" #include "Level/Dialog.hpp" #include "Level/Hotspot.hpp" -#include "Utils/Folders.hpp" #include "Tutorial.hpp" +#include "Utils/Folders.hpp" -const char *cmd_names[cmd_count] = { +const char* cmd_names[cmd_count] = { #define DECLARE_COMMAND(cmd) #cmd, #include "ConsoleCmds.def" -#undef DECLARE_COMMAND +#undef DECLARE_COMMAND }; console_handler cmd_handlers[cmd_count] = { #define DECLARE_COMMAND(cmd) ch_##cmd, #include "ConsoleCmds.def" -#undef DECLARE_COMMAND +#undef DECLARE_COMMAND }; using namespace Game; @@ -73,12 +73,12 @@ float tintr = 1, tintg = 1, tintb = 1; /* Helpers used in console commands */ /* Return true if PFX is a prefix of STR (case-insensitive). */ -static bool stripfx(const char *str, const char *pfx) +static bool stripfx(const char* str, const char* pfx) { return !strncasecmp(str, pfx, strlen(pfx)); } -static void set_proportion(int pnum, const char *args) +static void set_proportion(int pnum, const char* args) { float headprop, bodyprop, armprop, legprop; @@ -98,34 +98,34 @@ static void set_proportion(int pnum, const char *args) } } -static void set_protection(int pnum, const char *args) +static void set_protection(int pnum, const char* args) { float head, high, low; sscanf(args, "%f%f%f", &head, &high, &low); Person::players[pnum]->protectionhead = head; Person::players[pnum]->protectionhigh = high; - Person::players[pnum]->protectionlow = low; + Person::players[pnum]->protectionlow = low; } -static void set_armor(int pnum, const char *args) +static void set_armor(int pnum, const char* args) { float head, high, low; sscanf(args, "%f%f%f", &head, &high, &low); Person::players[pnum]->armorhead = head; Person::players[pnum]->armorhigh = high; - Person::players[pnum]->armorlow = low; + Person::players[pnum]->armorlow = low; } -static void set_metal(int pnum, const char *args) +static void set_metal(int pnum, const char* args) { float head, high, low; sscanf(args, "%f%f%f", &head, &high, &low); Person::players[pnum]->metalhead = head; Person::players[pnum]->metalhigh = high; - Person::players[pnum]->metallow = low; + Person::players[pnum]->metallow = low; } static void set_noclothes(int pnum, const char*) @@ -136,7 +136,7 @@ static void set_noclothes(int pnum, const char*) &Person::players[pnum]->skeleton.skinText[0], &Person::players[pnum]->skeleton.skinsize); } -static void set_clothes(int pnum, const char *args) +static void set_clothes(int pnum, const char* args) { char buf[64]; snprintf(buf, 63, "Textures/%s.png", args); @@ -156,12 +156,12 @@ static void set_clothes(int pnum, const char *args) /* Console commands themselves */ -void ch_quit(const char *) +void ch_quit(const char*) { tryquit = 1; } -void ch_map(const char *args) +void ch_map(const char* args) { if (!LoadLevel(args)) { // FIXME: Reduce code duplication with GameTick (should come from a Console class) @@ -175,7 +175,7 @@ void ch_map(const char *args) campaign = 0; } -void ch_save(const char *args) +void ch_save(const char* args) { std::string map_path = Folders::getUserDataPath() + "/Maps"; Folders::makeDirectory(map_path); @@ -183,8 +183,8 @@ void ch_save(const char *args) int mapvers = 12; - FILE *tfile; - tfile = fopen( map_path.c_str(), "wb" ); + FILE* tfile; + tfile = fopen(map_path.c_str(), "wb"); if (tfile == NULL) { perror((std::string("Couldn't open file ") + map_path + " for saving").c_str()); return; @@ -309,136 +309,135 @@ void ch_save(const char *args) fclose(tfile); } -void ch_cellar(const char *) +void ch_cellar(const char*) { Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Furdarko.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize); } -void ch_tint(const char *args) +void ch_tint(const char* args) { sscanf(args, "%f%f%f", &tintr, &tintg, &tintb); } -void ch_tintr(const char *args) +void ch_tintr(const char* args) { tintr = atof(args); } -void ch_tintg(const char *args) +void ch_tintg(const char* args) { tintg = atof(args); } -void ch_tintb(const char *args) +void ch_tintb(const char* args) { tintb = atof(args); } -void ch_speed(const char *args) +void ch_speed(const char* args) { Person::players[0]->speedmult = atof(args); } -void ch_strength(const char *args) +void ch_strength(const char* args) { Person::players[0]->power = atof(args); } -void ch_power(const char *args) +void ch_power(const char* args) { Person::players[0]->power = atof(args); } -void ch_size(const char *args) +void ch_size(const char* args) { Person::players[0]->scale = atof(args) * .2; } -void ch_sizenear(const char *args) +void ch_sizenear(const char* args) { int closest = findClosestPlayer(); if (closest >= 0) Person::players[closest]->scale = atof(args) * .2; } -void ch_proportion(const char *args) +void ch_proportion(const char* args) { set_proportion(0, args); } -void ch_proportionnear(const char *args) +void ch_proportionnear(const char* args) { int closest = findClosestPlayer(); if (closest >= 0) set_proportion(closest, args); } -void ch_protection(const char *args) +void ch_protection(const char* args) { set_protection(0, args); } -void ch_protectionnear(const char *args) +void ch_protectionnear(const char* args) { int closest = findClosestPlayer(); if (closest >= 0) set_protection(closest, args); } -void ch_armor(const char *args) +void ch_armor(const char* args) { set_armor(0, args); } -void ch_armornear(const char *args) +void ch_armornear(const char* args) { int closest = findClosestPlayer(); if (closest >= 0) set_armor(closest, args); } -void ch_protectionreset(const char *) +void ch_protectionreset(const char*) { set_protection(0, "1 1 1"); set_armor(0, "1 1 1"); } -void ch_metal(const char *args) +void ch_metal(const char* args) { set_metal(0, args); } -void ch_noclothes(const char *args) +void ch_noclothes(const char* args) { set_noclothes(0, args); } -void ch_noclothesnear(const char *args) +void ch_noclothesnear(const char* args) { int closest = findClosestPlayer(); if (closest >= 0) set_noclothes(closest, args); } -void ch_clothes(const char *args) +void ch_clothes(const char* args) { set_clothes(0, args); } -void ch_clothesnear(const char *args) +void ch_clothesnear(const char* args) { int closest = findClosestPlayer(); if (closest >= 0) set_clothes(closest, args); } -void ch_belt(const char *) +void ch_belt(const char*) { Person::players[0]->skeleton.clothes = !Person::players[0]->skeleton.clothes; } - -void ch_cellophane(const char *) +void ch_cellophane(const char*) { cellophane = !cellophane; float mul = (cellophane ? 0 : 1); @@ -451,7 +450,7 @@ void ch_cellophane(const char *) } } -void ch_funnybunny(const char *) +void ch_funnybunny(const char*) { Person::players[0]->creature = rabbittype; Person::players[0]->skeletonLoad(true); @@ -461,7 +460,7 @@ void ch_funnybunny(const char *) set_proportion(0, "1 1 1 1"); } -void ch_wolfie(const char *) +void ch_wolfie(const char*) { Person::players[0]->creature = wolftype; Person::players[0]->skeletonLoad(); @@ -469,64 +468,64 @@ void ch_wolfie(const char *) set_proportion(0, "1 1 1 1"); } -void ch_wolfieisgod(const char *args) +void ch_wolfieisgod(const char* args) { ch_wolfie(args); } -void ch_wolf(const char *) +void ch_wolf(const char*) { Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Wolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize); } -void ch_snowwolf(const char *) +void ch_snowwolf(const char*) { Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/SnowWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize); } -void ch_darkwolf(const char *) +void ch_darkwolf(const char*) { Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/DarkWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize); } -void ch_lizardwolf(const char *) +void ch_lizardwolf(const char*) { Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/LizardWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize); } -void ch_white(const char *) +void ch_white(const char*) { Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Fur.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize); } -void ch_brown(const char *) +void ch_brown(const char*) { Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Fur3.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize); } -void ch_black(const char *) +void ch_black(const char*) { Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Fur2.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize); } -void ch_sizemin(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) Person::players[i]->scale = 0.8 * 0.2; } -void ch_tutorial(const char *args) +void ch_tutorial(const char* args) { Tutorial::active = atoi(args); } -void ch_hostile(const char *args) +void ch_hostile(const char* args) { hostile = atoi(args); } -void ch_type(const char *args) +void ch_type(const char* args) { int n = sizeof(editortypenames) / sizeof(editortypenames[0]); for (int i = 0; i < n; i++) @@ -536,7 +535,7 @@ void ch_type(const char *args) } } -void ch_path(const char *args) +void ch_path(const char* args) { unsigned int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]); for (unsigned int i = 0; i < n; i++) @@ -546,7 +545,7 @@ void ch_path(const char *args) } } -void ch_hs(const char *args) +void ch_hs(const char* args) { float size; int type, shift; @@ -558,7 +557,7 @@ void ch_hs(const char *args) strcat(Hotspot::hotspots.back().text, "\n"); } -void ch_dialogue(const char *args) +void ch_dialogue(const char* args) { int type; char buf1[32]; @@ -573,7 +572,7 @@ void ch_dialogue(const char *args) Dialog::whichdialogue = Dialog::dialogs.size(); } -void ch_fixdialogue(const char *args) +void ch_fixdialogue(const char* args) { char buf1[32]; int whichdi; @@ -584,50 +583,50 @@ void ch_fixdialogue(const char *args) Dialog::dialogs[whichdi] = Dialog(Dialog::dialogs[whichdi].type, filename); } -void ch_fixtype(const char *args) +void ch_fixtype(const char* args) { int dlg; sscanf(args, "%d", &dlg); Dialog::dialogs[0].type = dlg; } -void ch_fixrotation(const char *) +void ch_fixrotation(const char*) { int playerId = Dialog::currentScene().participantfocus; Dialog::currentDialog().participantyaw[playerId] = Person::players[playerId]->yaw; } -void ch_ddialogue(const char *) +void ch_ddialogue(const char*) { if (!Dialog::dialogs.empty()) { Dialog::dialogs.pop_back(); } } -void ch_dhs(const char *) +void ch_dhs(const char*) { if (!Hotspot::hotspots.empty()) { Hotspot::hotspots.pop_back(); } } -void ch_immobile(const char *) +void ch_immobile(const char*) { Person::players[0]->immobile = 1; } -void ch_allimmobile(const char *) +void ch_allimmobile(const char*) { for (unsigned i = 1; i < Person::players.size(); i++) Person::players[i]->immobile = 1; } -void ch_mobile(const char *) +void ch_mobile(const char*) { Person::players[0]->immobile = 0; } -void ch_default(const char *) +void ch_default(const char*) { Person::players[0]->armorhead = 1; Person::players[0]->armorhigh = 1; @@ -664,7 +663,7 @@ void ch_default(const char *) Person::players[0]->immobile = 0; } -void ch_play(const char *args) +void ch_play(const char* args) { int dlg; sscanf(args, "%d", &dlg); @@ -677,49 +676,49 @@ void ch_play(const char *args) Dialog::currentDialog().play(); } -void ch_mapkilleveryone(const char *) +void ch_mapkilleveryone(const char*) { maptype = mapkilleveryone; } -void ch_mapkillmost(const char *) +void ch_mapkillmost(const char*) { maptype = mapkillmost; } -void ch_mapkillsomeone(const char *) +void ch_mapkillsomeone(const char*) { maptype = mapkillsomeone; } -void ch_mapgosomewhere(const char *) +void ch_mapgosomewhere(const char*) { maptype = mapgosomewhere; } -void ch_viewdistance(const char *args) +void ch_viewdistance(const char* args) { viewdistance = atof(args) * 100; } -void ch_fadestart(const char *args) +void ch_fadestart(const char* args) { fadestart = atof(args); } -void ch_slomo(const char *args) +void ch_slomo(const char* args) { slomospeed = atof(args); slomo = !slomo; slomodelay = 1000; } -void ch_slofreq(const char *args) +void ch_slofreq(const char* args) { slomofreq = atof(args); } -void ch_skytint(const char *args) +void ch_skytint(const char* args) { sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb); @@ -733,7 +732,7 @@ void ch_skytint(const char *args) Object::DoShadows(); } -void ch_skylight(const char *args) +void ch_skylight(const char* args) { sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb); diff --git a/Source/Environment/Lights.cpp b/Source/Environment/Lights.cpp index d448cd8..3151815 100644 --- a/Source/Environment/Lights.cpp +++ b/Source/Environment/Lights.cpp @@ -22,11 +22,11 @@ along with Lugaru. If not, see . void SetUpLight(Light* whichsource, int whichlight) { - static float qattenuation[] = {0.0002f}; + static float qattenuation[] = { 0.0002f }; //Initialize lights if (whichlight == 0) { - GLfloat LightAmbient[] = { whichsource->ambient[0], whichsource->ambient[1], whichsource->ambient[2], 1.0f}; + GLfloat LightAmbient[] = { whichsource->ambient[0], whichsource->ambient[1], whichsource->ambient[2], 1.0f }; GLfloat LightDiffuse[] = { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f }; GLfloat LightPosition[] = { whichsource->location.x, whichsource->location.y, whichsource->location.z, 0.0f }; @@ -37,27 +37,27 @@ void SetUpLight(Light* whichsource, int whichlight) } else { GLenum lightselect = GL_LIGHT1; switch (whichlight) { - case 2: - lightselect = GL_LIGHT2; - break; - case 3: - lightselect = GL_LIGHT3; - break; - case 4: - lightselect = GL_LIGHT4; - break; - case 5: - lightselect = GL_LIGHT5; - break; - case 6: - lightselect = GL_LIGHT6; - break; - case 7: - lightselect = GL_LIGHT7; - break; + case 2: + lightselect = GL_LIGHT2; + break; + case 3: + lightselect = GL_LIGHT3; + break; + case 4: + lightselect = GL_LIGHT4; + break; + case 5: + lightselect = GL_LIGHT5; + break; + case 6: + lightselect = GL_LIGHT6; + break; + case 7: + lightselect = GL_LIGHT7; + break; } - GLfloat LightAmbient[] = { 0, 0, 0, 1.0f}; + GLfloat LightAmbient[] = { 0, 0, 0, 1.0f }; GLfloat LightDiffuse[] = { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f }; GLfloat LightPosition[] = { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f }; @@ -66,6 +66,5 @@ void SetUpLight(Light* whichsource, int whichlight) glLightfv(lightselect, GL_AMBIENT, LightAmbient); glLightfv(lightselect, GL_DIFFUSE, LightDiffuse); glEnable(lightselect); - } } diff --git a/Source/Environment/Skybox.cpp b/Source/Environment/Skybox.cpp index 5ace90a..468329a 100644 --- a/Source/Environment/Skybox.cpp +++ b/Source/Environment/Skybox.cpp @@ -30,8 +30,8 @@ extern float skyboxr; extern float skyboxg; extern float skyboxb; -void SkyBox::load (const std::string& ffront, const std::string& fleft, const std::string& fback, - const std::string& fright, const std::string& fup, const std::string& fdown) +void SkyBox::load(const std::string& ffront, const std::string& fleft, const std::string& fback, + const std::string& fright, const std::string& fup, const std::string& fdown) { front.load(ffront, true); left.load(fleft, true); @@ -68,91 +68,91 @@ void SkyBox::draw() glDisable(GL_LIGHTING); if (skyboxtexture) glEnable(GL_TEXTURE_2D); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); front.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBegin(GL_QUADS); - glNormal3f( 0.0f, 0.0f, -1); + glNormal3f(0.0f, 0.0f, -1); glTexCoord2f(0, 0); - glVertex3f(-size, -size, size); + glVertex3f(-size, -size, size); glTexCoord2f(1, 0); - glVertex3f( size, -size, size); + glVertex3f(size, -size, size); glTexCoord2f(1, 1); - glVertex3f( size, size, size); + glVertex3f(size, size, size); glTexCoord2f(0, 1); - glVertex3f(-size, size, size); + glVertex3f(-size, size, size); glEnd(); back.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBegin(GL_QUADS); - glNormal3f( 0.0f, 0.0f, 1); + glNormal3f(0.0f, 0.0f, 1); glTexCoord2f(1, 0); glVertex3f(-size, -size, -size); glTexCoord2f(1, 1); - glVertex3f(-size, size, -size); + glVertex3f(-size, size, -size); glTexCoord2f(0, 1); - glVertex3f( size, size, -size); + glVertex3f(size, size, -size); glTexCoord2f(0, 0); - glVertex3f( size, -size, -size); + glVertex3f(size, -size, -size); glEnd(); up.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBegin(GL_QUADS); - glNormal3f( 0.0f, -1.0f, 0); + glNormal3f(0.0f, -1.0f, 0); glTexCoord2f(0, 1); - glVertex3f(-size, size, -size); + glVertex3f(-size, size, -size); glTexCoord2f(0, 0); - glVertex3f(-size, size, size); + glVertex3f(-size, size, size); glTexCoord2f(1, 0); - glVertex3f( size, size, size); + glVertex3f(size, size, size); glTexCoord2f(1, 1); - glVertex3f( size, size, -size); + glVertex3f(size, size, -size); glEnd(); down.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBegin(GL_QUADS); - glNormal3f( 0.0f, 1.0f, 0); + glNormal3f(0.0f, 1.0f, 0); glTexCoord2f(0, 0); glVertex3f(-size, -size, -size); glTexCoord2f(1, 0); - glVertex3f( size, -size, -size); + glVertex3f(size, -size, -size); glTexCoord2f(1, 1); - glVertex3f( size, -size, size); + glVertex3f(size, -size, size); glTexCoord2f(0, 1); - glVertex3f(-size, -size, size); + glVertex3f(-size, -size, size); glEnd(); right.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBegin(GL_QUADS); - glNormal3f( -1.0f, 0.0f, 0); + glNormal3f(-1.0f, 0.0f, 0); glTexCoord2f(1, 0); - glVertex3f( size, -size, -size); + glVertex3f(size, -size, -size); glTexCoord2f(1, 1); - glVertex3f( size, size, -size); + glVertex3f(size, size, -size); glTexCoord2f(0, 1); - glVertex3f( size, size, size); + glVertex3f(size, size, size); glTexCoord2f(0, 0); - glVertex3f( size, -size, size); + glVertex3f(size, -size, size); glEnd(); left.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBegin(GL_QUADS); - glNormal3f( 1.0f, 0.0f, 0); + glNormal3f(1.0f, 0.0f, 0); glTexCoord2f(0, 0); glVertex3f(-size, -size, -size); glTexCoord2f(1, 0); - glVertex3f(-size, -size, size); + glVertex3f(-size, -size, size); glTexCoord2f(1, 1); - glVertex3f(-size, size, size); + glVertex3f(-size, size, size); glTexCoord2f(0, 1); - glVertex3f(-size, size, -size); + glVertex3f(-size, size, -size); glEnd(); glEnable(GL_CULL_FACE); glDepthMask(1); diff --git a/Source/Environment/Terrain.cpp b/Source/Environment/Terrain.cpp index 6d195e2..d3a6f00 100644 --- a/Source/Environment/Terrain.cpp +++ b/Source/Environment/Terrain.cpp @@ -22,8 +22,8 @@ along with Lugaru. If not, see . #include "Game.hpp" #include "Objects/Object.hpp" -#include "Utils/Folders.hpp" #include "Tutorial.hpp" +#include "Utils/Folders.hpp" extern XYZ viewer; extern float viewdistance; @@ -42,7 +42,7 @@ extern bool skyboxtexture; //Functions -int Terrain::lineTerrain(XYZ p1, XYZ p2, XYZ *p) +int Terrain::lineTerrain(XYZ p1, XYZ p2, XYZ* p) { static int i, j, k; static float distance; @@ -277,7 +277,6 @@ void Terrain::UpdateVertexArray(int whichx, int whichy) { static int i, j, a, b, c, patch_size, stepsize; - numtris[whichx][whichy] = 0; patch_size = size / subdivision; @@ -355,9 +354,9 @@ 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; } } @@ -366,8 +365,8 @@ void Terrain::UpdateVertexArray(int whichx, int whichy) 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++) { - for (j = whichy * size / subdivision; j < (whichy + 1)*size / subdivision - 1; j++) { + for (i = whichx * size / subdivision; i < (whichx + 1) * size / subdivision - 1; i++) { + for (j = whichy * size / subdivision; j < (whichy + 1) * size / subdivision - 1; j++) { triangles[(i * (size - 1) * 2) + (j * 2)][0].x = i * scale; triangles[(i * (size - 1) * 2) + (j * 2)][0].y = heightmap[i][j] * scale; triangles[(i * (size - 1) * 2) + (j * 2)][0].z = j * scale; @@ -393,10 +392,8 @@ void Terrain::UpdateVertexArray(int whichx, int whichy) triangles[(i * (size - 1) * 2) + (j * 2) + 1][2].z = j * scale + 1 * scale; } } - } - bool Terrain::load(const std::string& fileName) { static long i, j; @@ -448,7 +445,6 @@ bool Terrain::load(const std::string& fileName) } Game::LoadingScreen(); - for (i = 0; i < size; i++) { for (j = 0; j < size; j++) { heightmap[i][j] *= .5; @@ -628,7 +624,6 @@ bool Terrain::load(const std::string& fileName) 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--; - } } } @@ -682,7 +677,6 @@ void Terrain::CalculateNormals() normals[i][j + 1] = normals[i][j + 1] + facenormal; normals[i + 1][j] = normals[i + 1][j] + facenormal; - a.x = i + 1; a.y = heightmap[i + 1][j]; a.z = j; @@ -800,7 +794,6 @@ void Terrain::drawpatchotherother(int whichx, int whichy) glMatrixMode(GL_MODELVIEW); } - float Terrain::getHeight(float pointx, float pointz) { static int tilex, tiley; @@ -975,9 +968,9 @@ void Terrain::draw(int layer) 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) - glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness); else if (environment == desertenvironment) - glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0); if (!layer && textureness[i][j] != allsecond) drawpatch(i, j, opacity); if (layer == 1 && textureness[i][j] != allfirst) @@ -990,7 +983,7 @@ void Terrain::draw(int layer) } } if (environment == desertenvironment) - glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0); } void Terrain::drawdecals() @@ -1061,7 +1054,7 @@ void Terrain::drawdecals() if (distancemult >= 1) glColor4f(1, 1, 1, decals[i].opacity); if (distancemult < 1) - glColor4f(1, 1, 1, decals[i].opacity*distancemult); + 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; @@ -1071,7 +1064,7 @@ void Terrain::drawdecals() glColor4f(1, 1, 1, decals[i].opacity * (5 - decals[i].alivetime) / 2); } if (distancemult < 1) { - glColor4f(1, 1, 1, decals[i].opacity*distancemult); + glColor4f(1, 1, 1, decals[i].opacity * distancemult); if (decals[i].alivetime > 3) glColor4f(1, 1, 1, decals[i].opacity * (5 - decals[i].alivetime) / 2 * distancemult); } @@ -1081,14 +1074,14 @@ void Terrain::drawdecals() if (distancemult >= 1) { glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity); if (decals[i].alivetime < 4) - glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity*decals[i].alivetime*.25); + glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * decals[i].alivetime * .25); 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); + glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * distancemult); if (decals[i].alivetime < 4) - glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity*decals[i].alivetime*distancemult * .25); + glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * decals[i].alivetime * distancemult * .25); if (decals[i].alivetime > 58) glColor4f(decals[i].brightness, decals[i].brightness, decals[i].brightness, decals[i].opacity * (60 - decals[i].alivetime) / 2 * distancemult); } @@ -1288,12 +1281,18 @@ void Terrain::DoShadows() 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) colors[i][j][0] = 1; - if (colors[i][j][1] > 1) colors[i][j][1] = 1; - if (colors[i][j][2] > 1) colors[i][j][2] = 1; - if (colors[i][j][0] < 0) colors[i][j][0] = 0; - if (colors[i][j][1] < 0) colors[i][j][1] = 0; - if (colors[i][j][2] < 0) colors[i][j][2] = 0; + if (colors[i][j][0] > 1) + colors[i][j][0] = 1; + if (colors[i][j][1] > 1) + colors[i][j][1] = 1; + if (colors[i][j][2] > 1) + colors[i][j][2] = 1; + if (colors[i][j][0] < 0) + colors[i][j][0] = 0; + if (colors[i][j][1] < 0) + colors[i][j][1] = 0; + if (colors[i][j][2] < 0) + colors[i][j][2] = 0; } } diff --git a/Source/Game.cpp b/Source/Game.cpp index 0fe8e53..54b4f2f 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -27,8 +27,8 @@ along with Lugaru. If not, see . extern int mainmenu; -const char *pathtypenames[] = {"keepwalking", "pause"}; -const char *editortypenames[] = { +const char* pathtypenames[] = { "keepwalking", "pause" }; +const char* editortypenames[] = { "active", "sitting", "sitting wall", "sleeping", "dead1", "dead2", "dead3", "dead4" }; @@ -62,7 +62,7 @@ int oldmousecoordh = 0; int oldmousecoordv = 0; float yaw = 0; float pitch = 0; -SkyBox *skybox = NULL; +SkyBox* skybox = NULL; bool cameramode = 0; bool firstLoadDone = false; @@ -89,8 +89,8 @@ int musictype = 0; XYZ mapcenter; float mapradius = 0; -Text *text = NULL; -Text *textmono = NULL; +Text* text = NULL; +Text* textmono = NULL; float fps = 0; bool editorenabled = 0; @@ -149,41 +149,41 @@ void Game::inputText(string& str, unsigned* charselected) break; } switch (evenement.type) { - case SDL_TEXTEDITING: - /* FIXME - We should handle this for complete input method support */ - break; - case SDL_TEXTINPUT: - str.insert(*charselected, evenement.text.text); - (*charselected) += strlen(evenement.text.text); - break; - case SDL_KEYDOWN: - if (evenement.key.keysym.sym == SDLK_ESCAPE) { - str.clear(); - *charselected = 0; - waiting = false; - } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) { - if ((*charselected) > 0) { - (*charselected)--; - str.erase(*charselected, 1); + case SDL_TEXTEDITING: + /* FIXME - We should handle this for complete input method support */ + break; + case SDL_TEXTINPUT: + str.insert(*charselected, evenement.text.text); + (*charselected) += strlen(evenement.text.text); + break; + case SDL_KEYDOWN: + if (evenement.key.keysym.sym == SDLK_ESCAPE) { + str.clear(); + *charselected = 0; + waiting = false; + } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) { + if ((*charselected) > 0) { + (*charselected)--; + str.erase(*charselected, 1); + } + } else if (evenement.key.keysym.sym == SDLK_DELETE) { + if ((*charselected) < str.size()) { + str.erase(*charselected, 1); + } + } else if (evenement.key.keysym.sym == SDLK_HOME) { + (*charselected) = 0; + } else if (evenement.key.keysym.sym == SDLK_END) { + (*charselected) = str.size(); + } else if (evenement.key.keysym.sym == SDLK_LEFT) { + if ((*charselected) != 0) + (*charselected)--; + } else if (evenement.key.keysym.sym == SDLK_RIGHT) { + if ((*charselected) < str.size()) + (*charselected)++; + } else if (evenement.key.keysym.sym == SDLK_RETURN) { + waiting = false; } - } else if (evenement.key.keysym.sym == SDLK_DELETE) { - if ((*charselected) < str.size()) { - str.erase(*charselected, 1); - } - } else if (evenement.key.keysym.sym == SDLK_HOME) { - (*charselected) = 0; - } else if (evenement.key.keysym.sym == SDLK_END) { - (*charselected) = str.size(); - } else if (evenement.key.keysym.sym == SDLK_LEFT) { - if ((*charselected) != 0) - (*charselected)--; - } else if (evenement.key.keysym.sym == SDLK_RIGHT) { - if ((*charselected) < str.size()) - (*charselected)++; - } else if (evenement.key.keysym.sym == SDLK_RETURN) { - waiting = false; - } - break; + break; } } diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 7ec4b65..2e15dcd 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -25,8 +25,8 @@ along with Lugaru. If not, see . #include "Level/Dialog.hpp" #include "Level/Hotspot.hpp" #include "Menu/Menu.hpp" -#include "Utils/Input.hpp" #include "Tutorial.hpp" +#include "Utils/Input.hpp" extern XYZ viewer; extern int environment; @@ -84,21 +84,22 @@ extern bool gamestarted; extern bool showdamagebar; - - int drawtoggle = 0; int numboundaries = 0; XYZ boundary[360]; int change = 0; - - -enum drawmodes { - normalmode, motionblurmode, radialzoommode, - realmotionblurmode, doublevisionmode, glowmode, +enum drawmodes +{ + normalmode, + motionblurmode, + radialzoommode, + realmotionblurmode, + doublevisionmode, + glowmode, }; -void Game::flash(float amount, int delay) // shouldn't be that way, these should be attributes and Person class should not change rendering. +void Game::flash(float amount, int delay) // shouldn't be that way, these should be attributes and Person class should not change rendering. { flashr = 1; flashg = 0; @@ -120,22 +121,22 @@ int Game::DrawGLScene(StereoSide side) std::string string; static int drawmode = 0; - if ( stereomode == stereoAnaglyph ) { + if (stereomode == stereoAnaglyph) { switch (side) { - case stereoLeft: - glColorMask( 0.0, 1.0, 1.0, 1.0 ); - break; - case stereoRight: - glColorMask( 1.0, 0.0, 0.0, 1.0 ); - break; - default: - break; + case stereoLeft: + glColorMask(0.0, 1.0, 1.0, 1.0); + break; + case stereoRight: + glColorMask(1.0, 0.0, 0.0, 1.0); + break; + default: + break; } } else { - glColorMask( 1.0, 1.0, 1.0, 1.0 ); + glColorMask(1.0, 1.0, 1.0, 1.0); - if ( stereomode == stereoHorizontalInterlaced || - stereomode == stereoVerticalInterlaced ) { + if (stereomode == stereoHorizontalInterlaced || + stereomode == stereoVerticalInterlaced) { glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01); } } @@ -187,7 +188,7 @@ int Game::DrawGLScene(StereoSide side) } if ((!changed && !slomo) || loading) { drawmode = normalmode; - if (ismotionblur && (/*fps>100||*/alwaysblur)) { + if (ismotionblur && (/*fps>100||*/ alwaysblur)) { if (olddrawmode != realmotionblurmode) change = 1; else @@ -243,18 +244,18 @@ int Game::DrawGLScene(StereoSide side) glClearColor(0.25f, 0.25f, 0.25f, 1.0f); glClear(GL_DEPTH_BUFFER_BIT); - glMatrixMode (GL_MODELVIEW); + glMatrixMode(GL_MODELVIEW); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glLoadIdentity (); + glLoadIdentity(); // Move the camera for the current eye's point of view. // Reverse the movement if we're reversing stereo - glTranslatef((stereoseparation / 2) * side * (stereoreverse ? -1 : 1), 0, 0); + glTranslatef((stereoseparation / 2) * side * (stereoreverse ? -1 : 1), 0, 0); //camera effects if (!cameramode && !freeze && !winfreeze) { //shake - glRotatef(float(Random() % 100) / 10 * camerashake/*+(woozy*woozy)/10*/, 0, 0, 1); + glRotatef(float(Random() % 100) / 10 * camerashake /*+(woozy*woozy)/10*/, 0, 0, 1); //sway glRotatef(pitch + sin(woozy / 2) * (Person::players[0]->damage / Person::players[0]->damagetolerance) * 5, 1, 0, 0); glRotatef(yaw + sin(woozy) * (Person::players[0]->damage / Person::players[0]->damagetolerance) * 5, 0, 1, 0); @@ -283,13 +284,13 @@ int Game::DrawGLScene(StereoSide side) if (environment == desertenvironment) { if (detail == 2) { - glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, blurness + .4 ); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, blurness + .4); } glRotatef((float)(abs(Random() % 100)) / 1000, 1, 0, 0); glRotatef((float)(abs(Random() % 100)) / 1000, 0, 1, 0); } skybox->draw(); - glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0); glPopMatrix(); glTranslatef(-viewer.x, -viewer.y, -viewer.z); frustum.GetFrustum(); @@ -532,7 +533,6 @@ int Game::DrawGLScene(StereoSide side) } } - if (numpathpoints > 1) { glColor4f(0, 1, 0, 1); for (unsigned k = 0; int(k) < numpathpoints; k++) { @@ -560,7 +560,7 @@ int Game::DrawGLScene(StereoSide side) if (!console) { if (!Tutorial::active) if (bonus > 0 && bonustime < 1 && !winfreeze && !Dialog::inDialog()) { - const char *bonus_name; + const char* bonus_name; if (bonus < bonus_count) bonus_name = bonus_names[bonus]; else @@ -611,7 +611,7 @@ int Game::DrawGLScene(StereoSide side) int i = 0; while (!done) { if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') { - 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); + 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') @@ -695,10 +695,10 @@ int Game::DrawGLScene(StereoSide side) string = std::string(tempname) + ": "; if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) { - text->glPrintOutlined(0.7, 0.7, 0.7, tutorialopac, startx - 2 * 7.6 * string.size()*screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + text->glPrintOutlined(0.7, 0.7, 0.7, tutorialopac, startx - 2 * 7.6 * string.size() * screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); } else { glColor4f(0, 0, 0, tutorialopac); - text->glPrintOutline(startx - 2 * 7.6 * string.size()*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); + text->glPrintOutline(startx - 2 * 7.6 * string.size() * screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); } tempnum = 0; @@ -829,7 +829,6 @@ int Game::DrawGLScene(StereoSide side) glColor4f(.5, .5, .5, 1); - if ((texttoggle || editorenabled) && devtools && !mainmenu) { string = "The framespersecond is " + to_string(int(fps)); text->glPrint(10, 30, string, 0, .8, 1024, 768); @@ -858,42 +857,42 @@ int Game::DrawGLScene(StereoSide side) string = "Object type: " + to_string(editortype); text->glPrint(10, 120, string, 0, .8, 1024, 768); switch (editortype) { - case boxtype: - string = "(box)"; - break; - case treetrunktype: - string = "(tree)"; - break; - case walltype: - string = "(wall)"; - break; - case weirdtype: - string = "(weird)"; - break; - case spiketype: - string = "(spike)"; - break; - case rocktype: - string = "(rock)"; - break; - case bushtype: - string = "(bush)"; - break; - case tunneltype: - string = "(tunnel)"; - break; - case chimneytype: - string = "(chimney)"; - break; - case platformtype: - string = "(platform)"; - break; - case cooltype: - string = "(cool)"; - break; - case firetype: - string = "(fire)"; - break; + case boxtype: + string = "(box)"; + break; + case treetrunktype: + string = "(tree)"; + break; + case walltype: + string = "(wall)"; + break; + case weirdtype: + string = "(weird)"; + break; + case spiketype: + string = "(spike)"; + break; + case rocktype: + string = "(rock)"; + break; + case bushtype: + string = "(bush)"; + break; + case tunneltype: + string = "(tunnel)"; + break; + case chimneytype: + string = "(chimney)"; + break; + case platformtype: + string = "(platform)"; + break; + case cooltype: + string = "(cool)"; + break; + case firetype: + string = "(fire)"; + break; } text->glPrint(130, 120, string, 0, .8, 1024, 768); @@ -904,7 +903,6 @@ int Game::DrawGLScene(StereoSide side) } string = "Difficulty: " + to_string(difficulty); text->glPrint(10, 240, string, 0, .8, 1024, 768); - } } @@ -926,7 +924,7 @@ int Game::DrawGLScene(StereoSide side) glEnable(GL_BLEND); glColor4f(0, 0, 0, .5); glBegin(GL_QUADS); - glVertex3f(0, 0, 0.0f); + glVertex3f(0, 0, 0.0f); glVertex3f(256, 0, 0.0f); glVertex3f(256, 256, 0.0f); glVertex3f(0, 256, 0.0f); @@ -965,8 +963,8 @@ int Game::DrawGLScene(StereoSide side) 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) { - glColor4f(0, 0, 0, Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5)*.3); + if ((Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5)) * .3 < .3) { + glColor4f(0, 0, 0, Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5) * .3); blackout = Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5) * .3; } else { glColor4f(0, 0, 0, Person::players[0]->blooddimamount * .3); @@ -976,8 +974,8 @@ int Game::DrawGLScene(StereoSide side) if (console) glColor4f(.7, 0, 0, .2); glBegin(GL_QUADS); - glVertex3f(0, 0, 0.0f); - glVertex3f(256, 0, 0.0f); + glVertex3f(0, 0, 0.0f); + glVertex3f(256, 0, 0.0f); glVertex3f(256, 256, 0.0f); glVertex3f(0, 256, 0.0f); glEnd(); @@ -1015,7 +1013,7 @@ int Game::DrawGLScene(StereoSide side) glEnable(GL_BLEND); glColor4f(flashr, flashg, flashb, flashamount); glBegin(GL_QUADS); - glVertex3f(0, 0, 0.0f); + glVertex3f(0, 0, 0.0f); glVertex3f(256, 0, 0.0f); glVertex3f(256, 256, 0.0f); glVertex3f(0, 256, 0.0f); @@ -1034,11 +1032,11 @@ int Game::DrawGLScene(StereoSide side) float mapviewdist = 20000; glDisable(GL_DEPTH_TEST); - glColor3f (1.0, 1.0, 1.0); // no coloring + glColor3f(1.0, 1.0, 1.0); // no coloring glEnable(GL_TEXTURE_2D); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -1216,7 +1214,7 @@ int Game::DrawGLScene(StereoSide side) //logo glDisable(GL_DEPTH_TEST); - glColor3f (1.0, 1.0, 1.0); // no coloring + glColor3f(1.0, 1.0, 1.0); // no coloring glEnable(GL_TEXTURE_2D); @@ -1266,7 +1264,7 @@ int Game::DrawGLScene(StereoSide side) //logo glDisable(GL_DEPTH_TEST); - glColor3f (1.0, 1.0, 1.0); // no coloring + glColor3f(1.0, 1.0, 1.0); // no coloring glEnable(GL_TEXTURE_2D); @@ -1312,25 +1310,25 @@ int Game::DrawGLScene(StereoSide side) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT); glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 2.0f); - glBindTexture( GL_TEXTURE_2D, screentexture); + glBindTexture(GL_TEXTURE_2D, screentexture); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight); } } if ((drawtoggle || change == 1) && drawmode == realmotionblurmode) { if (screentexture2) { - glBindTexture( GL_TEXTURE_2D, screentexture2); + glBindTexture(GL_TEXTURE_2D, screentexture2); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight); } if (!screentexture2) { - glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glGenTextures( 1, &screentexture2 ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glGenTextures(1, &screentexture2); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); - glBindTexture( GL_TEXTURE_2D, screentexture2); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glBindTexture(GL_TEXTURE_2D, screentexture2); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0); } @@ -1347,12 +1345,12 @@ int Game::DrawGLScene(StereoSide side) glDrawBuffer(GL_FRONT); glReadBuffer(GL_BACK); } - glColor3f (1.0, 1.0, 1.0); // no coloring + glColor3f(1.0, 1.0, 1.0); // no coloring glEnable(GL_TEXTURE_2D); - glBindTexture( GL_TEXTURE_2D, screentexture); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glBindTexture(GL_TEXTURE_2D, screentexture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -1389,7 +1387,7 @@ int Game::DrawGLScene(StereoSide side) glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glBindTexture( GL_TEXTURE_2D, screentexture); + glBindTexture(GL_TEXTURE_2D, screentexture); glColor4f(1, 1, 1, .5); glPushMatrix(); glBegin(GL_QUADS); @@ -1403,7 +1401,7 @@ int Game::DrawGLScene(StereoSide side) glVertex3f(-1, 1, 0.0f); glEnd(); glPopMatrix(); - glBindTexture( GL_TEXTURE_2D, screentexture2); + glBindTexture(GL_TEXTURE_2D, screentexture2); glColor4f(1, 1, 1, .5); glPushMatrix(); glBegin(GL_QUADS); @@ -1575,7 +1573,7 @@ int Game::DrawGLScene(StereoSide side) multiplier = 0; } - if ( side == stereoRight || side == stereoCenter ) { + if (side == stereoRight || side == stereoCenter) { if (drawmode != motionblurmode || mainmenu) { swap_gl_buffers(); } @@ -1603,7 +1601,7 @@ void DrawMenu() glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); Game::ReSizeGLScene(90, .1f); //draw menu background @@ -1628,8 +1626,8 @@ void DrawMenu() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); glColor4f(0, 0, 0, 1.0); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); glVertex3f(-1, -1, 0); @@ -1639,8 +1637,8 @@ void DrawMenu() glEnd(); glEnable(GL_BLEND); glColor4f(0.4, 0.4, 0.4, 1.0); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glEnable(GL_TEXTURE_2D); Game::Mainmenuitems[4].bind(); glBegin(GL_QUADS); @@ -1659,8 +1657,6 @@ void DrawMenu() glPopMatrix(); glMatrixMode(GL_MODELVIEW); - - glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); @@ -1692,8 +1688,8 @@ void DrawMenu() glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glColor4f(1, 1, 1, 1); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glPopMatrix(); if (!Game::waiting) { // hide the cursor while waiting for a key glPushMatrix(); @@ -1721,7 +1717,6 @@ void DrawMenu() glMatrixMode(GL_PROJECTION); glPopMatrix(); - //draw screen flash if (flashamount > 0) { if (flashamount > 1) diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 984202f..b082ef1 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -68,7 +68,7 @@ extern float accountcampaigntime[10]; extern int accountcampaignchoicesmade[10]; extern int accountcampaignchoices[10][5000]; -void LOG(const std::string &, ...) +void LOG(const std::string&, ...) { // !!! FIXME: write me. } @@ -121,9 +121,7 @@ void Game::deleteGame() Dispose(); } - - -void LoadSave(const std::string& fileName, GLubyte *array) +void LoadSave(const std::string& fileName, GLubyte* array) { LOGFUNC; @@ -152,8 +150,6 @@ void LoadSave(const std::string& fileName, GLubyte *array) } } - - //***************> ResizeGLScene() <******/ GLvoid Game::ReSizeGLScene(float fov, float pnear) { @@ -179,9 +175,9 @@ void Game::LoadingScreen() } static float loadprogress; - static AbsoluteTime frametime = {0, 0}; - AbsoluteTime currTime = UpTime (); - double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime); + static AbsoluteTime frametime = { 0, 0 }; + AbsoluteTime currTime = UpTime(); + double deltaTime = (float)AbsoluteDeltaToDuration(currTime, frametime); if (0 > deltaTime) // if negative microseconds deltaTime /= -1000000.0; @@ -201,7 +197,6 @@ void Game::LoadingScreen() glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - loadtime += multiplier * 4; loadprogress = loadtime; @@ -212,8 +207,8 @@ void Game::LoadingScreen() glEnable(GL_TEXTURE_2D); loadscreentexture.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -265,8 +260,8 @@ void Game::LoadingScreen() glEnable(GL_TEXTURE_2D); loadscreentexture.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -305,8 +300,8 @@ void Game::LoadingScreen() glEnable(GL_TEXTURE_2D); loadscreentexture.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -403,8 +398,8 @@ void FadeLoadingScreen(float howmuch) //Background glDisable(GL_TEXTURE_2D); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -585,7 +580,6 @@ void Game::InitGame() FadeLoadingScreen(95); - gameon = 0; mainmenu = 1; @@ -601,20 +595,18 @@ void Game::InitGame() Animation::loadAll(); } - void Game::LoadScreenTexture() { - glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if (!Game::screentexture) - glGenTextures( 1, &Game::screentexture ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - + glGenTextures(1, &Game::screentexture); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); - glBindTexture( GL_TEXTURE_2D, Game::screentexture); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glBindTexture(GL_TEXTURE_2D, Game::screentexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0); } @@ -668,12 +660,10 @@ void Game::LoadStuff() terrain.breaktexture.load("Textures/Break.png", 0); terrain.bloodtexture2.load("Textures/Blood.png", 0); - terrain.footprinttexture.load("Textures/Footprint.png", 0); terrain.bodyprinttexture.load("Textures/Bodyprint.png", 0); hawktexture.load("Textures/Hawk.png", 0); - Sprite::cloudtexture.load("Textures/Cloud.png", 1); Sprite::cloudimpacttexture.load("Textures/CloudImpact.png", 1); Sprite::bloodtexture.load("Textures/BloodParticle.png", 1); @@ -708,7 +698,6 @@ void Game::LoadStuff() SetUpLighting(); - fadestart = .6; gravity = -10; @@ -820,4 +809,3 @@ void Game::LoadStuff() visibleloading = false; firstLoadDone = true; } - diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index b94d2e8..7e50cc0 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -31,10 +31,10 @@ along with Lugaru. If not, see . #include "Level/Dialog.hpp" #include "Level/Hotspot.hpp" #include "Menu/Menu.hpp" +#include "Tutorial.hpp" #include "User/Settings.hpp" #include "Utils/Folders.hpp" #include "Utils/Input.hpp" -#include "Tutorial.hpp" #if PLATFORM_UNIX #include @@ -60,7 +60,6 @@ using namespace Game; #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format) #endif - extern float multiplier; extern XYZ viewer; extern int environment; @@ -149,7 +148,7 @@ float musicvolume[4] = {}; float oldmusicvolume[4] = {}; int musicselected = 0; -const char *rabbitskin[] = { +const char* rabbitskin[] = { "Textures/Fur3.jpg", "Textures/Fur.jpg", "Textures/Fur2.jpg", @@ -162,16 +161,16 @@ const char *rabbitskin[] = { "Textures/WB2.jpg" }; -const char *wolfskin[] = { +const char* wolfskin[] = { "Textures/Wolf.jpg", "Textures/DarkWolf.jpg", "Textures/SnowWolf.jpg" }; -const char **creatureskin[] = {rabbitskin, wolfskin}; +const char** creatureskin[] = { rabbitskin, wolfskin }; #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1]; -STATIC_ASSERT (rabbittype == 0 && wolftype == 1) +STATIC_ASSERT(rabbittype == 0 && wolftype == 1) // utility functions @@ -221,71 +220,71 @@ void Game::playdialoguescenesound() int sound = -1; switch (Dialog::currentScene().sound) { - case -6: - sound = alarmsound; - break; - case -4: - sound = consolefailsound; - break; - case -3: - sound = consolesuccesssound; - break; - case -2: - sound = firestartsound; - break; - case -1: - sound = fireendsound; - break; - case 1: - sound = rabbitchitter; - break; - case 2: - sound = rabbitchitter2; - break; - case 3: - sound = rabbitpainsound; - break; - case 4: - sound = rabbitpain1sound; - break; - case 5: - sound = rabbitattacksound; - break; - case 6: - sound = rabbitattack2sound; - break; - case 7: - sound = rabbitattack3sound; - break; - case 8: - sound = rabbitattack4sound; - break; - case 9: - sound = growlsound; - break; - case 10: - sound = growl2sound; - break; - case 11: - sound = snarlsound; - break; - case 12: - sound = snarl2sound; - break; - case 13: - sound = barksound; - break; - case 14: - sound = bark2sound; - break; - case 15: - sound = bark3sound; - break; - case 16: - sound = barkgrowlsound; - break; - default: - break; + case -6: + sound = alarmsound; + break; + case -4: + sound = consolefailsound; + break; + case -3: + sound = consolesuccesssound; + break; + case -2: + sound = firestartsound; + break; + case -1: + sound = fireendsound; + break; + case 1: + sound = rabbitchitter; + break; + case 2: + sound = rabbitchitter2; + break; + case 3: + sound = rabbitpainsound; + break; + case 4: + sound = rabbitpain1sound; + break; + case 5: + sound = rabbitattacksound; + break; + case 6: + sound = rabbitattack2sound; + break; + case 7: + sound = rabbitattack3sound; + break; + case 8: + sound = rabbitattack4sound; + break; + case 9: + sound = growlsound; + break; + case 10: + sound = growl2sound; + break; + case 11: + sound = snarlsound; + break; + case 12: + sound = snarl2sound; + break; + case 13: + sound = barksound; + break; + case 14: + sound = bark2sound; + break; + case 15: + sound = bark3sound; + break; + case 16: + sound = barkgrowlsound; + break; + default: + break; } if (sound != -1) emit_sound_at(sound, temppos); @@ -315,10 +314,10 @@ static int findClosestObject() for (unsigned int i = 0; i < Object::objects.size(); i++) { float distance = distsq(&Object::objects[i]->position, - &Person::players[0]->coords); + &Person::players[0]->coords); if (distance < closestdist) { closestdist = distance; - closest = (int) i; + closest = (int)i; } } return closest; @@ -338,12 +337,12 @@ static void cmd_dispatch(const string cmd) } /********************> Tick() <*****/ -extern bool save_screenshot(const char * fname); -void Screenshot (void) +extern bool save_screenshot(const char* fname); +void Screenshot(void) { char filename[1024]; time_t t = time(NULL); - struct tm *tme = localtime(&t); + struct tm* tme = localtime(&t); sprintf(filename, "Screenshot-%04d%02d%02d-%02d%02d%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec); @@ -385,7 +384,6 @@ void Setenvironment(int which) pause_sound(stream_wind); pause_sound(stream_desertambient); - if (environment == snowyenvironment) { windvector = 0; windvector.z = 3; @@ -405,17 +403,15 @@ void Setenvironment(int which) terraintexture.load("Textures/Snow.jpg", 1); terraintexture2.load("Textures/Rock.jpg", 1); - temptexdetail = texdetail; if (texdetail > 1) texdetail = 4; - skybox->load( "Textures/Skybox(snow)/Front.jpg", - "Textures/Skybox(snow)/Left.jpg", - "Textures/Skybox(snow)/Back.jpg", - "Textures/Skybox(snow)/Right.jpg", - "Textures/Skybox(snow)/Up.jpg", - "Textures/Skybox(snow)/Down.jpg"); - + skybox->load("Textures/Skybox(snow)/Front.jpg", + "Textures/Skybox(snow)/Left.jpg", + "Textures/Skybox(snow)/Back.jpg", + "Textures/Skybox(snow)/Right.jpg", + "Textures/Skybox(snow)/Up.jpg", + "Textures/Skybox(snow)/Down.jpg"); texdetail = temptexdetail; } else if (environment == desertenvironment) { @@ -426,7 +422,6 @@ void Setenvironment(int which) Object::rocktextureptr.load("Textures/BoulderDesert.jpg", 1); Object::boxtextureptr.load("Textures/DesertBox.jpg", 1); - if (ambientsound) emit_stream_np(stream_desertambient); @@ -438,17 +433,15 @@ void Setenvironment(int which) terraintexture.load("Textures/Sand.jpg", 1); terraintexture2.load("Textures/SandSlope.jpg", 1); - temptexdetail = texdetail; if (texdetail > 1) texdetail = 4; - skybox->load( "Textures/Skybox(sand)/Front.jpg", - "Textures/Skybox(sand)/Left.jpg", - "Textures/Skybox(sand)/Back.jpg", - "Textures/Skybox(sand)/Right.jpg", - "Textures/Skybox(sand)/Up.jpg", - "Textures/Skybox(sand)/Down.jpg"); - + skybox->load("Textures/Skybox(sand)/Front.jpg", + "Textures/Skybox(sand)/Left.jpg", + "Textures/Skybox(sand)/Back.jpg", + "Textures/Skybox(sand)/Right.jpg", + "Textures/Skybox(sand)/Up.jpg", + "Textures/Skybox(sand)/Down.jpg"); texdetail = temptexdetail; } else if (environment == grassyenvironment) { @@ -470,17 +463,15 @@ void Setenvironment(int which) terraintexture.load("Textures/GrassDirt.jpg", 1); terraintexture2.load("Textures/MossRock.jpg", 1); - temptexdetail = texdetail; if (texdetail > 1) texdetail = 4; - skybox->load( "Textures/Skybox(grass)/Front.jpg", - "Textures/Skybox(grass)/Left.jpg", - "Textures/Skybox(grass)/Back.jpg", - "Textures/Skybox(grass)/Right.jpg", - "Textures/Skybox(grass)/Up.jpg", - "Textures/Skybox(grass)/Down.jpg"); - + skybox->load("Textures/Skybox(grass)/Front.jpg", + "Textures/Skybox(grass)/Left.jpg", + "Textures/Skybox(grass)/Back.jpg", + "Textures/Skybox(grass)/Right.jpg", + "Textures/Skybox(grass)/Up.jpg", + "Textures/Skybox(grass)/Down.jpg"); texdetail = temptexdetail; } @@ -546,7 +537,7 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) pause_sound(stream_firesound); int mapvers; - FILE *tfile; + FILE* tfile; errno = 0; tfile = Folders::openMandatoryFile(level_path, "rb"); @@ -846,7 +837,6 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) } } - Game::LoadingScreen(); if (cellophane) { @@ -984,7 +974,7 @@ void doDevKeys() /* Grow tree leaves?? */ if (Input::isKeyPressed(SDL_SCANCODE_Y)) { - for (auto& an_object : Object::objects) { + for (auto& an_object : Object::objects) { if (an_object->type == treeleavestype) { an_object->scale *= .9; } @@ -1056,7 +1046,7 @@ void doDevKeys() 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); + &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize); } Person::players[closest]->addClothes(); @@ -1083,7 +1073,6 @@ void doDevKeys() legprop = Person::players[closest]->proportionlegs.x / 1.1; } - if (Person::players[closest]->creature == rabbittype) { Person::players[closest]->creature = wolftype; Person::players[closest]->whichskin = 0; @@ -1126,7 +1115,6 @@ void doDevKeys() Person::players[closest]->proportionlegs = 1.1 * legprop; Person::players[closest]->proportionlegs.y = 1.05 * legprop; } - } } @@ -1288,7 +1276,6 @@ void doDevKeys() Person::players[closest]->skeleton.free = 2; camerashake += .6; - } } @@ -1321,7 +1308,7 @@ void doDevKeys() if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { int closest = findClosestPlayer(); if (closest >= 0) { - Person::players.erase(Person::players.begin()+closest); + Person::players.erase(Person::players.begin() + closest); } } @@ -1359,7 +1346,7 @@ void doDevKeys() if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { Person::players.push_back(shared_ptr(new Person())); - Person::players.back()->id = Person::players.size()-1; + Person::players.back()->id = Person::players.size() - 1; Person::players.back()->scale = Person::players[0]->scale; Person::players.back()->creature = rabbittype; @@ -1563,7 +1550,6 @@ void doDevKeys() editorsize = .1; } - if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { mapradius -= multiplier * 10; } @@ -1595,24 +1581,24 @@ void doJumpReversals() { for (unsigned k = 0; k < Person::players.size(); k++) { for (unsigned i = k + 1; i < Person::players.size(); i++) { - if ( Person::players[k]->skeleton.free == 0 && - Person::players[i]->skeleton.oldfree == 0 && - (Person::players[i]->animTarget == jumpupanim || - Person::players[k]->animTarget == jumpupanim) && - (Person::players[i]->aitype == playercontrolled || - Person::players[k]->aitype == playercontrolled) && - ((Person::players[i]->aitype == attacktypecutoff && Person::players[i]->stunned <= 0) || - (Person::players[k]->aitype == attacktypecutoff && Person::players[k]->stunned <= 0))) { - if ( distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 10 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5) && - distsqflat(&Person::players[i]->coords, &Person::players[k]->coords) < 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) { + if (Person::players[k]->skeleton.free == 0 && + Person::players[i]->skeleton.oldfree == 0 && + (Person::players[i]->animTarget == jumpupanim || + Person::players[k]->animTarget == jumpupanim) && + (Person::players[i]->aitype == playercontrolled || + Person::players[k]->aitype == playercontrolled) && + ((Person::players[i]->aitype == attacktypecutoff && Person::players[i]->stunned <= 0) || + (Person::players[k]->aitype == attacktypecutoff && Person::players[k]->stunned <= 0))) { + if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 10 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5) && + distsqflat(&Person::players[i]->coords, &Person::players[k]->coords) < 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) { //TODO: refactor two huge similar ifs if (Person::players[i]->animTarget == jumpupanim && - Person::players[k]->animTarget != getupfrombackanim && - Person::players[k]->animTarget != getupfromfrontanim && - Animation::animations[Person::players[k]->animTarget].height == middleheight && - normaldotproduct(Person::players[i]->velocity, Person::players[k]->coords - Person::players[i]->coords) < 0 && - ((Person::players[k]->aitype == playercontrolled && Person::players[k]->attackkeydown) || - Person::players[k]->aitype != playercontrolled)) { + Person::players[k]->animTarget != getupfrombackanim && + Person::players[k]->animTarget != getupfromfrontanim && + Animation::animations[Person::players[k]->animTarget].height == middleheight && + normaldotproduct(Person::players[i]->velocity, Person::players[k]->coords - Person::players[i]->coords) < 0 && + ((Person::players[k]->aitype == playercontrolled && Person::players[k]->attackkeydown) || + Person::players[k]->aitype != playercontrolled)) { Person::players[i]->victim = Person::players[k]; Person::players[i]->velocity = 0; Person::players[i]->animCurrent = jumpreversedanim; @@ -1646,12 +1632,12 @@ void doJumpReversals() Person::players[k]->stunned = .5; } if (Person::players[k]->animTarget == jumpupanim && - Person::players[i]->animTarget != getupfrombackanim && - Person::players[i]->animTarget != getupfromfrontanim && - Animation::animations[Person::players[i]->animTarget].height == middleheight && - normaldotproduct(Person::players[k]->velocity, Person::players[i]->coords - Person::players[k]->coords) < 0 && - ((Person::players[i]->aitype == playercontrolled && Person::players[i]->attackkeydown) || - Person::players[i]->aitype != playercontrolled)) { + Person::players[i]->animTarget != getupfrombackanim && + Person::players[i]->animTarget != getupfromfrontanim && + Animation::animations[Person::players[i]->animTarget].height == middleheight && + normaldotproduct(Person::players[k]->velocity, Person::players[i]->coords - Person::players[k]->coords) < 0 && + ((Person::players[i]->aitype == playercontrolled && Person::players[i]->attackkeydown) || + Person::players[i]->aitype != playercontrolled)) { Person::players[k]->victim = Person::players[i]; Person::players[k]->velocity = 0; Person::players[k]->animCurrent = jumpreversedanim; @@ -1697,30 +1683,29 @@ void doAerialAcrobatics() Person::players[k]->turnspeed = 500; if ((Person::players[k]->isRun() && - ((Person::players[k]->targetyaw != rabbitrunninganim && - Person::players[k]->targetyaw != wolfrunninganim) || - Person::players[k]->frameTarget == 4)) || - Person::players[k]->animTarget == removeknifeanim || - Person::players[k]->animTarget == crouchremoveknifeanim || - Person::players[k]->animTarget == flipanim || - Person::players[k]->animTarget == fightsidestep || - Person::players[k]->animTarget == walkanim) { + ((Person::players[k]->targetyaw != rabbitrunninganim && + Person::players[k]->targetyaw != wolfrunninganim) || + Person::players[k]->frameTarget == 4)) || + Person::players[k]->animTarget == removeknifeanim || + Person::players[k]->animTarget == crouchremoveknifeanim || + Person::players[k]->animTarget == flipanim || + Person::players[k]->animTarget == fightsidestep || + Person::players[k]->animTarget == walkanim) { Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed); } - if (Person::players[k]->isStop() || - Person::players[k]->isLanding() || - Person::players[k]->animTarget == staggerbackhighanim || - (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent == sneakanim) || - Person::players[k]->animTarget == staggerbackhardanim || - Person::players[k]->animTarget == backhandspringanim || - Person::players[k]->animTarget == dodgebackanim || - Person::players[k]->animTarget == rollanim || - (Animation::animations[Person::players[k]->animTarget].attack && - Person::players[k]->animTarget != rabbitkickanim && - (Person::players[k]->animTarget != crouchstabanim || Person::players[k]->hasvictim) && - (Person::players[k]->animTarget != swordgroundstabanim || Person::players[k]->hasvictim))) { + Person::players[k]->isLanding() || + Person::players[k]->animTarget == staggerbackhighanim || + (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent == sneakanim) || + Person::players[k]->animTarget == staggerbackhardanim || + Person::players[k]->animTarget == backhandspringanim || + Person::players[k]->animTarget == dodgebackanim || + Person::players[k]->animTarget == rollanim || + (Animation::animations[Person::players[k]->animTarget].attack && + Person::players[k]->animTarget != rabbitkickanim && + (Person::players[k]->animTarget != crouchstabanim || Person::players[k]->hasvictim) && + (Person::players[k]->animTarget != swordgroundstabanim || Person::players[k]->hasvictim))) { Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 2); } @@ -1734,9 +1719,9 @@ void doAerialAcrobatics() //if player's position has changed (?) if (distsq(&Person::players[k]->coords, &Person::players[k]->realoldcoords) > 0 && - !Person::players[k]->skeleton.free && - Person::players[k]->animTarget != climbanim && - Person::players[k]->animTarget != hanganim) { + !Person::players[k]->skeleton.free && + Person::players[k]->animTarget != climbanim && + Person::players[k]->animTarget != hanganim) { XYZ lowpoint, lowpointtarget, lowpoint2, lowpointtarget2, lowpoint3, lowpointtarget3, lowpoint4, lowpointtarget4, lowpoint5, lowpointtarget5, lowpoint6, lowpointtarget6, lowpoint7, lowpointtarget7, colpoint, colpoint2; int whichhit; bool tempcollide = 0; @@ -1753,17 +1738,17 @@ void doAerialAcrobatics() for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) { unsigned int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l]; if (Object::objects[i]->type != rocktype || - Object::objects[i]->scale > .5 && Person::players[k]->aitype == playercontrolled || - Object::objects[i]->position.y > Person::players[k]->coords.y) { + Object::objects[i]->scale > .5 && Person::players[k]->aitype == playercontrolled || + Object::objects[i]->position.y > Person::players[k]->coords.y) { lowpoint = Person::players[k]->coords; if (Person::players[k]->animTarget != jumpupanim && - Person::players[k]->animTarget != jumpdownanim && - !Person::players[k]->isFlip()) + Person::players[k]->animTarget != jumpdownanim && + !Person::players[k]->isFlip()) lowpoint.y += 1.25; 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) + 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); 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; @@ -1774,11 +1759,11 @@ void doAerialAcrobatics() //wall jumps //TODO: refactor four similar blocks if (Person::players[k]->aitype == playercontrolled && - (Person::players[k]->animTarget == jumpupanim || - Person::players[k]->animTarget == jumpdownanim || - Person::players[k]->isFlip()) && - !Person::players[k]->jumptogglekeydown && - Person::players[k]->jumpkeydown) { + (Person::players[k]->animTarget == jumpupanim || + Person::players[k]->animTarget == jumpdownanim || + Person::players[k]->isFlip()) && + !Person::players[k]->jumptogglekeydown && + Person::players[k]->jumpkeydown) { lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, -90, 0) * 1.5; XYZ tempcoords1 = lowpoint; whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw); @@ -1907,19 +1892,19 @@ void doAerialAcrobatics() 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]->animTarget != jumpdownanim && + 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; if ((Person::players[k]->grabdelay <= 0 || Person::players[k]->aitype != playercontrolled) && - (Person::players[k]->animCurrent != climbanim && + (Person::players[k]->animCurrent != climbanim && Person::players[k]->animCurrent != hanganim && !Person::players[k]->isWallJump() || - Person::players[k]->animTarget == jumpupanim || - Person::players[k]->animTarget == jumpdownanim)) { + Person::players[k]->animTarget == jumpupanim || + Person::players[k]->animTarget == jumpdownanim)) { lowpoint = Person::players[k]->coords; Object::objects[i]->model.SphereCheckPossible(&lowpoint, 1.5, &Object::objects[i]->position, &Object::objects[i]->yaw); lowpoint = Person::players[k]->coords; @@ -1964,20 +1949,20 @@ void doAerialAcrobatics() Person::players[k]->collided = 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, - &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 && - 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) + 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, + &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 && + 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) 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) { + &colpoint2, &Object::objects[i]->position, &Object::objects[i]->yaw) == -1) { if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) break; if (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim) { @@ -2033,18 +2018,18 @@ void doAerialAcrobatics() if (Person::players[k]->collide <= 0) { //in the air if (!Person::players[k]->onterrain && - Person::players[k]->animTarget != jumpupanim && - Person::players[k]->animTarget != jumpdownanim && - Person::players[k]->animTarget != climbanim && - Person::players[k]->animTarget != hanganim && - !Person::players[k]->isWallJump() && - !Person::players[k]->isFlip()) { + Person::players[k]->animTarget != jumpupanim && + Person::players[k]->animTarget != jumpdownanim && + Person::players[k]->animTarget != climbanim && + Person::players[k]->animTarget != hanganim && + !Person::players[k]->isWallJump() && + !Person::players[k]->isFlip()) { if (Person::players[k]->animCurrent != climbanim && - Person::players[k]->animCurrent != tempanim && - Person::players[k]->animTarget != backhandspringanim && - (Person::players[k]->animTarget != rollanim || - Person::players[k]->frameTarget < 2 || - Person::players[k]->frameTarget > 6)) { + Person::players[k]->animCurrent != tempanim && + Person::players[k]->animTarget != backhandspringanim && + (Person::players[k]->animTarget != rollanim || + Person::players[k]->frameTarget < 2 || + Person::players[k]->frameTarget > 6)) { //stagger off ledge (?) if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim) Person::players[k]->RagDoll(0); @@ -2076,23 +2061,23 @@ void doAttacks() if (!oldattackkey) playerrealattackkeydown = Input::isKeyDown(attackkey); if ((Person::players[0]->parriedrecently <= 0 || - Person::players[0]->weaponactive == -1) && - (!oldattackkey || - (realthreat && - Person::players[0]->lastattack != swordslashanim && - Person::players[0]->lastattack != knifeslashstartanim && - Person::players[0]->lastattack != staffhitanim && - Person::players[0]->lastattack != staffspinhitanim))) + Person::players[0]->weaponactive == -1) && + (!oldattackkey || + (realthreat && + Person::players[0]->lastattack != swordslashanim && + Person::players[0]->lastattack != knifeslashstartanim && + Person::players[0]->lastattack != staffhitanim && + Person::players[0]->lastattack != staffspinhitanim))) Person::players[0]->attackkeydown = Input::isKeyDown(attackkey); if (Input::isKeyDown(attackkey) && - !oldattackkey && - !Person::players[0]->backkeydown) { + !oldattackkey && + !Person::players[0]->backkeydown) { for (unsigned k = 0; k < Person::players.size(); k++) { if ((Person::players[k]->animTarget == swordslashanim || - Person::players[k]->animTarget == staffhitanim || - Person::players[k]->animTarget == staffspinhitanim) && - Person::players[0]->animCurrent != dodgebackanim && - !Person::players[k]->skeleton.free) + Person::players[k]->animTarget == staffhitanim || + Person::players[k]->animTarget == staffspinhitanim) && + Person::players[0]->animCurrent != dodgebackanim && + !Person::players[k]->skeleton.free) Person::players[k]->Reverse(); } } @@ -2110,11 +2095,11 @@ void doAttacks() if (Person::players[k]->attackkeydown) { //dodge backward if (Person::players[k]->backkeydown && - Person::players[k]->animTarget != backhandspringanim && - (Person::players[k]->isIdle() || - Person::players[k]->isStop() || - Person::players[k]->isRun() || - Person::players[k]->animTarget == walkanim)) { + Person::players[k]->animTarget != backhandspringanim && + (Person::players[k]->isIdle() || + Person::players[k]->isStop() || + Person::players[k]->isRun() || + Person::players[k]->animTarget == walkanim)) { if (Person::players[k]->jumppower <= 1) { Person::players[k]->jumppower -= 2; } else { @@ -2122,9 +2107,9 @@ void doAttacks() 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 == knifeslashstartanim || + Person::players[i]->animTarget == staffhitanim || + 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); @@ -2147,12 +2132,12 @@ void doAttacks() } //attack if (!Animation::animations[Person::players[k]->animTarget].attack && - !Person::players[k]->backkeydown && - (Person::players[k]->isIdle() || - Person::players[k]->isRun() || - Person::players[k]->animTarget == walkanim || - Person::players[k]->animTarget == sneakanim || - Person::players[k]->isCrouch())) { + !Person::players[k]->backkeydown && + (Person::players[k]->isIdle() || + Person::players[k]->isRun() || + Person::players[k]->animTarget == walkanim || + Person::players[k]->animTarget == sneakanim || + Person::players[k]->isCrouch())) { 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; @@ -2165,25 +2150,25 @@ void doAttacks() //choose an attack const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords); if (distance < 4.5 && - !Person::players[i]->skeleton.free && - Person::players[i]->howactive < typedead1 && - Person::players[i]->animTarget != jumpreversedanim && - Person::players[i]->animTarget != rabbitkickreversedanim && - Person::players[i]->animTarget != rabbitkickanim && - Person::players[k]->animTarget != rabbitkickanim && - Person::players[i]->animTarget != getupfrombackanim && - (Person::players[i]->animTarget != staggerbackhighanim && - (Person::players[i]->animTarget != staggerbackhardanim || Person::players[i]->targetFrame().label == 6)) && - Person::players[i]->animTarget != jumpdownanim && - Person::players[i]->animTarget != jumpupanim && - Person::players[i]->animTarget != getupfromfrontanim) { + !Person::players[i]->skeleton.free && + Person::players[i]->howactive < typedead1 && + Person::players[i]->animTarget != jumpreversedanim && + Person::players[i]->animTarget != rabbitkickreversedanim && + Person::players[i]->animTarget != rabbitkickanim && + Person::players[k]->animTarget != rabbitkickanim && + Person::players[i]->animTarget != getupfrombackanim && + (Person::players[i]->animTarget != staggerbackhighanim && + (Person::players[i]->animTarget != staggerbackhardanim || Person::players[i]->targetFrame().label == 6)) && + Person::players[i]->animTarget != jumpdownanim && + Person::players[i]->animTarget != jumpupanim && + Person::players[i]->animTarget != getupfromfrontanim) { Person::players[k]->victim = Person::players[i]; Person::players[k]->hasvictim = 1; if (Person::players[k]->aitype == playercontrolled) { //human player //sweep if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Person::players[k]->crouchkeydown && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + Person::players[k]->crouchkeydown && + 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) && @@ -2274,9 +2259,9 @@ void doAttacks() 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) + distance < 2.5 * sq(Person::players[k]->scale * 5) && + randattack == 0 && + 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) && @@ -2326,15 +2311,15 @@ void doAttacks() } //sneak attacks if ((k == 0) && (!Tutorial::active || Tutorial::stage == 22) && - Person::players[i]->howactive < typedead1 && - distance < 1.5 * sq(Person::players[k]->scale * 5) && - !Person::players[i]->skeleton.free && - Person::players[i]->animTarget != getupfrombackanim && - Person::players[i]->animTarget != getupfromfrontanim && - (Person::players[i]->surprised > 0 || - Person::players[i]->aitype == passivetype || - attackweapon && Person::players[i]->stunned > 0) && - normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[k]->coords) > 0) { + Person::players[i]->howactive < typedead1 && + distance < 1.5 * sq(Person::players[k]->scale * 5) && + !Person::players[i]->skeleton.free && + Person::players[i]->animTarget != getupfrombackanim && + Person::players[i]->animTarget != getupfromfrontanim && + (Person::players[i]->surprised > 0 || + Person::players[i]->aitype == passivetype || + attackweapon && Person::players[i]->stunned > 0) && + normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[k]->coords) > 0) { //sneakattack if (!attackweapon) { Person::players[k]->animCurrent = sneakattackanim; @@ -2381,8 +2366,8 @@ void doAttacks() } } if (Animation::animations[Person::players[k]->animTarget].attack == normalattack && - Person::players[k]->victim == Person::players[i] && - (!Person::players[i]->skeleton.free)) { + Person::players[k]->victim == Person::players[i] && + (!Person::players[i]->skeleton.free)) { oldattackkey = 1; Person::players[k]->frameTarget = 0; Person::players[k]->target = 0; @@ -2394,7 +2379,7 @@ void doAttacks() Person::players[k]->lastattack = Person::players[k]->animTarget; } if (Person::players[k]->animTarget == knifefollowanim && - Person::players[k]->victim == Person::players[i]) { + Person::players[k]->victim == Person::players[i]) { oldattackkey = 1; 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); @@ -2430,20 +2415,20 @@ void doAttacks() if (i == k) continue; if ((playerrealattackkeydown || Person::players[i]->dead || !hasstaff) && - Animation::animations[Person::players[k]->animTarget].attack == neutral) { + 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 (distance < 3.5 * sq(Person::players[k]->scale * 5) && - (Person::players[i]->dead || - Person::players[i]->skeleton.longdead > 1000 || - Person::players[k]->isRun() || - hasstaff || - (attackweapon && - (Person::players[i]->skeleton.longdead > 2000 || - Person::players[i]->damage > Person::players[i]->damagetolerance / 8 || - Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) && - distance < 1.5 * sq(Person::players[k]->scale * 5)))) { + (Person::players[i]->dead || + Person::players[i]->skeleton.longdead > 1000 || + Person::players[k]->isRun() || + hasstaff || + (attackweapon && + (Person::players[i]->skeleton.longdead > 2000 || + Person::players[i]->damage > Person::players[i]->damagetolerance / 8 || + Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) && + distance < 1.5 * sq(Person::players[k]->scale * 5)))) { Person::players[k]->victim = Person::players[i]; Person::players[k]->hasvictim = 1; if (attackweapon && !Tutorial::active) { @@ -2458,12 +2443,12 @@ void doAttacks() Person::players[k]->animTarget = staffgroundsmashanim; } if (distance < 2.5 && - Person::players[k]->crouchkeydown && - Person::players[k]->animTarget != crouchstabanim && - !attackweapon && - Person::players[i]->dead && - Person::players[i]->skeleton.free && - Person::players[i]->skeleton.longdead > 1000) { + Person::players[k]->crouchkeydown && + Person::players[k]->animTarget != crouchstabanim && + !attackweapon && + Person::players[i]->dead && + Person::players[i]->skeleton.free && + Person::players[i]->skeleton.longdead > 1000) { Person::players[k]->animTarget = killanim; terrain.deleteDeadDecals(); for (unsigned int l = 0; l < Object::objects.size(); l++) { @@ -2474,13 +2459,13 @@ void doAttacks() } 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 && - (Person::players[i]->dead || - Person::players[i]->skeleton.longdead < 300 && + (Person::players[k]->isRun() || Person::players[k]->isIdle() && Person::players[k]->attackkeydown) && + Person::players[k]->staggerdelay <= 0 && + (Person::players[i]->dead || + Person::players[i]->skeleton.longdead < 300 && Person::players[k]->lastattack != spinkickanim && Person::players[i]->skeleton.free) && - (!Person::players[i]->dead || musictype != stream_fighttheme)) { + (!Person::players[i]->dead || musictype != stream_fighttheme)) { Person::players[k]->animTarget = dropkickanim; terrain.deleteDeadDecals(); for (unsigned int l = 0; l < Object::objects.size(); l++) { @@ -2491,23 +2476,24 @@ void doAttacks() } } if (Animation::animations[Person::players[k]->animTarget].attack == normalattack && - Person::players[k]->victim == Person::players[i] && - (!Person::players[i]->skeleton.free || - Person::players[k]->animTarget == killanim || - Person::players[k]->animTarget == crouchstabanim || - Person::players[k]->animTarget == swordgroundstabanim || - Person::players[k]->animTarget == staffgroundsmashanim || - Person::players[k]->animTarget == dropkickanim)) { + Person::players[k]->victim == Person::players[i] && + (!Person::players[i]->skeleton.free || + Person::players[k]->animTarget == killanim || + Person::players[k]->animTarget == crouchstabanim || + Person::players[k]->animTarget == swordgroundstabanim || + Person::players[k]->animTarget == staffgroundsmashanim || + Person::players[k]->animTarget == dropkickanim)) { oldattackkey = 1; Person::players[k]->frameTarget = 0; Person::players[k]->target = 0; XYZ targetpoint = Person::players[i]->coords; if (Person::players[k]->animTarget == crouchstabanim || - Person::players[k]->animTarget == swordgroundstabanim || - Person::players[k]->animTarget == staffgroundsmashanim) { + Person::players[k]->animTarget == swordgroundstabanim || + Person::players[k]->animTarget == staffgroundsmashanim) { targetpoint += (Person::players[i]->jointPos(abdomen) + - Person::players[i]->jointPos(neck)) / 2 * + Person::players[i]->jointPos(neck)) / + 2 * Person::players[i]->scale; } Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, targetpoint); @@ -2538,7 +2524,7 @@ void doAttacks() 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]; @@ -2550,19 +2536,19 @@ void doAttacks() if (Person::players[k]->aitype == playercontrolled) //rabbit kick if (Person::players[k]->attackkeydown && - Person::players[k]->isRun() && - Person::players[k]->wasRun() && - ((Person::players[k]->hasvictim && - distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) < 12 * sq(Person::players[k]->scale * 5) && - distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) > 7 * sq(Person::players[k]->scale * 5) && - !Person::players[k]->victim->skeleton.free && - Person::players[k]->victim->animTarget != getupfrombackanim && - Person::players[k]->victim->animTarget != getupfromfrontanim && - Animation::animations[Person::players[k]->victim->animTarget].height != lowheight && - Person::players[k]->aitype != playercontrolled && //wat??? - normaldotproduct(Person::players[k]->facing, Person::players[k]->victim->coords - Person::players[k]->coords) > 0 && - Person::players[k]->rabbitkickenabled) || - Person::players[k]->jumpkeydown)) { + Person::players[k]->isRun() && + Person::players[k]->wasRun() && + ((Person::players[k]->hasvictim && + distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) < 12 * sq(Person::players[k]->scale * 5) && + distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) > 7 * sq(Person::players[k]->scale * 5) && + !Person::players[k]->victim->skeleton.free && + Person::players[k]->victim->animTarget != getupfrombackanim && + Person::players[k]->victim->animTarget != getupfromfrontanim && + Animation::animations[Person::players[k]->victim->animTarget].height != lowheight && + Person::players[k]->aitype != playercontrolled && //wat??? + normaldotproduct(Person::players[k]->facing, Person::players[k]->victim->coords - Person::players[k]->coords) > 0 && + Person::players[k]->rabbitkickenabled) || + Person::players[k]->jumpkeydown)) { oldattackkey = 1; Person::players[k]->setTargetAnimation(rabbitkickanim); } @@ -2570,18 +2556,18 @@ void doAttacks() if (Animation::animations[Person::players[k]->animTarget].attack && k == 0) { numattacks++; switch (attackweapon) { - case 0: - numunarmedattack++; - break; - case knife: - numknifeattack++; - break; - case sword: - numswordattack++; - break; - case staff: - numstaffattack++; - break; + case 0: + numunarmedattack++; + break; + case knife: + numknifeattack++; + break; + case sword: + numswordattack++; + break; + case staff: + numstaffattack++; + break; } } } @@ -2599,25 +2585,27 @@ void doPlayerCollisions() 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)) + 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)) 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)) + 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)) //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) //in same patch, neither is climbing if (Person::players[i]->whichpatchx == Person::players[k]->whichpatchx && - Person::players[i]->whichpatchz == Person::players[k]->whichpatchz && - Person::players[k]->skeleton.oldfree == Person::players[k]->skeleton.free && - Person::players[i]->skeleton.oldfree == Person::players[i]->skeleton.free && - Person::players[i]->animTarget != climbanim && - Person::players[i]->animTarget != hanganim && - Person::players[k]->animTarget != climbanim && - Person::players[k]->animTarget != hanganim) + Person::players[i]->whichpatchz == Person::players[k]->whichpatchz && + Person::players[k]->skeleton.oldfree == Person::players[k]->skeleton.free && + Person::players[i]->skeleton.oldfree == Person::players[i]->skeleton.free && + Person::players[i]->animTarget != climbanim && + Person::players[i]->animTarget != hanganim && + Person::players[k]->animTarget != climbanim && + 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) @@ -2626,8 +2614,7 @@ void doPlayerCollisions() 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 (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) Person::players[i]->CatchFire(); @@ -2647,20 +2634,20 @@ void doPlayerCollisions() 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)) { + (distsq(&tempcoords1, &tempcoords2) < collisionradius || + distsq(&Person::players[i]->coords, &Person::players[k]->coords) < collisionradius)) { //jump down on a dead body if (k == 0 || i == 0) { int l = i ? i : k; if (Person::players[0]->animTarget == jumpdownanim && - !Person::players[0]->skeleton.oldfree && - !Person::players[0]->skeleton.free && - Person::players[l]->skeleton.oldfree && - Person::players[l]->skeleton.free && - Person::players[l]->dead && - Person::players[0]->lastcollide <= 0 && - fabs(Person::players[l]->coords.y - Person::players[0]->coords.y) < .2 && - distsq(&Person::players[0]->coords, &Person::players[l]->coords) < .7 * sq((Person::players[l]->scale + Person::players[0]->scale) * 2.5)) { + !Person::players[0]->skeleton.oldfree && + !Person::players[0]->skeleton.free && + Person::players[l]->skeleton.oldfree && + Person::players[l]->skeleton.free && + Person::players[l]->dead && + Person::players[0]->lastcollide <= 0 && + fabs(Person::players[l]->coords.y - Person::players[0]->coords.y) < .2 && + distsq(&Person::players[0]->coords, &Person::players[l]->coords) < .7 * sq((Person::players[l]->scale + Person::players[0]->scale) * 2.5)) { Person::players[0]->coords.y = Person::players[l]->coords.y; Person::players[l]->velocity = Person::players[0]->velocity; Person::players[l]->skeleton.free = 0; @@ -2673,28 +2660,28 @@ void doPlayerCollisions() } } - if ( (Person::players[i]->skeleton.oldfree == 1 && findLengthfast(&Person::players[i]->velocity) > 1) || - (Person::players[k]->skeleton.oldfree == 1 && findLengthfast(&Person::players[k]->velocity) > 1) || - (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0)) { + if ((Person::players[i]->skeleton.oldfree == 1 && findLengthfast(&Person::players[i]->velocity) > 1) || + (Person::players[k]->skeleton.oldfree == 1 && findLengthfast(&Person::players[k]->velocity) > 1) || + (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0)) { rotatetarget = Person::players[k]->velocity - Person::players[i]->velocity; 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[i]->skeleton.free) && + (Person::players[k]->animTarget != getupfrombackanim && Person::players[k]->animTarget != getupfromfrontanim || + 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) && - (k == 0 || - k != 0 && Person::players[i]->skeleton.oldfree == 1 && Animation::animations[Person::players[k]->animCurrent].attack == neutral || - /*i!=0&&*/Person::players[k]->skeleton.oldfree == 1 && Animation::animations[Person::players[i]->animCurrent].attack == neutral)) || - (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) && + k == 0 && findLengthfast(&rotatetarget) > 50 && Person::players[0]->rabbitkickragdoll) && + normaldotproduct(rotatetarget, Person::players[k]->coords - Person::players[i]->coords) > 0) && + (k == 0 || + k != 0 && Person::players[i]->skeleton.oldfree == 1 && Animation::animations[Person::players[k]->animCurrent].attack == neutral || + /*i!=0&&*/ Person::players[k]->skeleton.oldfree == 1 && Animation::animations[Person::players[i]->animCurrent].attack == neutral)) || + (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) && (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) && k == 0 && !Person::players[i]->skeleton.oldfree && !Person::players[k]->skeleton.oldfree) { //If hit by body - if ( (i != 0 || Person::players[i]->skeleton.free) && - (k != 0 || Person::players[k]->skeleton.free) || - (Animation::animations[Person::players[i]->animTarget].height == highheight && - Animation::animations[Person::players[k]->animTarget].height == highheight)) { + if ((i != 0 || Person::players[i]->skeleton.free) && + (k != 0 || Person::players[k]->skeleton.free) || + (Animation::animations[Person::players[i]->animTarget].height == highheight && + Animation::animations[Person::players[k]->animTarget].height == highheight)) { if (!Tutorial::active) { emit_sound_at(heavyimpactsound, Person::players[i]->coords); } @@ -2716,21 +2703,19 @@ void doPlayerCollisions() for (unsigned j = 0; j < Person::players[k]->skeleton.joints.size(); j++) { Person::players[k]->skeleton.joints[j].velocity = Person::players[k]->skeleton.joints[j].velocity / 5 + Person::players[i]->velocity; } - } } - 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 || - Animation::animations[Person::players[k]->animTarget].attack == normalattack)) { + 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 || + Animation::animations[Person::players[k]->animTarget].attack == normalattack)) { //If bumped if (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0) { if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < .5 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) { rotatetarget = Person::players[k]->coords - Person::players[i]->coords; Normalise(&rotatetarget); 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[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]->isIdle()) { @@ -2754,12 +2739,11 @@ void doPlayerCollisions() //jump down on player if (hostile) { if (k == 0 && i != 0 && Person::players[k]->animTarget == jumpdownanim && - !Person::players[i]->isCrouch() && - Person::players[i]->animTarget != rollanim && - !Person::players[k]->skeleton.oldfree && ! - Person::players[k]->skeleton.free && - Person::players[k]->lastcollide <= 0 && - Person::players[k]->velocity.y < -10) { + !Person::players[i]->isCrouch() && + Person::players[i]->animTarget != rollanim && + !Person::players[k]->skeleton.oldfree && !Person::players[k]->skeleton.free && + Person::players[k]->lastcollide <= 0 && + Person::players[k]->velocity.y < -10) { Person::players[i]->velocity = Person::players[k]->velocity; Person::players[k]->velocity = Person::players[k]->velocity * -.5; Person::players[k]->velocity.y = Person::players[i]->velocity.y; @@ -2769,12 +2753,12 @@ void doPlayerCollisions() award_bonus(k, AboveBonus); } if (i == 0 && k != 0 && Person::players[i]->animTarget == jumpdownanim && - !Person::players[k]->isCrouch() && - Person::players[k]->animTarget != rollanim && - !Person::players[i]->skeleton.oldfree && - !Person::players[i]->skeleton.free && - Person::players[i]->lastcollide <= 0 && - Person::players[i]->velocity.y < -10) { + !Person::players[k]->isCrouch() && + Person::players[k]->animTarget != rollanim && + !Person::players[i]->skeleton.oldfree && + !Person::players[i]->skeleton.free && + Person::players[i]->lastcollide <= 0 && + Person::players[i]->velocity.y < -10) { Person::players[k]->velocity = Person::players[i]->velocity; Person::players[i]->velocity = Person::players[i]->velocity * -.3; Person::players[i]->velocity.y = Person::players[k]->velocity.y; @@ -2829,7 +2813,6 @@ void Game::Tick() printf("Stereo separation increased to %f\n", stereoseparation); } - if (Input::isKeyPressed(SDL_SCANCODE_TAB) && Tutorial::active) { if (Tutorial::stage != 51) { Tutorial::stagetime = Tutorial::maxtime; @@ -2873,7 +2856,7 @@ void Game::Tick() } //escape key pressed if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) && - (gameon || mainmenu == 0)) { + (gameon || mainmenu == 0)) { selected = -1; if (mainmenu == 0 && !winfreeze) mainmenu = 2; //pause @@ -2969,8 +2952,6 @@ void Game::Tick() } } - - if (!freeze && !winfreeze && !(mainmenu && gameon) && (gameon || !gamestarted)) { //dialogues @@ -3027,11 +3008,11 @@ void Game::Tick() //bonuses if (!Tutorial::active) { if (bonustime == 0 && - bonus != solidhit && - bonus != spinecrusher && - bonus != tracheotomy && - bonus != backstab && - bonusvalue > 10) { + bonus != solidhit && + bonus != spinecrusher && + bonus != tracheotomy && + bonus != backstab && + bonusvalue > 10) { emit_sound_np(consolesuccesssound); } } else if (bonustime == 0) { @@ -3039,10 +3020,10 @@ void Game::Tick() } if (bonustime == 0) { if (bonus != solidhit && - bonus != twoxcombo && - bonus != threexcombo && - bonus != fourxcombo && - bonus != megacombo) + bonus != twoxcombo && + bonus != threexcombo && + bonus != fourxcombo && + bonus != megacombo) bonusnum[bonus]++; else bonusnum[bonus] += 0.15; @@ -3071,10 +3052,8 @@ void Game::Tick() } } - doAerialAcrobatics(); - static XYZ oldviewer; //control keys @@ -3101,7 +3080,6 @@ void Game::Tick() if (!Person::players[0]->jumpkeydown) Person::players[0]->jumpclimb = 0; - if (Dialog::inDialog()) { cameramode = 1; if (Dialog::directing) { @@ -3128,28 +3106,38 @@ void Game::Tick() viewer.y += multiplier * 4; if (Input::isKeyDown(crouchkey)) viewer.y -= multiplier * 4; - if ( Input::isKeyPressed(SDL_SCANCODE_1) || - Input::isKeyPressed(SDL_SCANCODE_2) || - Input::isKeyPressed(SDL_SCANCODE_3) || - Input::isKeyPressed(SDL_SCANCODE_4) || - Input::isKeyPressed(SDL_SCANCODE_5) || - Input::isKeyPressed(SDL_SCANCODE_6) || - Input::isKeyPressed(SDL_SCANCODE_7) || - Input::isKeyPressed(SDL_SCANCODE_8) || - Input::isKeyPressed(SDL_SCANCODE_9) || - Input::isKeyPressed(SDL_SCANCODE_0) || - Input::isKeyPressed(SDL_SCANCODE_MINUS)) { + if (Input::isKeyPressed(SDL_SCANCODE_1) || + Input::isKeyPressed(SDL_SCANCODE_2) || + Input::isKeyPressed(SDL_SCANCODE_3) || + Input::isKeyPressed(SDL_SCANCODE_4) || + Input::isKeyPressed(SDL_SCANCODE_5) || + Input::isKeyPressed(SDL_SCANCODE_6) || + Input::isKeyPressed(SDL_SCANCODE_7) || + Input::isKeyPressed(SDL_SCANCODE_8) || + Input::isKeyPressed(SDL_SCANCODE_9) || + Input::isKeyPressed(SDL_SCANCODE_0) || + Input::isKeyPressed(SDL_SCANCODE_MINUS)) { int whichend; - if (Input::isKeyPressed(SDL_SCANCODE_1)) whichend = 1; - if (Input::isKeyPressed(SDL_SCANCODE_2)) whichend = 2; - if (Input::isKeyPressed(SDL_SCANCODE_3)) whichend = 3; - if (Input::isKeyPressed(SDL_SCANCODE_4)) whichend = 4; - if (Input::isKeyPressed(SDL_SCANCODE_5)) whichend = 5; - if (Input::isKeyPressed(SDL_SCANCODE_6)) whichend = 6; - if (Input::isKeyPressed(SDL_SCANCODE_7)) whichend = 7; - if (Input::isKeyPressed(SDL_SCANCODE_8)) whichend = 8; - if (Input::isKeyPressed(SDL_SCANCODE_9)) whichend = 9; - if (Input::isKeyPressed(SDL_SCANCODE_0)) whichend = 0; + if (Input::isKeyPressed(SDL_SCANCODE_1)) + whichend = 1; + if (Input::isKeyPressed(SDL_SCANCODE_2)) + whichend = 2; + if (Input::isKeyPressed(SDL_SCANCODE_3)) + whichend = 3; + if (Input::isKeyPressed(SDL_SCANCODE_4)) + whichend = 4; + if (Input::isKeyPressed(SDL_SCANCODE_5)) + whichend = 5; + if (Input::isKeyPressed(SDL_SCANCODE_6)) + whichend = 6; + if (Input::isKeyPressed(SDL_SCANCODE_7)) + whichend = 7; + if (Input::isKeyPressed(SDL_SCANCODE_8)) + whichend = 8; + if (Input::isKeyPressed(SDL_SCANCODE_9)) + whichend = 9; + if (Input::isKeyPressed(SDL_SCANCODE_0)) + whichend = 0; if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) whichend = -1; if (whichend != -1) { @@ -3181,27 +3169,37 @@ void Game::Tick() } } //TODO: should these be KeyDown or KeyPressed? - if ( Input::isKeyDown(SDL_SCANCODE_KP_1) || - Input::isKeyDown(SDL_SCANCODE_KP_2) || - Input::isKeyDown(SDL_SCANCODE_KP_3) || - Input::isKeyDown(SDL_SCANCODE_KP_4) || - Input::isKeyDown(SDL_SCANCODE_KP_5) || - Input::isKeyDown(SDL_SCANCODE_KP_6) || - Input::isKeyDown(SDL_SCANCODE_KP_7) || - Input::isKeyDown(SDL_SCANCODE_KP_8) || - Input::isKeyDown(SDL_SCANCODE_KP_9) || - Input::isKeyDown(SDL_SCANCODE_KP_0)) { + if (Input::isKeyDown(SDL_SCANCODE_KP_1) || + Input::isKeyDown(SDL_SCANCODE_KP_2) || + Input::isKeyDown(SDL_SCANCODE_KP_3) || + Input::isKeyDown(SDL_SCANCODE_KP_4) || + Input::isKeyDown(SDL_SCANCODE_KP_5) || + Input::isKeyDown(SDL_SCANCODE_KP_6) || + Input::isKeyDown(SDL_SCANCODE_KP_7) || + Input::isKeyDown(SDL_SCANCODE_KP_8) || + Input::isKeyDown(SDL_SCANCODE_KP_9) || + Input::isKeyDown(SDL_SCANCODE_KP_0)) { int whichend; - if (Input::isKeyDown(SDL_SCANCODE_KP_1)) whichend = 1; - if (Input::isKeyDown(SDL_SCANCODE_KP_2)) whichend = 2; - if (Input::isKeyDown(SDL_SCANCODE_KP_3)) whichend = 3; - if (Input::isKeyDown(SDL_SCANCODE_KP_4)) whichend = 4; - if (Input::isKeyDown(SDL_SCANCODE_KP_5)) whichend = 5; - if (Input::isKeyDown(SDL_SCANCODE_KP_6)) whichend = 6; - if (Input::isKeyDown(SDL_SCANCODE_KP_7)) whichend = 7; - if (Input::isKeyDown(SDL_SCANCODE_KP_8)) whichend = 8; - if (Input::isKeyDown(SDL_SCANCODE_KP_9)) whichend = 9; - if (Input::isKeyDown(SDL_SCANCODE_KP_0)) whichend = 0; + if (Input::isKeyDown(SDL_SCANCODE_KP_1)) + whichend = 1; + if (Input::isKeyDown(SDL_SCANCODE_KP_2)) + whichend = 2; + if (Input::isKeyDown(SDL_SCANCODE_KP_3)) + whichend = 3; + if (Input::isKeyDown(SDL_SCANCODE_KP_4)) + whichend = 4; + if (Input::isKeyDown(SDL_SCANCODE_KP_5)) + whichend = 5; + if (Input::isKeyDown(SDL_SCANCODE_KP_6)) + whichend = 6; + if (Input::isKeyDown(SDL_SCANCODE_KP_7)) + whichend = 7; + if (Input::isKeyDown(SDL_SCANCODE_KP_8)) + whichend = 8; + if (Input::isKeyDown(SDL_SCANCODE_KP_9)) + whichend = 9; + if (Input::isKeyDown(SDL_SCANCODE_KP_0)) + whichend = 0; Dialog::currentScene().participantfacing[whichend] = facing; } if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) { @@ -3262,12 +3260,11 @@ void Game::Tick() Person::players[0]->jumptogglekeydown = 0; } if (Person::players[0]->jumpkeydown && - Person::players[0]->animTarget != jumpupanim && - Person::players[0]->animTarget != jumpdownanim && - !Person::players[0]->isFlip()) + Person::players[0]->animTarget != jumpupanim && + Person::players[0]->animTarget != jumpdownanim && + !Person::players[0]->isFlip()) Person::players[0]->jumptogglekeydown = 1; - Dialog::dialoguetime += multiplier; hawkyaw += multiplier * 25; realhawkcoords = 0; @@ -3304,21 +3301,20 @@ void Game::Tick() //respawn static bool respawnkeydown; if (!editorenabled && - (whichlevel != -2 && + (whichlevel != -2 && (Input::isKeyDown(SDL_SCANCODE_Z) && Input::isKeyDown(SDL_SCANCODE_LGUI) && devtools) || - (Input::isKeyDown(jumpkey) && - !respawnkeydown && - !oldattackkey && - Person::players[0]->dead))) { + (Input::isKeyDown(jumpkey) && + !respawnkeydown && + !oldattackkey && + Person::players[0]->dead))) { targetlevel = whichlevel; loading = 1; leveltime = 5; } respawnkeydown = Input::isKeyDown(jumpkey); - static bool movekey; //? @@ -3329,14 +3325,14 @@ void Game::Tick() if (i == 0 && !Dialog::inDialog()) { //TODO: refactor repetitive code if (!Animation::animations[Person::players[0]->animTarget].attack && - Person::players[0]->animTarget != staggerbackhighanim && - Person::players[0]->animTarget != staggerbackhardanim && - Person::players[0]->animTarget != crouchremoveknifeanim && - Person::players[0]->animTarget != removeknifeanim && - Person::players[0]->animTarget != backhandspringanim && - Person::players[0]->animTarget != dodgebackanim && - Person::players[0]->animTarget != walljumprightkickanim && - Person::players[0]->animTarget != walljumpleftkickanim) { + Person::players[0]->animTarget != staggerbackhighanim && + Person::players[0]->animTarget != staggerbackhardanim && + Person::players[0]->animTarget != crouchremoveknifeanim && + Person::players[0]->animTarget != removeknifeanim && + Person::players[0]->animTarget != backhandspringanim && + Person::players[0]->animTarget != dodgebackanim && + Person::players[0]->animTarget != walljumprightkickanim && + Person::players[0]->animTarget != walljumpleftkickanim) { if (cameramode) Person::players[0]->targetyaw = 0; else @@ -3361,14 +3357,14 @@ void Game::Tick() } if (i != 0 && Person::players[i]->aitype == playercontrolled && !Dialog::inDialog()) { if (!Animation::animations[Person::players[i]->animTarget].attack && - Person::players[i]->animTarget != staggerbackhighanim && - Person::players[i]->animTarget != staggerbackhardanim && - Person::players[i]->animTarget != crouchremoveknifeanim && - Person::players[i]->animTarget != removeknifeanim && - Person::players[i]->animTarget != backhandspringanim && - Person::players[i]->animTarget != dodgebackanim && - Person::players[i]->animTarget != walljumprightkickanim && - Person::players[i]->animTarget != walljumpleftkickanim) { + Person::players[i]->animTarget != staggerbackhighanim && + Person::players[i]->animTarget != staggerbackhardanim && + Person::players[i]->animTarget != crouchremoveknifeanim && + Person::players[i]->animTarget != removeknifeanim && + Person::players[i]->animTarget != backhandspringanim && + Person::players[i]->animTarget != dodgebackanim && + Person::players[i]->animTarget != walljumprightkickanim && + Person::players[i]->animTarget != walljumpleftkickanim) { Person::players[i]->targetyaw = -Person::players[i]->lookyaw + 180; } @@ -3397,12 +3393,12 @@ void Game::Tick() 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)) { + if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < + distsq(&Person::players[i]->coords, &Person::players[0]->coords)) { Person::players[i]->collided = 0; Person::players[i]->avoidcollided = 1; if (Person::players[i]->avoidsomething == 0 || - distsq(&Person::players[i]->coords, &Object::objects[j]->position) < + distsq(&Person::players[i]->coords, &Object::objects[j]->position) < distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) { Person::players[i]->avoidwhere = Object::objects[j]->position; Person::players[i]->avoidsomething = 1; @@ -3413,12 +3409,12 @@ void Game::Tick() 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)) { + if (distsq(&Person::players[i]->coords, &Person::players[j]->coords) < + distsq(&Person::players[i]->coords, &Person::players[0]->coords)) { Person::players[i]->collided = 0; Person::players[i]->avoidcollided = 1; if (Person::players[i]->avoidsomething == 0 || - distsq(&Person::players[i]->coords, &Person::players[j]->coords) < + distsq(&Person::players[i]->coords, &Person::players[j]->coords) < distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) { Person::players[i]->avoidwhere = Person::players[j]->coords; Person::players[i]->avoidsomething = 1; @@ -3472,10 +3468,10 @@ void Game::Tick() Person::players[i]->surprised -= multiplier; } if (i != 0 && Person::players[i]->surprised <= 0 && - Person::players[i]->aitype == attacktypecutoff && - !Person::players[i]->dead && - !Person::players[i]->skeleton.free && - Animation::animations[Person::players[i]->animTarget].attack == neutral) + Person::players[i]->aitype == attacktypecutoff && + !Person::players[i]->dead && + !Person::players[i]->skeleton.free && + Animation::animations[Person::players[i]->animTarget].attack == neutral) numresponded = 1; if (!Person::players[i]->throwkeydown) @@ -3484,26 +3480,26 @@ void Game::Tick() //pick up weapon if (Person::players[i]->throwkeydown && !Person::players[i]->throwtogglekeydown) { if (Person::players[i]->weaponactive == -1 && - Person::players[i]->num_weapons < 2 && - (Person::players[i]->isIdle() || - Person::players[i]->isCrouch() || - Person::players[i]->animTarget == sneakanim || - Person::players[i]->animTarget == rollanim || - Person::players[i]->animTarget == backhandspringanim || - Person::players[i]->isFlip() || - Person::players[i]->aitype != playercontrolled)) { + Person::players[i]->num_weapons < 2 && + (Person::players[i]->isIdle() || + Person::players[i]->isCrouch() || + Person::players[i]->animTarget == sneakanim || + Person::players[i]->animTarget == rollanim || + Person::players[i]->animTarget == backhandspringanim || + Person::players[i]->isFlip() || + Person::players[i]->aitype != playercontrolled)) { for (unsigned j = 0; j < weapons.size(); j++) { 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]->aitype == playercontrolled) && + weapons[j].owner == -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() || - Person::players[i]->animTarget == sneakanim || - Person::players[i]->isRun() || - Person::players[i]->isIdle() || - Person::players[i]->aitype != playercontrolled) { + Person::players[i]->animTarget == sneakanim || + Person::players[i]->isRun() || + Person::players[i]->isIdle() || + Person::players[i]->aitype != playercontrolled) { Person::players[i]->throwtogglekeydown = 1; Person::players[i]->setTargetAnimation(crouchremoveknifeanim); Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position); @@ -3514,9 +3510,9 @@ void Game::Tick() Person::players[i]->hasvictim = 0; if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 || - Person::players[i]->aitype == playercontrolled) && + Person::players[i]->aitype == playercontrolled) && weapons[j].owner == -1 || - Person::players[i]->victim && + 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) if (distsq(&Person::players[i]->coords, &weapons[j].position) < 1 || Person::players[i]->victim) { @@ -3543,12 +3539,12 @@ void Game::Tick() for (unsigned k = 0; k < weapons.size(); k++) { 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) && + Person::players[i]->aitype == playercontrolled) && weapons[k].owner == -1 || - Person::players[i]->victim && + Person::players[i]->victim && weapons[k].owner == int(Person::players[i]->victim->id)) if (distsqflat(&Person::players[i]->coords, &weapons[k].position) < 3 && - Person::players[i]->weaponactive == -1) { + Person::players[i]->weaponactive == -1) { if (weapons[k].getType() != staff) emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); @@ -3560,23 +3556,23 @@ void Game::Tick() } } 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) { + 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) for (unsigned j = 0; j < Person::players.size(); j++) { 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*/ && - (((Person::players[j]->skeleton.forward.y < 0 && - Person::players[j]->weaponstuckwhere == 0) || - (Person::players[j]->skeleton.forward.y > 0 && - Person::players[j]->weaponstuckwhere == 1)) || - Person::players[j]->weaponstuck == -1 || - Person::players[j]->num_weapons > 1)) { + Person::players[j]->skeleton.free && + distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 2 /*&&Person::players[j]->dead*/ && + (((Person::players[j]->skeleton.forward.y < 0 && + Person::players[j]->weaponstuckwhere == 0) || + (Person::players[j]->skeleton.forward.y > 0 && + Person::players[j]->weaponstuckwhere == 1)) || + Person::players[j]->weaponstuck == -1 || + Person::players[j]->num_weapons > 1)) { if (Person::players[i]->animTarget != rollanim && Person::players[i]->animTarget != backhandspringanim) { Person::players[i]->throwtogglekeydown = 1; Person::players[i]->victim = Person::players[j]; @@ -3661,20 +3657,20 @@ void Game::Tick() if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) { if (weapons[Person::players[i]->weaponids[0]].getType() == knife) { if (Person::players[i]->isIdle() || - Person::players[i]->isRun() || - Person::players[i]->isCrouch() || - Person::players[i]->animTarget == sneakanim || - Person::players[i]->isFlip()) + Person::players[i]->isRun() || + Person::players[i]->isCrouch() || + Person::players[i]->animTarget == sneakanim || + 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 (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 && - !Person::players[j]->skeleton.free && - -1 == Object::checkcollide(DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0)*Person::players[j]->scale + Person::players[j]->coords, DoRotation(Person::players[i]->jointPos(head), 0, Person::players[i]->yaw, 0)*Person::players[i]->scale + Person::players[i]->coords)) { + distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 100 && + distsq(&Person::players[i]->coords, &Person::players[j]->coords) > 1.5 && + !Person::players[j]->skeleton.free && + -1 == Object::checkcollide(DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0) * Person::players[j]->scale + Person::players[j]->coords, DoRotation(Person::players[i]->jointPos(head), 0, Person::players[i]->yaw, 0) * Person::players[i]->scale + Person::players[i]->coords)) { if (!Person::players[i]->isFlip()) { Person::players[i]->throwtogglekeydown = 1; Person::players[i]->victim = Person::players[j]; @@ -3724,16 +3720,15 @@ void Game::Tick() } } } - } //draw weapon if (i == 0 || !Person::players[0]->dead || (Person::players[i]->weaponactive != -1)) { if (Person::players[i]->drawkeydown && !Person::players[i]->drawtogglekeydown || - (Person::players[i]->num_weapons == 2) && + (Person::players[i]->num_weapons == 2) && (Person::players[i]->weaponactive == -1) && Person::players[i]->isIdle() || - Person::players[0]->dead && + Person::players[0]->dead && (Person::players[i]->weaponactive != -1) && i != 0) { bool isgood = true; @@ -3746,11 +3741,11 @@ void Game::Tick() Person::players[i]->drawtogglekeydown = 1; } if ((Person::players[i]->isIdle() || - (Person::players[i]->aitype != playercontrolled && - Person::players[0]->weaponactive != -1 && - Person::players[i]->isRun())) && - Person::players[i]->num_weapons && - weapons[Person::players[i]->weaponids[0]].getType() == sword) { + (Person::players[i]->aitype != playercontrolled && + Person::players[0]->weaponactive != -1 && + Person::players[i]->isRun())) && + Person::players[i]->num_weapons && + weapons[Person::players[i]->weaponids[0]].getType() == sword) { Person::players[i]->setTargetAnimation(drawleftanim); Person::players[i]->drawtogglekeydown = 1; } @@ -3765,12 +3760,12 @@ void Game::Tick() //clean weapon if (Person::players[i]->weaponactive != -1) { if (Person::players[i]->isCrouch() && - weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].bloody && - bloodtoggle && - Person::players[i]->onterrain && - Person::players[i]->num_weapons && - Person::players[i]->attackkeydown && - musictype != stream_fighttheme) { + weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].bloody && + bloodtoggle && + Person::players[i]->onterrain && + Person::players[i]->num_weapons && + Person::players[i]->attackkeydown && + musictype != stream_fighttheme) { 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) @@ -3804,10 +3799,10 @@ void Game::Tick() movekey = 0; //Do controls if (!Animation::animations[Person::players[i]->animTarget].attack && - Person::players[i]->animTarget != staggerbackhighanim && - Person::players[i]->animTarget != staggerbackhardanim && - Person::players[i]->animTarget != backhandspringanim && - Person::players[i]->animTarget != dodgebackanim) { + Person::players[i]->animTarget != staggerbackhighanim && + Person::players[i]->animTarget != staggerbackhardanim && + Person::players[i]->animTarget != backhandspringanim && + Person::players[i]->animTarget != dodgebackanim) { if (!Person::players[i]->forwardkeydown) Person::players[i]->forwardstogglekeydown = 0; if (Person::players[i]->crouchkeydown) { @@ -3826,15 +3821,15 @@ void Game::Tick() 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 && - Person::players[j]->victim == Person::players[i] && - (Person::players[j]->animTarget == sweepanim || - Person::players[j]->animTarget == upunchanim || - Person::players[j]->animTarget == wolfslapanim || - ((Person::players[j]->animTarget == swordslashanim || - Person::players[j]->animTarget == knifeslashstartanim || - Person::players[j]->animTarget == staffhitanim || - Person::players[j]->animTarget == staffspinhitanim) && - distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2))) { + Person::players[j]->victim == Person::players[i] && + (Person::players[j]->animTarget == sweepanim || + Person::players[j]->animTarget == upunchanim || + Person::players[j]->animTarget == wolfslapanim || + ((Person::players[j]->animTarget == swordslashanim || + Person::players[j]->animTarget == knifeslashstartanim || + Person::players[j]->animTarget == staffhitanim || + Person::players[j]->animTarget == staffspinhitanim) && + distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2))) { if (target >= 0) target = -1; else @@ -3851,11 +3846,11 @@ void Game::Tick() Person::players[i]->transspeed = 10; } if (Person::players[i]->isRun() || - (Person::players[i]->isStop() && - (Person::players[i]->leftkeydown || - Person::players[i]->rightkeydown || - Person::players[i]->forwardkeydown || - Person::players[i]->backkeydown))) { + (Person::players[i]->isStop() && + (Person::players[i]->leftkeydown || + Person::players[i]->rightkeydown || + Person::players[i]->forwardkeydown || + Person::players[i]->backkeydown))) { Person::players[i]->setTargetAnimation(rollanim); Person::players[i]->transspeed = 20; } @@ -3869,13 +3864,13 @@ void Game::Tick() 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]->highreversaldelay <= 0) { + !Person::players[j]->skeleton.free && + Person::players[j]->victim && + Person::players[i]->highreversaldelay <= 0) { if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 && - Person::players[j]->victim == Person::players[i] && - (Person::players[j]->animTarget == spinkickanim) && - Person::players[i]->isCrouch()) { + Person::players[j]->victim == Person::players[i] && + (Person::players[j]->animTarget == spinkickanim) && + Person::players[i]->isCrouch()) { if (target >= 0) target = -1; else @@ -3903,15 +3898,15 @@ void Game::Tick() } if (Person::players[i]->forwardkeydown) { if (Person::players[i]->isIdle() || - (Person::players[i]->isStop() && - Person::players[i]->targetyaw == Person::players[i]->yaw) || - (Person::players[i]->isLanding() && - Person::players[i]->frameTarget > 0 && - !Person::players[i]->jumpkeydown) || - (Person::players[i]->isLandhard() && - Person::players[i]->frameTarget > 0 && - !Person::players[i]->jumpkeydown && - Person::players[i]->crouchkeydown)) { + (Person::players[i]->isStop() && + Person::players[i]->targetyaw == Person::players[i]->yaw) || + (Person::players[i]->isLanding() && + Person::players[i]->frameTarget > 0 && + !Person::players[i]->jumpkeydown) || + (Person::players[i]->isLandhard() && + Person::players[i]->frameTarget > 0 && + !Person::players[i]->jumpkeydown && + Person::players[i]->crouchkeydown)) { if (Person::players[i]->aitype == passivetype) Person::players[i]->setTargetAnimation(walkanim); else @@ -3923,7 +3918,7 @@ void Game::Tick() 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)*/) { + if (Person::players[i]->animTarget == hanganim /*&&(!Person::players[i]->forwardstogglekeydown||Person::players[i]->aitype!=playercontrolled)*/) { Person::players[i]->setTargetAnimation(climbanim); Person::players[i]->frameTarget = 1; Person::players[i]->jumpclimb = 1; @@ -3936,15 +3931,15 @@ void Game::Tick() } if (Person::players[i]->rightkeydown) { if (Person::players[i]->isIdle() || - (Person::players[i]->isStop() && - Person::players[i]->targetyaw == Person::players[i]->yaw) || - (Person::players[i]->isLanding() && - Person::players[i]->frameTarget > 0 && - !Person::players[i]->jumpkeydown) || - (Person::players[i]->isLandhard() && - Person::players[i]->frameTarget > 0 && - !Person::players[i]->jumpkeydown && - Person::players[i]->crouchkeydown)) { + (Person::players[i]->isStop() && + Person::players[i]->targetyaw == Person::players[i]->yaw) || + (Person::players[i]->isLanding() && + Person::players[i]->frameTarget > 0 && + !Person::players[i]->jumpkeydown) || + (Person::players[i]->isLandhard() && + Person::players[i]->frameTarget > 0 && + !Person::players[i]->jumpkeydown && + Person::players[i]->crouchkeydown)) { Person::players[i]->setTargetAnimation(Person::players[i]->getRun()); } if (Person::players[i]->isCrouch()) { @@ -3963,17 +3958,17 @@ void Game::Tick() Person::players[i]->targetyaw -= 45; movekey = 1; } - if ( Person::players[i]->leftkeydown) { + if (Person::players[i]->leftkeydown) { if (Person::players[i]->isIdle() || - (Person::players[i]->isStop() && - Person::players[i]->targetyaw == Person::players[i]->yaw) || - (Person::players[i]->isLanding() && - Person::players[i]->frameTarget > 0 && - !Person::players[i]->jumpkeydown) || - (Person::players[i]->isLandhard() && - Person::players[i]->frameTarget > 0 && - !Person::players[i]->jumpkeydown && - Person::players[i]->crouchkeydown)) { + (Person::players[i]->isStop() && + Person::players[i]->targetyaw == Person::players[i]->yaw) || + (Person::players[i]->isLanding() && + Person::players[i]->frameTarget > 0 && + !Person::players[i]->jumpkeydown) || + (Person::players[i]->isLandhard() && + Person::players[i]->frameTarget > 0 && + !Person::players[i]->jumpkeydown && + Person::players[i]->crouchkeydown)) { Person::players[i]->setTargetAnimation(Person::players[i]->getRun()); } if (Person::players[i]->isCrouch()) { @@ -3994,15 +3989,15 @@ void Game::Tick() } if (Person::players[i]->backkeydown) { if (Person::players[i]->isIdle() || - (Person::players[i]->isStop() && - Person::players[i]->targetyaw == Person::players[i]->yaw) || - (Person::players[i]->isLanding() && - Person::players[i]->frameTarget > 0 && - !Person::players[i]->jumpkeydown) || - (Person::players[i]->isLandhard() && - Person::players[i]->frameTarget > 0 && - !Person::players[i]->jumpkeydown && - Person::players[i]->crouchkeydown)) { + (Person::players[i]->isStop() && + Person::players[i]->targetyaw == Person::players[i]->yaw) || + (Person::players[i]->isLanding() && + Person::players[i]->frameTarget > 0 && + !Person::players[i]->jumpkeydown) || + (Person::players[i]->isLandhard() && + Person::players[i]->frameTarget > 0 && + !Person::players[i]->jumpkeydown && + Person::players[i]->crouchkeydown)) { Person::players[i]->setTargetAnimation(Person::players[i]->getRun()); } if (Person::players[i]->isCrouch()) { @@ -4025,19 +4020,20 @@ 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) { if ((((Person::players[i]->isLanding() && Person::players[i]->frameTarget >= 3) || - Person::players[i]->isRun() || - Person::players[i]->animTarget == walkanim || - Person::players[i]->isCrouch() || - Person::players[i]->animTarget == sneakanim) && - Person::players[i]->jumppower > 1) && - ((Person::players[i]->animTarget != rabbitrunninganim && - Person::players[i]->animTarget != wolfrunninganim) || i != 0)) { + Person::players[i]->isRun() || + Person::players[i]->animTarget == walkanim || + Person::players[i]->isCrouch() || + Person::players[i]->animTarget == sneakanim) && + Person::players[i]->jumppower > 1) && + ((Person::players[i]->animTarget != rabbitrunninganim && + Person::players[i]->animTarget != wolfrunninganim) || + i != 0)) { Person::players[i]->jumpstart = 0; Person::players[i]->setTargetAnimation(jumpupanim); Person::players[i]->yaw = Person::players[i]->targetyaw; @@ -4060,8 +4056,8 @@ void Game::Tick() 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)) { + (Person::players[j]->victim == Person::players[i]) && + (Person::players[j]->animTarget == sweepanim)) { if (target >= 0) target = -1; else @@ -4071,11 +4067,11 @@ void Game::Tick() } 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 Person::players[i]->velocity.y = 5; + } else + Person::players[i]->velocity.y = 5; if (mousejump && i == 0 && devtools) { if (!Person::players[i]->isLanding()) @@ -4100,10 +4096,10 @@ void Game::Tick() Person::players[i]->tempdeltav = deltav; } if (Person::players[i]->animTarget == jumpupanim && - (((!floatjump && - !editorenabled) || - !devtools) || - Person::players[i]->aitype != playercontrolled)) { + (((!floatjump && + !editorenabled) || + !devtools) || + Person::players[i]->aitype != playercontrolled)) { if (Person::players[i]->jumppower > multiplier * 6) { Person::players[i]->velocity.y += multiplier * 6; Person::players[i]->jumppower -= multiplier * 6; @@ -4130,10 +4126,10 @@ void Game::Tick() } } if (Person::players[i]->animTarget == walkanim && - (Person::players[i]->aitype == attacktypecutoff || - Person::players[i]->aitype == searchtype || - (Person::players[i]->aitype == passivetype && - Person::players[i]->numwaypoints <= 1))) + (Person::players[i]->aitype == attacktypecutoff || + Person::players[i]->aitype == searchtype || + (Person::players[i]->aitype == passivetype && + Person::players[i]->numwaypoints <= 1))) Person::players[i]->setTargetAnimation(Person::players[i]->getStop()); if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype)) Person::players[i]->setTargetAnimation(Person::players[i]->getStop()); @@ -4160,9 +4156,9 @@ void Game::Tick() 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]->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) Person::players[k]->jumppower = 0; @@ -4204,7 +4200,6 @@ void Game::Tick() Tutorial::DoStuff(multiplier); } - //3d sound static float gLoc[3]; gLoc[0] = viewer.x; @@ -4229,7 +4224,6 @@ void Game::Tick() facing = DoRotation(facing, -pitch, 0, 0); facing = DoRotation(facing, 0, 0 - yaw, 0); - static float ori[6]; ori[0] = -facing.x; ori[1] = facing.y; @@ -4294,13 +4288,13 @@ void Game::TickOnceAfter() musictype = leveltheme; for (unsigned i = 0; i < Person::players.size(); i++) { if ((Person::players[i]->aitype == attacktypecutoff || - Person::players[i]->aitype == getweapontype || - Person::players[i]->aitype == gethelptype || - Person::players[i]->aitype == searchtype) && - !Person::players[i]->dead && - (Person::players[i]->animTarget != sneakattackedanim && - Person::players[i]->animTarget != knifesneakattackedanim && - Person::players[i]->animTarget != swordsneakattackedanim)) { + Person::players[i]->aitype == getweapontype || + Person::players[i]->aitype == gethelptype || + Person::players[i]->aitype == searchtype) && + !Person::players[i]->dead && + (Person::players[i]->animTarget != sneakattackedanim && + Person::players[i]->animTarget != knifesneakattackedanim && + Person::players[i]->animTarget != swordsneakattackedanim)) { musictype = stream_fighttheme; realthreat = 1; } @@ -4308,7 +4302,6 @@ void Game::TickOnceAfter() if (Person::players[0]->dead) musictype = stream_menutheme; - if (musictype == stream_fighttheme) unseendelay = 1; @@ -4318,7 +4311,6 @@ void Game::TickOnceAfter() musictype = stream_fighttheme; } - if (loading == 2) { musictype = stream_menutheme; musicvolume[2] = 512; @@ -4401,7 +4393,6 @@ void Game::TickOnceAfter() if (Hotspot::killhotspot == 2) Hotspot::killhotspot = 0; - winhotspot = false; for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) { if (Hotspot::hotspots[i].type == -1) { @@ -4434,7 +4425,6 @@ void Game::TickOnceAfter() } } - if (alldead && !Person::players[0]->dead && maptype == mapkilleveryone) { changedelay = 1; targetlevel = whichlevel + 1; @@ -4448,7 +4438,6 @@ void Game::TickOnceAfter() targetlevel = 0; } - if (Hotspot::killhotspot) { changedelay = 1; targetlevel = whichlevel + 1; @@ -4511,19 +4500,19 @@ void Game::TickOnceAfter() loading = 3; } if (changedelay <= -999 && - whichlevel != -2 && - !loading && - (Person::players[0]->dead || - (alldead && maptype == mapkilleveryone) || - (winhotspot) || - (Hotspot::killhotspot))) + whichlevel != -2 && + !loading && + (Person::players[0]->dead || + (alldead && maptype == mapkilleveryone) || + (winhotspot) || + (Hotspot::killhotspot))) loading = 1; if ((Person::players[0]->dead || - (alldead && maptype == mapkilleveryone) || - (winhotspot) || - (windialogue) || - (Hotspot::killhotspot)) && - changedelay <= 0) { + (alldead && maptype == mapkilleveryone) || + (winhotspot) || + (windialogue) || + (Hotspot::killhotspot)) && + changedelay <= 0) { if (whichlevel != -2 && !loading && !Person::players[0]->dead) { winfreeze = true; changedelay = -999; @@ -4576,7 +4565,6 @@ void Game::TickOnceAfter() if (loading == 3) loading = 0; - } oldmusictype = musictype; @@ -4669,4 +4657,3 @@ void Game::TickOnceAfter() } } } - diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 9054955..bfbc7ce 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -57,7 +57,7 @@ float gravity = 0; Light light; Terrain terrain; -SDL_Window *sdlwindow; +SDL_Window* sdlwindow; int kTextureSize = 0; int detail = 0; @@ -67,8 +67,8 @@ float realtexdetail = 0; float playerdist = 0; int slomo = 0; float slomodelay = 0; -GLubyte bloodText[512 * 512 * 3] = {0}; -GLubyte wolfbloodText[512 * 512 * 3] = {0}; +GLubyte bloodText[512 * 512 * 3] = { 0 }; +GLubyte wolfbloodText[512 * 512 * 3] = { 0 }; int bloodtoggle = 0; float camerashake = 0; float woozy = 0; @@ -93,8 +93,8 @@ bool immediate = false; bool velocityblur = false; XYZ windvector; int mainmenu = 0; -int whichjointstartarray[26] = {0}; -int whichjointendarray[26] = {0}; +int whichjointstartarray[26] = { 0 }; +int whichjointendarray[26] = { 0 }; float smoketex = 0; @@ -126,15 +126,15 @@ int hostile = 0; float hostiletime = 0; XYZ envsound[30]; -float envsoundvol[30] = {0}; -float envsoundlife[30] = {0}; +float envsoundvol[30] = { 0 }; +float envsoundlife[30] = { 0 }; int numenvsounds; bool devtools = false; bool gamestarted = false; -StereoMode stereomode = stereoNone; +StereoMode stereomode = stereoNone; StereoMode newstereomode = stereoNone; float stereoseparation = 0.05; -bool stereoreverse = false; +bool stereoreverse = false; diff --git a/Source/Graphic/Decal.cpp b/Source/Graphic/Decal.cpp index 0857bef..7491d73 100644 --- a/Source/Graphic/Decal.cpp +++ b/Source/Graphic/Decal.cpp @@ -23,23 +23,23 @@ along with Lugaru. If not, see . #include "Environment/Terrain.hpp" #include "Graphic/Models.hpp" -Decal::Decal() : - position(), - type(shadowdecal), - opacity(0), - rotation(0), - alivetime(0), - brightness(0) +Decal::Decal() + : position() + , type(shadowdecal) + , opacity(0) + , rotation(0) + , alivetime(0) + , brightness(0) { } -Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, float _brightness, int whichx, int whichy, float size, const Terrain& terrain, bool first) : - position(_position), - type(_type), - opacity(_opacity), - rotation(_rotation), - alivetime(0), - brightness(_brightness) +Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, float _brightness, int whichx, int whichy, float size, const Terrain& terrain, bool first) + : position(_position) + , type(_type) + , opacity(_opacity) + , rotation(_rotation) + , alivetime(0) + , brightness(_brightness) { float placex, placez; placex = (float)whichx * terrain.scale + terrain.scale; @@ -71,7 +71,6 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f vertex[1].y = terrain.heightmap[whichx][whichy] * terrain.scale + .01; } - placex = (float)whichx * terrain.scale; placez = (float)whichy * terrain.scale + terrain.scale; @@ -95,13 +94,13 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f } } -Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, float size, const Model& model, int i, int which) : - position(_position), - type(_type), - opacity(_opacity), - rotation(_rotation), - alivetime(0), - brightness(0) +Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, float size, const Model& model, int i, int which) + : position(_position) + , type(_type) + , opacity(_opacity) + , rotation(_rotation) + , alivetime(0) + , brightness(0) { float placex, placez; if (which == 0) { @@ -115,7 +114,6 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f vertex[0].z = placez; vertex[0].y = model.getTriangleVertex(i, 0).y; - placex = model.getTriangleVertex(i, 1).x; placez = model.getTriangleVertex(i, 1).z; @@ -126,7 +124,6 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f vertex[1].z = placez; vertex[1].y = model.getTriangleVertex(i, 1).y; - placex = model.getTriangleVertex(i, 2).x; placez = model.getTriangleVertex(i, 2).z; @@ -147,7 +144,6 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f vertex[0].z = placez; vertex[0].y = placex; - placex = model.getTriangleVertex(i, 1).y; placez = model.getTriangleVertex(i, 1).z; @@ -158,7 +154,6 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f vertex[1].z = placez; vertex[1].y = placex; - placex = model.getTriangleVertex(i, 2).y; placez = model.getTriangleVertex(i, 2).z; @@ -179,7 +174,6 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f vertex[0].z = model.getTriangleVertex(i, 0).z; vertex[0].y = placez; - placex = model.getTriangleVertex(i, 1).x; placez = model.getTriangleVertex(i, 1).y; @@ -190,7 +184,6 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f vertex[1].z = model.getTriangleVertex(i, 1).z; vertex[1].y = placez; - placex = model.getTriangleVertex(i, 2).x; placez = model.getTriangleVertex(i, 2).y; diff --git a/Source/Graphic/Models.cpp b/Source/Graphic/Models.cpp index 09036ae..860957d 100644 --- a/Source/Graphic/Models.cpp +++ b/Source/Graphic/Models.cpp @@ -30,7 +30,7 @@ extern float fadestart; extern float texdetail; extern bool decalstoggle; -int Model::LineCheck(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate) +int Model::LineCheck(XYZ* p1, XYZ* p2, XYZ* p, XYZ* move, float* rotate) { static float distance; static float olddistance; @@ -64,7 +64,7 @@ int Model::LineCheck(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate) return firstintersecting; } -int Model::LineCheckPossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate) +int Model::LineCheckPossible(XYZ* p1, XYZ* p2, XYZ* p, XYZ* move, float* rotate) { static float distance; static float olddistance; @@ -100,7 +100,7 @@ int Model::LineCheckPossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate) return firstintersecting; } -int Model::LineCheckSlidePossible(XYZ *p1, XYZ *p2, XYZ *move, float *rotate) +int Model::LineCheckSlidePossible(XYZ* p1, XYZ* p2, XYZ* move, float* rotate) { static float distance; static float olddistance; @@ -140,7 +140,7 @@ int Model::LineCheckSlidePossible(XYZ *p1, XYZ *p2, XYZ *move, float *rotate) return firstintersecting; } -int Model::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate) +int Model::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate) { static int i; static float distance; @@ -165,7 +165,7 @@ 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) intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], p1, &radius); @@ -193,7 +193,7 @@ int Model::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate) return firstintersecting; } -int Model::SphereCheckPossible(XYZ *p1, float radius, XYZ *move, float *rotate) +int Model::SphereCheckPossible(XYZ* p1, float radius, XYZ* move, float* rotate) { static float distance; static float olddistance; @@ -221,7 +221,7 @@ 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) intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], p1, &radius); @@ -245,7 +245,6 @@ int Model::SphereCheckPossible(XYZ *p1, float radius, XYZ *move, float *rotate) return firstintersecting; } - void Model::UpdateVertexArray() { if (type != normaltype && type != decalstype) @@ -393,14 +392,14 @@ void Model::UpdateVertexArrayNoTexNoNorm() bool Model::loadnotex(const std::string& filename) { - FILE *tfile; + FILE* tfile; long i; short triangleNum; type = notextype; color = 0; - tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" ); + tfile = Folders::openMandatoryFile(Folders::getResourcePath(filename), "rb"); // read model settings @@ -453,10 +452,9 @@ bool Model::loadnotex(const std::string& filename) return true; } - bool Model::load(const std::string& filename) { - FILE *tfile; + FILE* tfile; long i; short triangleNum; @@ -469,7 +467,7 @@ bool Model::load(const std::string& filename) type = normaltype; color = 0; - tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" ); + tfile = Folders::openMandatoryFile(Folders::getResourcePath(filename), "rb"); // read model settings @@ -528,7 +526,7 @@ bool Model::load(const std::string& filename) bool Model::loaddecal(const std::string& filename) { - FILE *tfile; + FILE* tfile; long i, j; short triangleNum; @@ -539,7 +537,7 @@ bool Model::loaddecal(const std::string& filename) type = decalstype; color = 0; - tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" ); + tfile = Folders::openMandatoryFile(Folders::getResourcePath(filename), "rb"); // read model settings @@ -572,7 +570,6 @@ bool Model::loaddecal(const std::string& filename) funpackf(tfile, "Bf Bf Bf", &Triangles[i].gy[0], &Triangles[i].gy[1], &Triangles[i].gy[2]); } - modelTexture.xsz = 0; fclose(tfile); @@ -599,7 +596,7 @@ bool Model::loaddecal(const std::string& filename) bool Model::loadraw(const std::string& filename) { - FILE *tfile; + FILE* tfile; long i; short triangleNum; @@ -610,7 +607,7 @@ bool Model::loadraw(const std::string& filename) type = rawtype; color = 0; - tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" ); + tfile = Folders::openMandatoryFile(Folders::getResourcePath(filename), "rb"); // read model settings @@ -627,7 +624,6 @@ bool Model::loadraw(const std::string& filename) Triangles.resize(triangleNum); vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24); - for (i = 0; i < vertexNum; i++) { funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z); } @@ -642,7 +638,6 @@ bool Model::loadraw(const std::string& filename) funpackf(tfile, "Bf Bf Bf", &Triangles[i].gy[0], &Triangles[i].gy[1], &Triangles[i].gy[2]); } - fclose(tfile); for (i = 0; i < vertexNum; i++) { @@ -652,7 +647,6 @@ bool Model::loadraw(const std::string& filename) return true; } - void Model::UniformTexCoords() { for (unsigned int i = 0; i < Triangles.size(); i++) { @@ -666,7 +660,6 @@ void Model::UniformTexCoords() UpdateVertexArray(); } - void Model::FlipTexCoords() { for (unsigned int i = 0; i < Triangles.size(); i++) { @@ -776,7 +769,6 @@ void Model::Rotate(float xang, float yang, float zang) boundingsphereradius = fast_sqrt(boundingsphereradius); } - void Model::CalculateNormals(bool facenormalise) { Game::LoadingScreen(); @@ -862,9 +854,9 @@ void Model::draw() glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (color) { - glInterleavedArrays( GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]); + glInterleavedArrays(GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]); } else { - glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]); + glInterleavedArrays(GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]); } textureptr.bind(); @@ -885,14 +877,14 @@ void Model::drawdifftex(Texture texture) glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (color) { - glInterleavedArrays( GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]); + glInterleavedArrays(GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]); } else { - glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]); + glInterleavedArrays(GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]); } texture.bind(); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glDrawArrays(GL_TRIANGLES, 0, Triangles.size() * 3); @@ -969,7 +961,7 @@ void Model::drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloo 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) - glColor4f(1, 1, 1, decals[i].opacity*decals[i].alivetime*.25); + glColor4f(1, 1, 1, decals[i].opacity * decals[i].alivetime * .25); if (decals[i].alivetime > 58) glColor4f(1, 1, 1, decals[i].opacity * (60 - decals[i].alivetime) / 2); } @@ -1012,7 +1004,7 @@ void Model::DeleteDecal(int which) } } -void Model::MakeDecal(decal_type atype, XYZ *where, float *size, float *opacity, float *rotation) +void Model::MakeDecal(decal_type atype, XYZ* where, float* size, float* opacity, float* rotation) { if (decalstoggle) { if (type != decalstype) @@ -1182,16 +1174,16 @@ void Model::deallocate() } Model::Model() - : vertexNum(0), - type(nothing), - owner(0), - vertex(0), - normals(0), - vArray(0), - color(0), - boundingspherecenter(), - boundingsphereradius(0), - flat(false) + : vertexNum(0) + , type(nothing) + , owner(0) + , vertex(0) + , normals(0) + , vArray(0) + , color(0) + , boundingspherecenter() + , boundingsphereradius(0) + , flat(false) { memset(&modelTexture, 0, sizeof(modelTexture)); } diff --git a/Source/Graphic/Sprite.cpp b/Source/Graphic/Sprite.cpp index 862d4bb..fc1cae2 100644 --- a/Source/Graphic/Sprite.cpp +++ b/Source/Graphic/Sprite.cpp @@ -100,89 +100,89 @@ void Sprite::Draw() for (unsigned i = 0; i < sprites.size(); i++) { if (lasttype != sprites[i]->type) { switch (sprites[i]->type) { - case cloudsprite: - cloudtexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case breathsprite: - case cloudimpactsprite: - cloudimpacttexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case smoketype: - smoketexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case bloodsprite: - bloodtexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case splintersprite : - if (lastspecial != sprites[i]->special) { - if (sprites[i]->special == 0) - splintertexture.bind(); - if (sprites[i]->special == 1) - leaftexture.bind(); - if (sprites[i]->special == 2) - snowflaketexture.bind(); - if (sprites[i]->special == 3) - toothtexture.bind(); + case cloudsprite: + cloudtexture.bind(); if (!blend) { blend = 1; glAlphaFunc(GL_GREATER, 0.0001); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - } - break; - case snowsprite: - snowflaketexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case weaponshinesprite: - shinetexture.bind(); - if (blend) { - blend = 0; - glAlphaFunc(GL_GREATER, 0.001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } - break; - case flamesprite: - case weaponflamesprite: - flametexture.bind(); - if (blend || lasttype == bloodflamesprite) { - blend = 0; - glAlphaFunc(GL_GREATER, 0.3); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } - break; - case bloodflamesprite: - bloodflametexture.bind(); - if (blend) { - blend = 0; - glAlphaFunc(GL_GREATER, 0.3); - glBlendFunc(GL_ONE, GL_ZERO); - } - break; + break; + case breathsprite: + case cloudimpactsprite: + cloudimpacttexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + break; + case smoketype: + smoketexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + break; + case bloodsprite: + bloodtexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + break; + case splintersprite: + if (lastspecial != sprites[i]->special) { + if (sprites[i]->special == 0) + splintertexture.bind(); + if (sprites[i]->special == 1) + leaftexture.bind(); + if (sprites[i]->special == 2) + snowflaketexture.bind(); + if (sprites[i]->special == 3) + toothtexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + } + break; + case snowsprite: + snowflaketexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + break; + case weaponshinesprite: + shinetexture.bind(); + if (blend) { + blend = 0; + glAlphaFunc(GL_GREATER, 0.001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + } + break; + case flamesprite: + case weaponflamesprite: + flametexture.bind(); + if (blend || lasttype == bloodflamesprite) { + blend = 0; + glAlphaFunc(GL_GREATER, 0.3); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + } + break; + case bloodflamesprite: + bloodflametexture.bind(); + if (blend) { + blend = 0; + glAlphaFunc(GL_GREATER, 0.3); + glBlendFunc(GL_ONE, GL_ZERO); + } + break; } } if (sprites[i]->type == snowsprite) @@ -196,9 +196,9 @@ void Sprite::Draw() glColor4f(sprites[i]->color[0], sprites[i]->color[1], sprites[i]->color[2], sprites[i]->opacity * distancemult); } else { 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); + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity); else - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity * distancemult); + 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; @@ -230,42 +230,42 @@ void Sprite::Draw() 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) - 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); + 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) - 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); + 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) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->alivetime / .2); + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->alivetime / .2); 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); + 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) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1); + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], 1); else - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], distancemult); + 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) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1); + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], 1); else - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], distancemult); + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult); } glBegin(GL_TRIANGLES); glTexCoord2f(1.0f, 1.0f); - glVertex3f( .5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f); + glVertex3f(.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f); glTexCoord2f(1.0f, 0.0f); - glVertex3f( .5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); + glVertex3f(.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); glTexCoord2f(1.0f, 0.0f); - glVertex3f( .5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); + glVertex3f(.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f); glEnd(); @@ -307,12 +307,18 @@ 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) sprites[i]->position.y += 12; - if (sprites[i]->position.y > tempviewer.y + 6) sprites[i]->position.y -= 12; - if (sprites[i]->position.z < tempviewer.z - 6) sprites[i]->position.z += 12; - if (sprites[i]->position.z > tempviewer.z + 6) sprites[i]->position.z -= 12; - if (sprites[i]->position.x < tempviewer.x - 6) sprites[i]->position.x += 12; - if (sprites[i]->position.x > tempviewer.x + 6) sprites[i]->position.x -= 12; + if (sprites[i]->position.y < tempviewer.y - 6) + sprites[i]->position.y += 12; + if (sprites[i]->position.y > tempviewer.y + 6) + sprites[i]->position.y -= 12; + if (sprites[i]->position.z < tempviewer.z - 6) + sprites[i]->position.z += 12; + if (sprites[i]->position.z > tempviewer.z + 6) + sprites[i]->position.z -= 12; + if (sprites[i]->position.x < tempviewer.x - 6) + sprites[i]->position.x += 12; + if (sprites[i]->position.x > tempviewer.x + 6) + sprites[i]->position.x -= 12; } if (sprites[i]->type == bloodsprite) { bool spritehit = 0; diff --git a/Source/Graphic/Stereo.cpp b/Source/Graphic/Stereo.cpp index 66938e2..6bcf775 100644 --- a/Source/Graphic/Stereo.cpp +++ b/Source/Graphic/Stereo.cpp @@ -30,123 +30,121 @@ bool CanInitStereo(StereoMode mode) GLint stencilbits = 0; switch (mode) { - case stereoNone: - case stereoAnaglyph: - return true; - break; - case stereoHorizontalInterlaced: - case stereoVerticalInterlaced: - glGetIntegerv(GL_STENCIL_BITS, &stencilbits); - if ( stencilbits < 1 ) { - fprintf(stderr, "Failed to get a stencil buffer, interlaced stereo not available.\n"); + case stereoNone: + case stereoAnaglyph: + return true; + break; + case stereoHorizontalInterlaced: + case stereoVerticalInterlaced: + glGetIntegerv(GL_STENCIL_BITS, &stencilbits); + if (stencilbits < 1) { + fprintf(stderr, "Failed to get a stencil buffer, interlaced stereo not available.\n"); + return false; + } else { + fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits); + } + return true; + break; + default: return false; - } else { - fprintf(stderr, "Stencil buffer has %i bits, good.\n", stencilbits); - } - return true; - break; - default: - return false; } - } void InitStereo(StereoMode mode) { switch (mode) { - default: - case stereoNone: - case stereoAnaglyph: - glDisable(GL_STENCIL_TEST); - return; - case stereoHorizontalInterlaced: - case stereoVerticalInterlaced: - fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight); - - // Setup stencil buffer - glDisable( GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glDisable(GL_LIGHTING); - glDisable(GL_TEXTURE_2D); - - glEnable( GL_STENCIL_TEST); - glClearStencil(0); - glClear( GL_STENCIL_BUFFER_BIT ); - glStencilFunc(GL_ALWAYS, 0x1, 0x1); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - - // Setup viewport - glViewport(0, 0, kContextWidth, kContextHeight); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); - glDisable(GL_LINE_SMOOTH); - - // Add 0.5 to the coordinates, because OpenGL considers a pixel should be - // turned on when a line passes through the center of it. - if ( mode == stereoHorizontalInterlaced ) { - for (int y = 0; y < kContextHeight; y += 2) { - glBegin(GL_LINES); - glVertex3f(0.5, y + 0.5, 0); - glVertex3f(kContextWidth + 0.5, y + 0.5, 0); - glEnd(); + default: + case stereoNone: + case stereoAnaglyph: + glDisable(GL_STENCIL_TEST); + return; + case stereoHorizontalInterlaced: + case stereoVerticalInterlaced: + fprintf(stderr, "Screen width is %i, height is %i\n", kContextWidth, kContextHeight); + + // Setup stencil buffer + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + + glEnable(GL_STENCIL_TEST); + glClearStencil(0); + glClear(GL_STENCIL_BUFFER_BIT); + glStencilFunc(GL_ALWAYS, 0x1, 0x1); + glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); + + // Setup viewport + glViewport(0, 0, kContextWidth, kContextHeight); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho((GLdouble)0, (GLdouble)kContextWidth, (GLdouble)kContextHeight, 0, -1, 1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glDisable(GL_LINE_SMOOTH); + + // Add 0.5 to the coordinates, because OpenGL considers a pixel should be + // turned on when a line passes through the center of it. + if (mode == stereoHorizontalInterlaced) { + for (int y = 0; y < kContextHeight; y += 2) { + glBegin(GL_LINES); + glVertex3f(0.5, y + 0.5, 0); + glVertex3f(kContextWidth + 0.5, y + 0.5, 0); + glEnd(); + } + } else { + for (int x = 0; x < kContextWidth; x += 2) { + glBegin(GL_LINES); + glVertex3f(x + 0.5, 0.5, 0); + glVertex3f(x + 0.5, kContextHeight + 0.5, 0); + glEnd(); + } } - } else { - for (int x = 0; x < kContextWidth; x += 2) { - glBegin(GL_LINES); - glVertex3f(x + 0.5, 0.5, 0); - glVertex3f(x + 0.5, kContextHeight + 0.5, 0); - glEnd(); - } - } - glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); - glStencilFunc(GL_NOTEQUAL, 0x01, 0x01); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glEnable( GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); - glEnable(GL_TEXTURE_2D); + glStencilFunc(GL_NOTEQUAL, 0x01, 0x01); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); } - } const std::string StereoModeName(StereoMode mode) { switch (mode) { - case stereoNone: - return "None"; - break; - case stereoAnaglyph: - return "Anaglyph"; - break; - case stereoHorizontalInterlaced: - return "Horizontal interlacing"; - break; - case stereoVerticalInterlaced: - return "Vertical interlacing"; - break; - case stereoHorizontalSplit: - return "Horizontal split"; - break; - case stereoVerticalSplit: - return "Vertical split"; - break; - case stereoOpenGL: - return "OpenGL"; - break; - default: - return "(error)"; - break; + case stereoNone: + return "None"; + break; + case stereoAnaglyph: + return "Anaglyph"; + break; + case stereoHorizontalInterlaced: + return "Horizontal interlacing"; + break; + case stereoVerticalInterlaced: + return "Vertical interlacing"; + break; + case stereoHorizontalSplit: + return "Horizontal split"; + break; + case stereoVerticalSplit: + return "Vertical split"; + break; + case stereoOpenGL: + return "OpenGL"; + break; + default: + return "(error)"; + break; } } diff --git a/Source/Graphic/Text.cpp b/Source/Graphic/Text.cpp index 1253ba9..a5b60b8 100644 --- a/Source/Graphic/Text.cpp +++ b/Source/Graphic/Text.cpp @@ -58,23 +58,23 @@ void Text::BuildFont() // Build Our Font Display List cx = float((loop - 256) % 16) / 16.0f; // X Position Of Current Character cy = float((loop - 256) / 16) / 16.0f; // Y Position Of Current Character } - glNewList(base + loop, GL_COMPILE); // Start Building A List - glBegin(GL_QUADS); // Use A Quad For Each Character - glTexCoord2f(cx, 1 - cy - 0.0625f + .001); // Texture Coord (Bottom Left) - glVertex2i(0, 0); // Vertex Coord (Bottom Left) + glNewList(base + loop, GL_COMPILE); // Start Building A List + glBegin(GL_QUADS); // Use A Quad For Each Character + glTexCoord2f(cx, 1 - cy - 0.0625f + .001); // Texture Coord (Bottom Left) + glVertex2i(0, 0); // Vertex Coord (Bottom Left) glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f + .001); // Texture Coord (Bottom Right) - glVertex2i(16, 0); // Vertex Coord (Bottom Right) - glTexCoord2f(cx + 0.0625f, 1 - cy - .001); // Texture Coord (Top Right) - glVertex2i(16, 16); // Vertex Coord (Top Right) - glTexCoord2f(cx, 1 - cy - +.001); // Texture Coord (Top Left) - glVertex2i(0, 16); // Vertex Coord (Top Left) - glEnd(); // Done Building Our Quad (Character) + glVertex2i(16, 0); // Vertex Coord (Bottom Right) + glTexCoord2f(cx + 0.0625f, 1 - cy - .001); // Texture Coord (Top Right) + glVertex2i(16, 16); // Vertex Coord (Top Right) + 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) glTranslated(10, 0, 0); // Move To The Right Of The Character 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 @@ -82,7 +82,7 @@ void Text::_glPrint(float x, float y, const std::string& string, int set, float if (set > 1) { set = 1; } - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); FontTexture.bind(); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); @@ -97,14 +97,14 @@ void Text::_glPrint(float x, float y, const std::string& string, int set, float glLoadIdentity(); glTranslated(x, y, 0); glScalef(size, size, 1); - glListBase(base - 32 + (128 * set) + offset); // Choose The Font Set (0 or 1) + glListBase(base - 32 + (128 * set) + offset); // Choose The Font Set (0 or 1) glCallLists(end - start, GL_BYTE, &string[start]); // Write The Text To The Screen glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEnable(GL_DEPTH_TEST); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } void Text::glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) @@ -131,9 +131,9 @@ void Text::glPrintOutlined(float x, float y, const std::string& string, int set, void Text::glPrintOutlined(float r, float g, float b, float a, float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { glColor4f(0, 0, 0, a); - glPrintOutline( x - 2 * size, y - 2 * size, string, set, size * 2.5 / 2, width, height, start, end); + glPrintOutline(x - 2 * size, y - 2 * size, string, set, size * 2.5 / 2, width, height, start, end); glColor4f(r, g, b, a); - glPrint( x, y, string, set, size, width, height, start, end); + glPrint(x, y, string, set, size, width, height, start, end); } Text::Text() @@ -148,4 +148,3 @@ Text::~Text() base = 0; } } - diff --git a/Source/Graphic/Texture.cpp b/Source/Graphic/Texture.cpp index 9dd4ea6..69ff28e 100644 --- a/Source/Graphic/Texture.cpp +++ b/Source/Graphic/Texture.cpp @@ -76,16 +76,26 @@ void TextureRes::bind() glBindTexture(GL_TEXTURE_2D, id); } -TextureRes::TextureRes(const string& _filename, bool _hasMipmap): - id(0), filename(_filename), hasMipmap(_hasMipmap), isSkin(false), - skinsize(0), data(NULL), datalen(0) +TextureRes::TextureRes(const string& _filename, bool _hasMipmap) + : id(0) + , filename(_filename) + , hasMipmap(_hasMipmap) + , isSkin(false) + , skinsize(0) + , data(NULL) + , datalen(0) { load(); } -TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array, int* skinsizep): - id(0), filename(_filename), hasMipmap(_hasMipmap), isSkin(true), - skinsize(0), data(NULL), datalen(0) +TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array, int* skinsizep) + : id(0) + , filename(_filename) + , hasMipmap(_hasMipmap) + , isSkin(true) + , skinsize(0) + , data(NULL) + , datalen(0) { load(); *skinsizep = skinsize; diff --git a/Source/Level/Awards.cpp b/Source/Level/Awards.cpp index 933f518..b5da1db 100644 --- a/Source/Level/Awards.cpp +++ b/Source/Level/Awards.cpp @@ -29,13 +29,13 @@ float startbonustotal; float bonustime; float bonusnum[100]; -const char *bonus_names[bonus_count] = { +const char* bonus_names[bonus_count] = { #define DECLARE_BONUS(id, name, ...) name, #include "Bonuses.def" #undef DECLARE_BONUS }; -const char *award_names[award_count] = { +const char* award_names[award_count] = { #define DECLARE_AWARD(id, name) name, #include "Awards.def" #undef DECLARE_AWARD @@ -47,8 +47,7 @@ static const int bonus_values[bonus_count] = { #undef DECLARE_BONUS }; -void -award_bonus(int playerid, int bonusid, int alt_value) +void award_bonus(int playerid, int bonusid, int alt_value) { if (playerid != 0) return; @@ -76,7 +75,7 @@ int numreversals; int numattacks; int maxalarmed; -int award_awards(int *awards) +int award_awards(int* awards) { int numawards = 0; if (damagetaken == 0 && Person::players[0]->bloodloss == 0) { @@ -142,7 +141,7 @@ int award_awards(int *awards) awards[numawards] = awardbrutal; numawards++; } - if (numreversals > ((float)numattacks)*.8 && numreversals > 3) { + if (numreversals > ((float)numattacks) * .8 && numreversals > 3) { awards[numawards] = awardaikido; numawards++; } diff --git a/Source/Level/Campaign.cpp b/Source/Level/Campaign.cpp index 236f631..0ff7392 100644 --- a/Source/Level/Campaign.cpp +++ b/Source/Level/Campaign.cpp @@ -36,8 +36,8 @@ int actuallevel = 0; std::vector ListCampaigns() { errno = 0; - DIR *campaigns = opendir(Folders::getResourcePath("Campaigns").c_str()); - struct dirent *campaign = NULL; + DIR* campaigns = opendir(Folders::getResourcePath("Campaigns").c_str()); + struct dirent* campaign = NULL; if (!campaigns) { perror(("Problem while loading campaigns from " + Folders::getResourcePath("Campaigns")).c_str()); exit(EXIT_FAILURE); @@ -94,42 +94,49 @@ void LoadCampaign() } } -CampaignLevel::CampaignLevel() : - width(10), - choosenext(1) +CampaignLevel::CampaignLevel() + : width(10) + , choosenext(1) { location.x = 0; location.y = 0; } -int CampaignLevel::getStartX() { +int CampaignLevel::getStartX() +{ return 30 + 120 + location.x * 400 / 512; } -int CampaignLevel::getStartY() { +int CampaignLevel::getStartY() +{ return 30 + 30 + (512 - location.y) * 400 / 512; } -int CampaignLevel::getEndX() { +int CampaignLevel::getEndX() +{ return getStartX() + width; } -int CampaignLevel::getEndY() { +int CampaignLevel::getEndY() +{ return getStartY() + width; } -XYZ CampaignLevel::getCenter() { +XYZ CampaignLevel::getCenter() +{ XYZ center; center.x = getStartX() + width / 2; center.y = getStartY() + width / 2; return center; } -int CampaignLevel::getWidth() { +int CampaignLevel::getWidth() +{ return width; } -istream& CampaignLevel::operator<< (istream& is) { +istream& CampaignLevel::operator<<(istream& is) +{ is.ignore(256, ':'); is.ignore(256, ':'); is.ignore(256, ' '); diff --git a/Source/Level/Dialog.cpp b/Source/Level/Dialog.cpp index 64d3015..ce15da6 100644 --- a/Source/Level/Dialog.cpp +++ b/Source/Level/Dialog.cpp @@ -22,9 +22,9 @@ along with Lugaru. If not, see . #include "Game.hpp" #include "Objects/Person.hpp" -#include "Utils/binio.h" #include "Utils/Folders.hpp" #include "Utils/Input.hpp" +#include "Utils/binio.h" extern int hostile; @@ -43,7 +43,8 @@ void Dialog::loadDialogs(FILE* tfile) } } -Dialog::Dialog(FILE* tfile) : gonethrough(0) +Dialog::Dialog(FILE* tfile) + : gonethrough(0) { int numdialogscenes; funpackf(tfile, "Bi", &numdialogscenes); @@ -110,7 +111,8 @@ DialogScene::DialogScene(FILE* tfile) } /* Load dialog from txt file, used by console */ -Dialog::Dialog(int type, std::string filename) : type(type) +Dialog::Dialog(int type, std::string filename) + : type(type) { ifstream ipstream(Folders::getResourcePath(filename)); ipstream.ignore(256, ':'); @@ -125,7 +127,7 @@ Dialog::Dialog(int type, std::string filename) : type(type) ipstream.close(); } -DialogScene::DialogScene(ifstream &ipstream) +DialogScene::DialogScene(ifstream& ipstream) { ipstream.ignore(256, ':'); ipstream.ignore(256, ':'); @@ -154,13 +156,13 @@ void Dialog::tick(int id) bool special = (type > 9); if ((!hostile || (type > 40) && (type < 50)) && - (playerId < Person::players.size()) && - (playerId > 0) && - ((gonethrough == 0) || !special) && - (special || Input::isKeyPressed(Game::attackkey))) { + (playerId < Person::players.size()) && + (playerId > 0) && + ((gonethrough == 0) || !special) && + (special || Input::isKeyPressed(Game::attackkey))) { if ((distsq(&Person::players[0]->coords, &Person::players[playerId]->coords) < 6) || - (Person::players[playerId]->howactive >= typedead1) || - (type > 40) && (type < 50)) { + (Person::players[playerId]->howactive >= typedead1) || + (type > 40) && (type < 50)) { whichdialogue = id; play(); dialoguetime = 0; diff --git a/Source/Level/Hotspot.cpp b/Source/Level/Hotspot.cpp index f1b2ced..9ea7e95 100644 --- a/Source/Level/Hotspot.cpp +++ b/Source/Level/Hotspot.cpp @@ -23,16 +23,16 @@ std::vector Hotspot::hotspots; int Hotspot::current = 0; int Hotspot::killhotspot = 0; -Hotspot::Hotspot() : - position(), - type(0), - size(0) +Hotspot::Hotspot() + : position() + , type(0) + , size(0) { } -Hotspot::Hotspot(XYZ p, int t, float s) : - position(p), - type(t), - size(s) +Hotspot::Hotspot(XYZ p, int t, float s) + : position(p) + , type(t) + , size(s) { } diff --git a/Source/MacCompatibility.cpp b/Source/MacCompatibility.cpp index 65a4c5f..dc1ad47 100644 --- a/Source/MacCompatibility.cpp +++ b/Source/MacCompatibility.cpp @@ -21,10 +21,10 @@ along with Lugaru. If not, see . #include "MacCompatibility.hpp" #include -#include #include #include #include +#include #ifdef WIN32 #include @@ -32,38 +32,39 @@ along with Lugaru. If not, see . #if PLATFORM_UNIX #include -#include #include #include +#include typedef long long __int64; typedef __int64 LARGE_INTEGER; -static int QueryPerformanceFrequency(LARGE_INTEGER *liptr) +static int QueryPerformanceFrequency(LARGE_INTEGER* liptr) { - assert(sizeof (__int64) == 8); - assert(sizeof (LARGE_INTEGER) == 8); + assert(sizeof(__int64) == 8); + assert(sizeof(LARGE_INTEGER) == 8); *liptr = 1000; - return(1); + return (1); } -static int QueryPerformanceCounter(LARGE_INTEGER *liptr) +static int QueryPerformanceCounter(LARGE_INTEGER* liptr) { struct timeval tv; gettimeofday(&tv, NULL); - *liptr = ( (((LARGE_INTEGER) tv.tv_sec) * 1000) + - (((LARGE_INTEGER) tv.tv_usec) / 1000) ); - return(1); + *liptr = ((((LARGE_INTEGER)tv.tv_sec) * 1000) + + (((LARGE_INTEGER)tv.tv_usec) / 1000)); + return (1); } #endif class AppTime { -public: - AppTime() { + public: + AppTime() + { counterRate = 1; baseCounter = 0; - QueryPerformanceFrequency( (LARGE_INTEGER*)&counterRate); - QueryPerformanceCounter( (LARGE_INTEGER*)&baseCounter); + QueryPerformanceFrequency((LARGE_INTEGER*)&counterRate); + QueryPerformanceCounter((LARGE_INTEGER*)&baseCounter); } __int64 counterRate; // LARGE_INTEGER type has no math functions so use int64 __int64 baseCounter; @@ -73,7 +74,7 @@ static AppTime g_appTime; AbsoluteTime UpTime() { __int64 counter; - QueryPerformanceCounter( (LARGE_INTEGER*)&counter); + QueryPerformanceCounter((LARGE_INTEGER*)&counter); counter -= g_appTime.baseCounter; @@ -83,8 +84,7 @@ AbsoluteTime UpTime() return time; } - -Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b) +Duration AbsoluteDeltaToDuration(AbsoluteTime& a, AbsoluteTime& b) { __int64 value = a.hi; value <<= 32; diff --git a/Source/Math/Frustum.cpp b/Source/Math/Frustum.cpp index e8b1366..516b9ce 100644 --- a/Source/Math/Frustum.cpp +++ b/Source/Math/Frustum.cpp @@ -25,7 +25,7 @@ along with Lugaru. If not, see . #include void FRUSTUM:: -GetFrustum() + GetFrustum() { static float projmatrix[16]; static float mvmatrix[16]; @@ -93,7 +93,7 @@ GetFrustum() } int FRUSTUM:: -CubeInFrustum(float x, float y, float z, float size) + CubeInFrustum(float x, float y, float z, float size) { static int c, c2; @@ -127,7 +127,7 @@ CubeInFrustum(float x, float y, float z, float size) } int FRUSTUM:: -CubeInFrustum(float x, float y, float z, float size, float height) + CubeInFrustum(float x, float y, float z, float size, float height) { static int c, c2; @@ -161,9 +161,9 @@ CubeInFrustum(float x, float y, float z, float size, float height) } int FRUSTUM:: -SphereInFrustum(float x, float y, float z, float radius) + SphereInFrustum(float x, float y, float z, float radius) { - static int c2; + 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) diff --git a/Source/Math/XYZ.cpp b/Source/Math/XYZ.cpp index ad145ae..113ddf5 100644 --- a/Source/Math/XYZ.cpp +++ b/Source/Math/XYZ.cpp @@ -20,7 +20,7 @@ along with Lugaru. If not, see . #include "Math/XYZ.hpp" -bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3) +bool PointInTriangle(XYZ* p, XYZ normal, XYZ* p1, XYZ* p2, XYZ* p3) { static float u0, u1, u2; static float v0, v1, v2; @@ -40,7 +40,6 @@ bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3) pointv[1] = p->y; pointv[2] = p->z; - p1v[0] = p1->x; p1v[1] = p1->y; p1v[2] = p1->z; @@ -57,20 +56,20 @@ bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3) normalv[1] = normal.y; normalv[2] = normal.z; -#define ABS(X) (((X)<0.f)?-(X):(X) ) -#define MAX(A, B) (((A)<(B))?(B):(A)) +#define ABS(X) (((X) < 0.f) ? -(X) : (X)) +#define MAX(A, B) (((A) < (B)) ? (B) : (A)) max = MAX(MAX(ABS(normalv[0]), ABS(normalv[1])), ABS(normalv[2])); #undef MAX if (max == ABS(normalv[0])) { - i = 1; // y, z + i = 1; // y, z j = 2; } if (max == ABS(normalv[1])) { - i = 0; // x, z + i = 0; // x, z j = 2; } if (max == ABS(normalv[2])) { - i = 0; // x, y + i = 0; // x, y j = 1; } #undef ABS @@ -86,14 +85,14 @@ 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; } } @@ -101,7 +100,7 @@ bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3) return bInter; } -bool LineFacet(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ *p) +bool LineFacet(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ* p) { static float d; static float denom, mu; @@ -112,27 +111,27 @@ bool LineFacet(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ *p) n.y = (pb.z - pa.z) * (pc.x - pa.x) - (pb.x - pa.x) * (pc.z - pa.z); n.z = (pb.x - pa.x) * (pc.y - pa.y) - (pb.y - pa.y) * (pc.x - pa.x); Normalise(&n); - d = - n.x * pa.x - n.y * pa.y - n.z * pa.z; + d = -n.x * pa.x - n.y * pa.y - n.z * pa.z; //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; + 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)) { + if (!PointInTriangle(p, n, &pa, &pb, &pc)) { return 0; } return 1; } -float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ *p) +float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ* p) { static float d; static float denom, mu; @@ -143,52 +142,52 @@ float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ *p) n.y = (pb.z - pa.z) * (pc.x - pa.x) - (pb.x - pa.x) * (pc.z - pa.z); n.z = (pb.x - pa.x) * (pc.y - pa.y) - (pb.y - pa.y) * (pc.x - pa.x); Normalise(&n); - d = - n.x * pa.x - n.y * pa.y - n.z * pa.z; + d = -n.x * pa.x - n.y * pa.y - n.z * pa.z; //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; + 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)) { + if (!PointInTriangle(p, n, &pa, &pb, &pc)) { return 0; } return 1; } -float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ n, XYZ *p) +float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ n, XYZ* p) { static float d; static float denom, mu; //Calculate the parameters for the plane - d = - n.x * pa.x - n.y * pa.y - n.z * pa.z; + d = -n.x * pa.x - n.y * pa.y - n.z * pa.z; //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; + 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)) { + if (!PointInTriangle(p, n, &pa, &pb, &pc)) { return 0; } return 1; } -float LineFacetd(XYZ *p1, XYZ *p2, XYZ *pa, XYZ *pb, XYZ *pc, XYZ *p) +float LineFacetd(XYZ* p1, XYZ* p2, XYZ* pa, XYZ* pb, XYZ* pc, XYZ* p) { static float d; static float denom, mu; @@ -199,49 +198,46 @@ float LineFacetd(XYZ *p1, XYZ *p2, XYZ *pa, XYZ *pb, XYZ *pc, XYZ *p) n.y = (pb->z - pa->z) * (pc->x - pa->x) - (pb->x - pa->x) * (pc->z - pa->z); n.z = (pb->x - pa->x) * (pc->y - pa->y) - (pb->y - pa->y) * (pc->x - pa->x); Normalise(&n); - d = - n.x * pa->x - n.y * pa->y - n.z * pa->z; - + d = -n.x * pa->x - n.y * pa->y - n.z * pa->z; //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; + 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)) { + if (!PointInTriangle(p, n, pa, pb, pc)) { return 0; } return 1; } -float LineFacetd(XYZ *p1, XYZ *p2, XYZ *pa, XYZ *pb, XYZ *pc, XYZ *n, XYZ *p) +float LineFacetd(XYZ* p1, XYZ* p2, XYZ* pa, XYZ* pb, XYZ* pc, XYZ* n, XYZ* p) { static float d; static float denom, mu; //Calculate the parameters for the plane - d = - n->x * pa->x - n->y * pa->y - n->z * pa->z; + d = -n->x * pa->x - n->y * pa->y - n->z * pa->z; //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; + 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)) { + if (!PointInTriangle(p, *n, pa, pb, pc)) { return 0; } return 1; } - - diff --git a/Source/Menu/Menu.cpp b/Source/Menu/Menu.cpp index 91dd2ed..4242ff0 100644 --- a/Source/Menu/Menu.cpp +++ b/Source/Menu/Menu.cpp @@ -36,7 +36,7 @@ along with Lugaru. If not, see . using namespace Game; extern float multiplier; -extern std::set> resolutions; +extern std::set> resolutions; extern int mainmenu; extern std::vector campaignlevels; extern float musicvolume[4]; @@ -57,22 +57,22 @@ bool newuserblink = false; std::vector Menu::items; MenuItem::MenuItem(MenuItemType _type, int _id, const string& _text, Texture _texture, - int _x, int _y, int _w, int _h, float _r, float _g, float _b, - float _linestartsize, float _lineendsize): - type(_type), - id(_id), - text(_text), - texture(_texture), - x(_x), - y(_y), - w(_w), - h(_h), - r(_r), - g(_g), - b(_b), - effectfade(0), - linestartsize(_linestartsize), - lineendsize(_lineendsize) + int _x, int _y, int _w, int _h, float _r, float _g, float _b, + float _linestartsize, float _lineendsize) + : type(_type) + , id(_id) + , text(_text) + , texture(_texture) + , x(_x) + , y(_y) + , w(_w) + , h(_h) + , r(_r) + , g(_g) + , b(_b) + , effectfade(0) + , linestartsize(_linestartsize) + , lineendsize(_lineendsize) { if (type == MenuItem::BUTTON) { if (w == -1) { @@ -182,105 +182,104 @@ void Menu::drawItems() glEnable(GL_BLEND); for (vector::iterator it = items.begin(); it != items.end(); it++) { switch (it->type) { - case MenuItem::IMAGE: - case MenuItem::IMAGEBUTTON: - case MenuItem::MAPMARKER: - glColor4f(it->r, it->g, it->b, 1); - glPushMatrix(); - if (it->type == MenuItem::MAPMARKER) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glTranslatef(2.5, -4.5, 0); //from old code - } else { - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } - it->texture.bind(); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex3f(it->x, it->y, 0); - glTexCoord2f(1, 0); - glVertex3f(it->x + it->w, it->y, 0); - glTexCoord2f(1, 1); - glVertex3f(it->x + it->w, it->y + it->h, 0); - glTexCoord2f(0, 1); - glVertex3f(it->x, it->y + it->h, 0); - glEnd(); - if (it->type != MenuItem::IMAGE) { - //mouseover highlight - for (int i = 0; i < 10; i++) { - if (1 - ((float)i) / 10 - (1 - it->effectfade) > 0) { - glColor4f(it->r, it->g, it->b, (1 - ((float)i) / 10 - (1 - it->effectfade))*.25); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex3f(it->x - ((float)i) * 1 / 2, it->y - ((float)i) * 1 / 2, 0); - glTexCoord2f(1, 0); - glVertex3f(it->x + it->w + ((float)i) * 1 / 2, it->y - ((float)i) * 1 / 2, 0); - glTexCoord2f(1, 1); - glVertex3f(it->x + it->w + ((float)i) * 1 / 2, it->y + it->h + ((float)i) * 1 / 2, 0); - glTexCoord2f(0, 1); - glVertex3f(it->x - ((float)i) * 1 / 2, it->y + it->h + ((float)i) * 1 / 2, 0); - glEnd(); + case MenuItem::IMAGE: + case MenuItem::IMAGEBUTTON: + case MenuItem::MAPMARKER: + glColor4f(it->r, it->g, it->b, 1); + glPushMatrix(); + if (it->type == MenuItem::MAPMARKER) { + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glTranslatef(2.5, -4.5, 0); //from old code + } else { + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + } + it->texture.bind(); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex3f(it->x, it->y, 0); + glTexCoord2f(1, 0); + glVertex3f(it->x + it->w, it->y, 0); + glTexCoord2f(1, 1); + glVertex3f(it->x + it->w, it->y + it->h, 0); + glTexCoord2f(0, 1); + glVertex3f(it->x, it->y + it->h, 0); + glEnd(); + if (it->type != MenuItem::IMAGE) { + //mouseover highlight + for (int i = 0; i < 10; i++) { + if (1 - ((float)i) / 10 - (1 - it->effectfade) > 0) { + glColor4f(it->r, it->g, it->b, (1 - ((float)i) / 10 - (1 - it->effectfade)) * .25); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex3f(it->x - ((float)i) * 1 / 2, it->y - ((float)i) * 1 / 2, 0); + glTexCoord2f(1, 0); + glVertex3f(it->x + it->w + ((float)i) * 1 / 2, it->y - ((float)i) * 1 / 2, 0); + glTexCoord2f(1, 1); + glVertex3f(it->x + it->w + ((float)i) * 1 / 2, it->y + it->h + ((float)i) * 1 / 2, 0); + glTexCoord2f(0, 1); + glVertex3f(it->x - ((float)i) * 1 / 2, it->y + it->h + ((float)i) * 1 / 2, 0); + glEnd(); + } } } - } - glPopMatrix(); - break; - case MenuItem::LABEL: - case MenuItem::BUTTON: - glColor4f(it->r, it->g, it->b, 1); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - Game::text->glPrint(it->x, it->y, it->text.c_str(), 0, 1, 640, 480); - if (it->type != MenuItem::LABEL) { - //mouseover highlight - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - for (int i = 0; i < 15; i++) { - if (1 - ((float)i) / 15 - (1 - it->effectfade) > 0) { - glColor4f(it->r, it->g, it->b, (1 - ((float)i) / 10 - (1 - it->effectfade))*.25); - Game::text->glPrint(it->x - ((float)i), it->y, it->text.c_str(), 0, 1 + ((float)i) / 70, 640, 480); + glPopMatrix(); + break; + case MenuItem::LABEL: + case MenuItem::BUTTON: + glColor4f(it->r, it->g, it->b, 1); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + Game::text->glPrint(it->x, it->y, it->text.c_str(), 0, 1, 640, 480); + if (it->type != MenuItem::LABEL) { + //mouseover highlight + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + for (int i = 0; i < 15; i++) { + if (1 - ((float)i) / 15 - (1 - it->effectfade) > 0) { + glColor4f(it->r, it->g, it->b, (1 - ((float)i) / 10 - (1 - it->effectfade)) * .25); + Game::text->glPrint(it->x - ((float)i), it->y, it->text.c_str(), 0, 1 + ((float)i) / 70, 640, 480); + } } } - } - break; - case MenuItem::MAPLABEL: - Game::text->glPrintOutlined(0.9, 0, 0, 1, it->x, it->y, it->text.c_str(), 0, 0.6, 640, 480); - break; - case MenuItem::MAPLINE: { - XYZ linestart; - linestart.x = it->x; - linestart.y = it->y; - linestart.z = 0; - XYZ lineend; - lineend.x = it->x + it->w; - lineend.y = it->y + it->h; - lineend.z = 0; - XYZ offset = lineend - linestart; - XYZ fac = offset; - Normalise(&fac); - offset = DoRotation(offset, 0, 0, 90); - Normalise(&offset); - - linestart += fac * 4 * it->linestartsize; - lineend -= fac * 4 * it->lineendsize; - - glDisable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(it->r, it->g, it->b, 1); - glPushMatrix(); - glTranslatef(2, -5, 0); //from old code - glBegin(GL_QUADS); - glVertex3f(linestart.x - offset.x * it->linestartsize, linestart.y - offset.y * it->linestartsize, 0.0f); - glVertex3f(linestart.x + offset.x * it->linestartsize, linestart.y + offset.y * it->linestartsize, 0.0f); - glVertex3f(lineend.x + offset.x * it->lineendsize, lineend.y + offset.y * it->lineendsize, 0.0f); - glVertex3f(lineend.x - offset.x * it->lineendsize, lineend.y - offset.y * it->lineendsize, 0.0f); - glEnd(); - glPopMatrix(); - glEnable(GL_TEXTURE_2D); - } - break; - default: - case MenuItem::NONE: - break; + break; + case MenuItem::MAPLABEL: + Game::text->glPrintOutlined(0.9, 0, 0, 1, it->x, it->y, it->text.c_str(), 0, 0.6, 640, 480); + break; + case MenuItem::MAPLINE: { + XYZ linestart; + linestart.x = it->x; + linestart.y = it->y; + linestart.z = 0; + XYZ lineend; + lineend.x = it->x + it->w; + lineend.y = it->y + it->h; + lineend.z = 0; + XYZ offset = lineend - linestart; + XYZ fac = offset; + Normalise(&fac); + offset = DoRotation(offset, 0, 0, 90); + Normalise(&offset); + + linestart += fac * 4 * it->linestartsize; + lineend -= fac * 4 * it->lineendsize; + + glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(it->r, it->g, it->b, 1); + glPushMatrix(); + glTranslatef(2, -5, 0); //from old code + glBegin(GL_QUADS); + glVertex3f(linestart.x - offset.x * it->linestartsize, linestart.y - offset.y * it->linestartsize, 0.0f); + glVertex3f(linestart.x + offset.x * it->linestartsize, linestart.y + offset.y * it->linestartsize, 0.0f); + glVertex3f(lineend.x + offset.x * it->lineendsize, lineend.y + offset.y * it->lineendsize, 0.0f); + glVertex3f(lineend.x - offset.x * it->lineendsize, lineend.y - offset.y * it->lineendsize, 0.0f); + glEnd(); + glPopMatrix(); + glEnable(GL_TEXTURE_2D); + } break; + default: + case MenuItem::NONE: + break; } } } @@ -293,12 +292,18 @@ void Menu::updateSettingsMenu() } setText(0, sbuf); setText(14, fullscreen ? "Fullscreen: On" : "Fullscreen: Off"); - if (newdetail == 0) setText(1, "Detail: Low"); - if (newdetail == 1) setText(1, "Detail: Medium"); - if (newdetail == 2) setText(1, "Detail: High"); - if (bloodtoggle == 0) setText(2, "Blood: Off"); - if (bloodtoggle == 1) setText(2, "Blood: On, low detail"); - if (bloodtoggle == 2) setText(2, "Blood: On, high detail (slower)"); + if (newdetail == 0) + setText(1, "Detail: Low"); + if (newdetail == 1) + setText(1, "Detail: Medium"); + if (newdetail == 2) + setText(1, "Detail: High"); + if (bloodtoggle == 0) + setText(2, "Blood: Off"); + if (bloodtoggle == 1) + setText(2, "Blood: On, low detail"); + 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"); @@ -322,17 +327,17 @@ void Menu::updateStereoConfigMenu() void Menu::updateControlsMenu() { - setText(0, (string)"Forwards: " + (keyselect == 0 ? "_" : Input::keyToChar(forwardkey))); - setText(1, (string)"Back: " + (keyselect == 1 ? "_" : Input::keyToChar(backkey))); - setText(2, (string)"Left: " + (keyselect == 2 ? "_" : Input::keyToChar(leftkey))); - setText(3, (string)"Right: " + (keyselect == 3 ? "_" : Input::keyToChar(rightkey))); - setText(4, (string)"Crouch: " + (keyselect == 4 ? "_" : Input::keyToChar(crouchkey))); - setText(5, (string)"Jump: " + (keyselect == 5 ? "_" : Input::keyToChar(jumpkey))); - setText(6, (string)"Draw: " + (keyselect == 6 ? "_" : Input::keyToChar(drawkey))); - setText(7, (string)"Throw: " + (keyselect == 7 ? "_" : Input::keyToChar(throwkey))); - setText(8, (string)"Attack: " + (keyselect == 8 ? "_" : Input::keyToChar(attackkey))); + setText(0, (string) "Forwards: " + (keyselect == 0 ? "_" : Input::keyToChar(forwardkey))); + setText(1, (string) "Back: " + (keyselect == 1 ? "_" : Input::keyToChar(backkey))); + setText(2, (string) "Left: " + (keyselect == 2 ? "_" : Input::keyToChar(leftkey))); + setText(3, (string) "Right: " + (keyselect == 3 ? "_" : Input::keyToChar(rightkey))); + setText(4, (string) "Crouch: " + (keyselect == 4 ? "_" : Input::keyToChar(crouchkey))); + setText(5, (string) "Jump: " + (keyselect == 5 ? "_" : Input::keyToChar(jumpkey))); + setText(6, (string) "Draw: " + (keyselect == 6 ? "_" : Input::keyToChar(drawkey))); + setText(7, (string) "Throw: " + (keyselect == 7 ? "_" : Input::keyToChar(throwkey))); + setText(8, (string) "Attack: " + (keyselect == 8 ? "_" : Input::keyToChar(attackkey))); if (devtools) { - setText(9, (string)"Console: " + (keyselect == 9 ? "_" : Input::keyToChar(consolekey))); + setText(9, (string) "Console: " + (keyselect == 9 ? "_" : Input::keyToChar(consolekey))); } } @@ -356,146 +361,144 @@ void Menu::Load() { clearMenu(); switch (mainmenu) { - case 1: - case 2: - addImage(0, Mainmenuitems[0], 150, 480 - 128, 256, 128); - addButtonImage(1, Mainmenuitems[mainmenu == 1 ? 1 : 5], 18, 480 - 152 - 32, 128, 32); - addButtonImage(2, Mainmenuitems[2], 18, 480 - 228 - 32, 112, 32); - addButtonImage(3, Mainmenuitems[mainmenu == 1 ? 3 : 6], 18, 480 - 306 - 32, mainmenu == 1 ? 68 : 132, 32); - break; - case 3: - addButton( 0, "", 10 + 20, 440); - addButton(14, "", 10 + 400, 440); - addButton( 1, "", 10 + 60, 405); - addButton( 2, "", 10 + 70, 370); - addButton( 4, "", 10 , 335); - addButton( 5, "", 10 + 60, 300); - addButton( 6, "", 10 + 70, 265); - addButton( 9, "", 10 , 230); - addButton(10, "", 20 , 195); - addButton(11, "", 10 + 60, 160); - addButton(13, "", 30 , 125); - addButton( 7, "-Configure Controls-", 10 + 15, 90); - addButton(12, "-Configure Stereo -", 10 + 15, 55); - addButton(8, "Back", 10, 10); - updateSettingsMenu(); - break; - case 4: - addButton(0, "", 10 , 400); - addButton(1, "", 10 + 40, 360); - addButton(2, "", 10 + 40, 320); - addButton(3, "", 10 + 30, 280); - addButton(4, "", 10 + 20, 240); - addButton(5, "", 10 + 40, 200); - addButton(6, "", 10 + 40, 160); - addButton(7, "", 10 + 30, 120); - addButton(8, "", 10 + 20, 80); - if (devtools) { - addButton(9, "", 10 + 10, 40); - } - addButton(devtools ? 10 : 9, "Back", 10, 10); - updateControlsMenu(); - break; - case 5: { - LoadCampaign(); - addLabel(-1, Account::active().getName(), 5, 400); - addButton(1, "Tutorial", 5, 300); - addButton(2, "Challenge", 5, 240); - addButton(3, "Delete User", 400, 10); - addButton(4, "Main Menu", 5, 10); - addButton(5, "Change User", 5, 180); - addButton(6, "Campaign : " + Account::active().getCurrentCampaign(), 200, 420); - - //show campaign map - //with (2,-5) offset from old code - addImage(-1, Mainmenuitems[7], 150 + 2, 60 - 5, 400, 400); - //show levels - int numlevels = Account::active().getCampaignChoicesMade(); - numlevels += numlevels > 0 ? campaignlevels[numlevels - 1].nextlevel.size() : 1; - for (int i = 0; i < numlevels; i++) { - XYZ midpoint = campaignlevels[i].getCenter(); - float itemsize = campaignlevels[i].getWidth(); - const bool active = (i >= Account::active().getCampaignChoicesMade()); - if (!active) { - itemsize /= 2; + case 1: + case 2: + addImage(0, Mainmenuitems[0], 150, 480 - 128, 256, 128); + addButtonImage(1, Mainmenuitems[mainmenu == 1 ? 1 : 5], 18, 480 - 152 - 32, 128, 32); + addButtonImage(2, Mainmenuitems[2], 18, 480 - 228 - 32, 112, 32); + addButtonImage(3, Mainmenuitems[mainmenu == 1 ? 3 : 6], 18, 480 - 306 - 32, mainmenu == 1 ? 68 : 132, 32); + break; + case 3: + addButton(0, "", 10 + 20, 440); + addButton(14, "", 10 + 400, 440); + addButton(1, "", 10 + 60, 405); + addButton(2, "", 10 + 70, 370); + addButton(4, "", 10, 335); + addButton(5, "", 10 + 60, 300); + addButton(6, "", 10 + 70, 265); + addButton(9, "", 10, 230); + addButton(10, "", 20, 195); + addButton(11, "", 10 + 60, 160); + addButton(13, "", 30, 125); + addButton(7, "-Configure Controls-", 10 + 15, 90); + addButton(12, "-Configure Stereo -", 10 + 15, 55); + addButton(8, "Back", 10, 10); + updateSettingsMenu(); + break; + case 4: + addButton(0, "", 10, 400); + addButton(1, "", 10 + 40, 360); + addButton(2, "", 10 + 40, 320); + addButton(3, "", 10 + 30, 280); + addButton(4, "", 10 + 20, 240); + addButton(5, "", 10 + 40, 200); + addButton(6, "", 10 + 40, 160); + addButton(7, "", 10 + 30, 120); + addButton(8, "", 10 + 20, 80); + if (devtools) { + addButton(9, "", 10 + 10, 40); } + addButton(devtools ? 10 : 9, "Back", 10, 10); + updateControlsMenu(); + break; + case 5: { + LoadCampaign(); + addLabel(-1, Account::active().getName(), 5, 400); + addButton(1, "Tutorial", 5, 300); + addButton(2, "Challenge", 5, 240); + addButton(3, "Delete User", 400, 10); + addButton(4, "Main Menu", 5, 10); + addButton(5, "Change User", 5, 180); + addButton(6, "Campaign : " + Account::active().getCurrentCampaign(), 200, 420); + + //show campaign map + //with (2,-5) offset from old code + addImage(-1, Mainmenuitems[7], 150 + 2, 60 - 5, 400, 400); + //show levels + int numlevels = Account::active().getCampaignChoicesMade(); + numlevels += numlevels > 0 ? campaignlevels[numlevels - 1].nextlevel.size() : 1; + for (int i = 0; i < numlevels; i++) { + XYZ midpoint = campaignlevels[i].getCenter(); + float itemsize = campaignlevels[i].getWidth(); + const bool active = (i >= Account::active().getCampaignChoicesMade()); + if (!active) { + itemsize /= 2; + } - if (i >= 1) { - XYZ start = campaignlevels[i - 1].getCenter(); - addMapLine(start.x, start.y, midpoint.x - start.x, midpoint.y - start.y, 0.5, active ? 1 : 0.5, active ? 1 : 0.5, 0, 0); - } - addMapMarker(NB_CAMPAIGN_MENU_ITEM + i, Mapcircletexture, - midpoint.x - itemsize / 2, midpoint.y - itemsize / 2, itemsize, itemsize, active ? 1 : 0.5, 0, 0); + if (i >= 1) { + XYZ start = campaignlevels[i - 1].getCenter(); + addMapLine(start.x, start.y, midpoint.x - start.x, midpoint.y - start.y, 0.5, active ? 1 : 0.5, active ? 1 : 0.5, 0, 0); + } + addMapMarker(NB_CAMPAIGN_MENU_ITEM + i, Mapcircletexture, + midpoint.x - itemsize / 2, midpoint.y - itemsize / 2, itemsize, itemsize, active ? 1 : 0.5, 0, 0); - if (active) { - addMapLabel(-2, campaignlevels[i].description, - campaignlevels[i].getStartX() + 10, - campaignlevels[i].getStartY() - 4); + if (active) { + addMapLabel(-2, campaignlevels[i].description, + campaignlevels[i].getStartX() + 10, + campaignlevels[i].getStartY() - 4); + } } - } - } - break; - case 6: - addLabel(-1, "Are you sure you want to delete this user?", 10, 400); - addButton(1, "Yes", 10, 360); - addButton(2, "No", 10, 320); - break; - case 7: - if (Account::getNbAccounts() < 8) - addButton(0, "New User", 10, 400); - 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++) { - addButton(i + 1, Account::get(i).getName(), 10, 340 - 20 * (i + 1)); - } - break; - case 8: - addButton(0, "Easier", 10, 400); - addButton(1, "Difficult", 10, 360); - addButton(2, "Insane", 10, 320); - break; - case 9: - for (int i = 0; i < numchallengelevels; i++) { - string name = "Level "; - name += to_string(i + 1); - if (name.size() < 17) { - name.append((17 - name.size()), ' '); + } break; + case 6: + addLabel(-1, "Are you sure you want to delete this user?", 10, 400); + addButton(1, "Yes", 10, 360); + addButton(2, "No", 10, 320); + break; + case 7: + if (Account::getNbAccounts() < 8) + addButton(0, "New User", 10, 400); + 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++) { + addButton(i + 1, Account::get(i).getName(), 10, 340 - 20 * (i + 1)); } - name += to_string(int(Account::active().getHighScore(i))); - if (name.size() < 32) { - name.append((32 - name.size()), ' '); + break; + case 8: + addButton(0, "Easier", 10, 400); + addButton(1, "Difficult", 10, 360); + addButton(2, "Insane", 10, 320); + break; + case 9: + for (int i = 0; i < numchallengelevels; i++) { + string name = "Level "; + name += to_string(i + 1); + if (name.size() < 17) { + name.append((17 - name.size()), ' '); + } + name += to_string(int(Account::active().getHighScore(i))); + if (name.size() < 32) { + name.append((32 - name.size()), ' '); + } + int fasttime = (int)round(Account::active().getFastTime(i)); + name += to_string(int((fasttime - fasttime % 60) / 60)); + name += ":"; + 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); } - int fasttime = (int)round(Account::active().getFastTime(i)); - name += to_string(int((fasttime - fasttime % 60) / 60)); - name += ":"; - 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); - } - addButton(-1, " High Score Best Time", 10, 440); - addButton(numchallengelevels, "Back", 10, 10); - break; - case 10: { - addLabel(0, "Congratulations!", 220, 330); - addLabel(1, "You have avenged your family and", 140, 300); - addLabel(2, "restored peace to the island of Lugaru.", 110, 270); - addButton(3, "Back", 10, 10); - addLabel(4, string("Your score: ") + to_string((int)Account::active().getCampaignScore()), 190, 200); - addLabel(5, string("Highest score: ") + to_string((int)Account::active().getCampaignHighScore()), 190, 180); - } - break; - case 18: - addButton(0, "", 70, 400); - addButton(1, "", 10, 360); - addButton(2, "", 40, 320); - addButton(3, "Back", 10, 10); - updateStereoConfigMenu(); - break; + addButton(-1, " High Score Best Time", 10, 440); + addButton(numchallengelevels, "Back", 10, 10); + break; + case 10: { + addLabel(0, "Congratulations!", 220, 330); + addLabel(1, "You have avenged your family and", 140, 300); + addLabel(2, "restored peace to the island of Lugaru.", 110, 270); + addButton(3, "Back", 10, 10); + addLabel(4, string("Your score: ") + to_string((int)Account::active().getCampaignScore()), 190, 200); + addLabel(5, string("Highest score: ") + to_string((int)Account::active().getCampaignHighScore()), 190, 180); + } break; + case 18: + addButton(0, "", 70, 400); + addButton(1, "", 10, 360); + addButton(2, "", 40, 320); + addButton(3, "Back", 10, 10); + updateStereoConfigMenu(); + break; } } @@ -516,20 +519,20 @@ void Menu::Tick() } //go back switch (mainmenu) { - case 3: - case 5: - mainmenu = gameon ? 2 : 1; - break; - case 4: - case 18: - mainmenu = 3; - break; - case 6: - case 7: - case 9: - case 10: - mainmenu = 5; - break; + case 3: + case 5: + mainmenu = gameon ? 2 : 1; + break; + case 4: + case 18: + mainmenu = 3; + break; + case 6: + case 7: + case 9: + case 10: + mainmenu = 5; + break; } } @@ -551,320 +554,320 @@ void Menu::Tick() static int oldmainmenu = mainmenu; if (Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus - set>::iterator newscreenresolution; + set>::iterator newscreenresolution; switch (mainmenu) { - case 1: - case 2: - switch (selected) { case 1: - if (gameon) { //resume - mainmenu = 0; - pause_sound(stream_menutheme); - resume_stream(leveltheme); - } else { //new game - fireSound(firestartsound); - flash(); - mainmenu = (Account::hasActive() ? 5 : 7); - selected = -1; + case 2: + switch (selected) { + case 1: + if (gameon) { //resume + mainmenu = 0; + pause_sound(stream_menutheme); + resume_stream(leveltheme); + } else { //new game + fireSound(firestartsound); + flash(); + mainmenu = (Account::hasActive() ? 5 : 7); + selected = -1; + } + break; + case 2: //options + fireSound(); + flash(); + mainmenu = 3; + if (newdetail > 2) + newdetail = detail; + if (newdetail < 0) + newdetail = detail; + if (newscreenwidth > 3000) + newscreenwidth = screenwidth; + if (newscreenwidth < 0) + newscreenwidth = screenwidth; + if (newscreenheight > 3000) + newscreenheight = screenheight; + if (newscreenheight < 0) + newscreenheight = screenheight; + break; + case 3: + fireSound(); + flash(); + if (gameon) { //end game + gameon = 0; + mainmenu = 1; + } else { //quit + tryquit = 1; + pause_sound(stream_menutheme); + } + break; } break; - case 2: //options - fireSound(); - flash(); - mainmenu = 3; - if (newdetail > 2) - newdetail = detail; - if (newdetail < 0) - newdetail = detail; - if (newscreenwidth > 3000) - newscreenwidth = screenwidth; - if (newscreenwidth < 0) - newscreenwidth = screenwidth; - if (newscreenheight > 3000) - newscreenheight = screenheight; - if (newscreenheight < 0) - newscreenheight = screenheight; - break; case 3: fireSound(); - flash(); - if (gameon) { //end game - gameon = 0; - mainmenu = 1; - } else { //quit - tryquit = 1; - pause_sound(stream_menutheme); + switch (selected) { + case 0: + newscreenresolution = resolutions.find(make_pair(newscreenwidth, newscreenheight)); + /* Next one (end() + 1 is also end() so the ++ is safe even if it was not found) */ + newscreenresolution++; + if (newscreenresolution == resolutions.end()) { + /* It was the last one (or not found), go back to the beginning */ + newscreenresolution = resolutions.begin(); + } + newscreenwidth = newscreenresolution->first; + newscreenheight = newscreenresolution->second; + break; + case 1: + newdetail++; + if (newdetail > 2) + newdetail = 0; + break; + case 2: + bloodtoggle++; + if (bloodtoggle > 2) + bloodtoggle = 0; + break; + case 4: + ismotionblur = !ismotionblur; + break; + case 5: + decalstoggle = !decalstoggle; + break; + case 6: + musictoggle = !musictoggle; + if (musictoggle) { + emit_stream_np(stream_menutheme); + } else { + pause_sound(leveltheme); + pause_sound(stream_fighttheme); + pause_sound(stream_menutheme); + + for (int i = 0; i < 4; i++) { + oldmusicvolume[i] = 0; + musicvolume[i] = 0; + } + } + break; + case 7: // controls + flash(); + mainmenu = 4; + selected = -1; + keyselect = -1; + break; + case 8: + flash(); + SaveSettings(); + mainmenu = gameon ? 2 : 1; + break; + case 9: + invertmouse = !invertmouse; + break; + case 10: + usermousesensitivity += .2; + if (usermousesensitivity > 2) + usermousesensitivity = .2; + break; + case 11: + volume += .1f; + if (volume > 1.0001f) + volume = 0; + OPENAL_SetSFXMasterVolume((int)(volume * 255)); + break; + case 12: + flash(); + newstereomode = stereomode; + mainmenu = 18; + keyselect = -1; + break; + case 13: + showdamagebar = !showdamagebar; + break; + case 14: + toggleFullscreen(); + break; } - break; - } - break; - case 3: - fireSound(); - switch (selected) { - case 0: - newscreenresolution = resolutions.find(make_pair(newscreenwidth, newscreenheight)); - /* Next one (end() + 1 is also end() so the ++ is safe even if it was not found) */ - newscreenresolution++; - if (newscreenresolution == resolutions.end()) { - /* It was the last one (or not found), go back to the beginning */ - newscreenresolution = resolutions.begin(); - } - newscreenwidth = newscreenresolution->first; - newscreenheight = newscreenresolution->second; - break; - case 1: - newdetail++; - if (newdetail > 2) - newdetail = 0; - break; - case 2: - bloodtoggle++; - if (bloodtoggle > 2) - bloodtoggle = 0; + updateSettingsMenu(); break; case 4: - ismotionblur = !ismotionblur; + if (!waiting) { + fireSound(); + if (selected < (devtools ? 10 : 9) && keyselect == -1) + keyselect = selected; + if (keyselect != -1) + setKeySelected(); + if (selected == (devtools ? 10 : 9)) { + flash(); + mainmenu = 3; + } + } + updateControlsMenu(); break; case 5: - decalstoggle = !decalstoggle; + fireSound(); + flash(); + if ((selected - NB_CAMPAIGN_MENU_ITEM >= Account::active().getCampaignChoicesMade())) { + startbonustotal = 0; + + loading = 2; + loadtime = 0; + targetlevel = 7; + if (firstLoadDone) { + TickOnceAfter(); + } else { + LoadStuff(); + } + whichchoice = selected - NB_CAMPAIGN_MENU_ITEM - Account::active().getCampaignChoicesMade(); + actuallevel = (Account::active().getCampaignChoicesMade() > 0 ? campaignlevels[Account::active().getCampaignChoicesMade() - 1].nextlevel[whichchoice] : 0); + visibleloading = true; + stillloading = 1; + LoadLevel(campaignlevels[actuallevel].mapname.c_str()); + campaign = 1; + mainmenu = 0; + gameon = 1; + pause_sound(stream_menutheme); + } + switch (selected) { + case 1: + startbonustotal = 0; + + loading = 2; + loadtime = 0; + targetlevel = -1; + if (firstLoadDone) { + TickOnceAfter(); + } else { + LoadStuff(); + } + LoadLevel(-1); + + mainmenu = 0; + gameon = 1; + pause_sound(stream_menutheme); + break; + case 2: + mainmenu = 9; + break; + case 3: + mainmenu = 6; + break; + case 4: + mainmenu = (gameon ? 2 : 1); + break; + case 5: + mainmenu = 7; + break; + case 6: + vector campaigns = ListCampaigns(); + vector::iterator c; + if ((c = find(campaigns.begin(), campaigns.end(), Account::active().getCurrentCampaign())) == campaigns.end()) { + if (!campaigns.empty()) + Account::active().setCurrentCampaign(campaigns.front()); + } else { + c++; + if (c == campaigns.end()) + c = campaigns.begin(); + Account::active().setCurrentCampaign(*c); + } + Load(); + break; + } break; case 6: - musictoggle = !musictoggle; - if (musictoggle) { - emit_stream_np(stream_menutheme); - } else { - pause_sound(leveltheme); - pause_sound(stream_fighttheme); - pause_sound(stream_menutheme); - - for (int i = 0; i < 4; i++) { - oldmusicvolume[i] = 0; - musicvolume[i] = 0; - } + fireSound(); + if (selected == 1) { + flash(); + Account::destroyActive(); + mainmenu = 7; + } else if (selected == 2) { + flash(); + mainmenu = 5; } break; - case 7: // controls - flash(); - mainmenu = 4; - selected = -1; - keyselect = -1; + case 7: + fireSound(); + if (selected == 0 && Account::getNbAccounts() < 8) { + entername = 1; + } else if (selected < Account::getNbAccounts() + 1) { + flash(); + mainmenu = 5; + Account::setActive(selected - 1); + } else if (selected == Account::getNbAccounts() + 1) { + flash(); + if (Account::hasActive()) { + mainmenu = 5; + } else { + mainmenu = 1; + } + newusername.clear(); + newuserselected = 0; + entername = 0; + } break; case 8: + fireSound(); flash(); - SaveSettings(); - mainmenu = gameon ? 2 : 1; + if (selected <= 2) + Account::active().setDifficulty(selected); + mainmenu = 5; break; case 9: - invertmouse = !invertmouse; - break; - case 10: - usermousesensitivity += .2; - if (usermousesensitivity > 2) - usermousesensitivity = .2; - break; - case 11: - volume += .1f; - if (volume > 1.0001f) - volume = 0; - OPENAL_SetSFXMasterVolume((int)(volume * 255)); - break; - case 12: - flash(); - newstereomode = stereomode; - mainmenu = 18; - keyselect = -1; - break; - case 13: - showdamagebar = !showdamagebar; - break; - case 14: - toggleFullscreen(); - break; - } - updateSettingsMenu(); - break; - case 4: - if (!waiting) { - fireSound(); - if (selected < (devtools ? 10 : 9) && keyselect == -1) - keyselect = selected; - if (keyselect != -1) - setKeySelected(); - if (selected == (devtools ? 10 : 9)) { + if (selected < numchallengelevels && selected <= Account::active().getProgress()) { + fireSound(); flash(); - mainmenu = 3; - } - } - updateControlsMenu(); - break; - case 5: - fireSound(); - flash(); - if ((selected - NB_CAMPAIGN_MENU_ITEM >= Account::active().getCampaignChoicesMade())) { - startbonustotal = 0; - - loading = 2; - loadtime = 0; - targetlevel = 7; - if (firstLoadDone) { - TickOnceAfter(); - } else { - LoadStuff(); - } - whichchoice = selected - NB_CAMPAIGN_MENU_ITEM - Account::active().getCampaignChoicesMade(); - actuallevel = (Account::active().getCampaignChoicesMade() > 0 ? campaignlevels[Account::active().getCampaignChoicesMade() - 1].nextlevel[whichchoice] : 0); - visibleloading = true; - stillloading = 1; - LoadLevel(campaignlevels[actuallevel].mapname.c_str()); - campaign = 1; - mainmenu = 0; - gameon = 1; - pause_sound(stream_menutheme); - } - switch (selected) { - case 1: - startbonustotal = 0; - loading = 2; - loadtime = 0; - targetlevel = -1; - if (firstLoadDone) { - TickOnceAfter(); - } else { - LoadStuff(); - } - LoadLevel(-1); + startbonustotal = 0; - mainmenu = 0; - gameon = 1; - pause_sound(stream_menutheme); - break; - case 2: - mainmenu = 9; - break; - case 3: - mainmenu = 6; - break; - case 4: - mainmenu = (gameon ? 2 : 1); - break; - case 5: - mainmenu = 7; - break; - case 6: - vector campaigns = ListCampaigns(); - vector::iterator c; - if ((c = find(campaigns.begin(), campaigns.end(), Account::active().getCurrentCampaign())) == campaigns.end()) { - if (!campaigns.empty()) - Account::active().setCurrentCampaign(campaigns.front()); - } else { - c++; - if (c == campaigns.end()) - c = campaigns.begin(); - Account::active().setCurrentCampaign(*c); + loading = 2; + loadtime = 0; + targetlevel = selected; + if (firstLoadDone) { + TickOnceAfter(); + } else { + LoadStuff(); + } + LoadLevel(selected); + campaign = 0; + + mainmenu = 0; + gameon = 1; + pause_sound(stream_menutheme); } - Load(); - break; - } - break; - case 6: - fireSound(); - if (selected == 1) { - flash(); - Account::destroyActive(); - mainmenu = 7; - } else if (selected == 2) { - flash(); - mainmenu = 5; - } - break; - case 7: - fireSound(); - if (selected == 0 && Account::getNbAccounts() < 8) { - entername = 1; - } else if (selected < Account::getNbAccounts() + 1) { - flash(); - mainmenu = 5; - Account::setActive(selected - 1); - } else if (selected == Account::getNbAccounts() + 1) { - flash(); - if (Account::hasActive()) { + if (selected == numchallengelevels) { + fireSound(); + flash(); mainmenu = 5; - } else { - mainmenu = 1; } - newusername.clear(); - newuserselected = 0; - entername = 0; - } - break; - case 8: - fireSound(); - flash(); - if (selected <= 2) - Account::active().setDifficulty(selected); - mainmenu = 5; - break; - case 9: - if (selected < numchallengelevels && selected <= Account::active().getProgress()) { - fireSound(); - flash(); - - startbonustotal = 0; - - loading = 2; - loadtime = 0; - targetlevel = selected; - if (firstLoadDone) { - TickOnceAfter(); - } else { - LoadStuff(); + break; + case 10: + if (selected == 3) { + fireSound(); + flash(); + mainmenu = 5; } - LoadLevel(selected); - campaign = 0; - - mainmenu = 0; - gameon = 1; - pause_sound(stream_menutheme); - } - if (selected == numchallengelevels) { - fireSound(); - flash(); - mainmenu = 5; - } - break; - case 10: - if (selected == 3) { - fireSound(); - flash(); - mainmenu = 5; - } - break; - case 18: - if (selected == 1) - stereoseparation += 0.001; - 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); + break; + case 18: + if (selected == 1) + stereoseparation += 0.001; + else { + fireSound(); + if (selected == 0) { newstereomode = (StereoMode)(newstereomode + 1); - if (newstereomode >= stereoCount) - newstereomode = stereoNone; + while (!CanInitStereo(newstereomode)) { + printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode).c_str(), newstereomode); + newstereomode = (StereoMode)(newstereomode + 1); + if (newstereomode >= stereoCount) + newstereomode = stereoNone; + } + } else if (selected == 2) { + stereoreverse = !stereoreverse; + } else if (selected == 3) { + flash(); + mainmenu = 3; + + stereomode = newstereomode; + InitStereo(stereomode); } - } else if (selected == 2) { - stereoreverse = !stereoreverse; - } else if (selected == 3) { - flash(); - mainmenu = 3; - - stereomode = newstereomode; - InitStereo(stereomode); } - } - updateStereoConfigMenu(); - break; + updateStereoConfigMenu(); + break; } } @@ -872,7 +875,7 @@ void Menu::Tick() if (entername) { inputText(newusername, &newuserselected); - if (!waiting) { // the input as finished + if (!waiting) { // the input as finished if (!newusername.empty()) { // with enter Account::add(string(newusername)); @@ -905,7 +908,6 @@ void Menu::Tick() if (oldmainmenu != mainmenu) Load(); oldmainmenu = mainmenu; - } int setKeySelected_thread(void*) @@ -916,51 +918,51 @@ int setKeySelected_thread(void*) while (scancode == -1) { SDL_WaitEvent(&evenement); switch (evenement.type) { - case SDL_KEYDOWN: - scancode = evenement.key.keysym.scancode; - break; - case SDL_MOUSEBUTTONDOWN: - scancode = SDL_NUM_SCANCODES + evenement.button.button; - break; - default: - break; + case SDL_KEYDOWN: + scancode = evenement.key.keysym.scancode; + break; + case SDL_MOUSEBUTTONDOWN: + scancode = SDL_NUM_SCANCODES + evenement.button.button; + break; + default: + break; } } if (scancode != SDL_SCANCODE_ESCAPE) { fireSound(); switch (keyselect) { - case 0: - forwardkey = scancode; - break; - case 1: - backkey = scancode; - break; - case 2: - leftkey = scancode; - break; - case 3: - rightkey = scancode; - break; - case 4: - crouchkey = scancode; - break; - case 5: - jumpkey = scancode; - break; - case 6: - drawkey = scancode; - break; - case 7: - throwkey = scancode; - break; - case 8: - attackkey = scancode; - break; - case 9: - consolekey = scancode; - break; - default: - break; + case 0: + forwardkey = scancode; + break; + case 1: + backkey = scancode; + break; + case 2: + leftkey = scancode; + break; + case 3: + rightkey = scancode; + break; + case 4: + crouchkey = scancode; + break; + case 5: + jumpkey = scancode; + break; + case 6: + drawkey = scancode; + break; + case 7: + throwkey = scancode; + break; + case 8: + attackkey = scancode; + break; + case 9: + consolekey = scancode; + break; + default: + break; } } keyselect = -1; @@ -974,7 +976,7 @@ void Menu::setKeySelected() waiting = true; printf("launch thread\n"); SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL); - if ( thread == NULL ) { + if (thread == NULL) { fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError()); waiting = false; return; diff --git a/Source/Objects/Object.cpp b/Source/Objects/Object.cpp index 13f124c..f0dd169 100644 --- a/Source/Objects/Object.cpp +++ b/Source/Objects/Object.cpp @@ -47,30 +47,31 @@ Texture Object::rocktextureptr; //Functions -Object::Object() : - position(), - type(boxtype), - yaw(0), - pitch(0), - rotx(0), - rotxvel(0), - roty(0), - rotyvel(0), - possible(false), - model(), - displaymodel(), - friction(0), - scale(0), - messedwith(0), - checked(0), - shadowed(0), - occluded(0), - onfire(false), - flamedelay(0) +Object::Object() + : position() + , type(boxtype) + , yaw(0) + , pitch(0) + , rotx(0) + , rotxvel(0) + , roty(0) + , rotyvel(0) + , possible(false) + , model() + , displaymodel() + , friction(0) + , scale(0) + , messedwith(0) + , checked(0) + , shadowed(0) + , occluded(0) + , onfire(false) + , flamedelay(0) { } -Object::Object(object_type _type, XYZ _position, float _yaw, float _pitch, float _scale) : Object() +Object::Object(object_type _type, XYZ _position, float _yaw, float _pitch, float _scale) + : Object() { scale = _scale; type = _type; @@ -78,7 +79,7 @@ Object::Object(object_type _type, XYZ _position, float _yaw, float _pitch, float yaw = _yaw; pitch = _pitch; - switch(type) { + switch (type) { case boxtype: model.loaddecal("Models/Box.solid"); friction = 1.5; @@ -250,12 +251,18 @@ void Object::handleRot(int divide) { messedwith -= multiplier; if (rotxvel || rotx) { - if (rotx > 0) rotxvel -= multiplier * 8 * fabs(rotx); - if (rotx < 0) rotxvel += multiplier * 8 * fabs(rotx); - if (rotx > 0) rotxvel -= multiplier * 4; - if (rotx < 0) rotxvel += multiplier * 4; - if (rotxvel > 0) rotxvel -= multiplier * 4; - if (rotxvel < 0) rotxvel += multiplier * 4; + if (rotx > 0) + rotxvel -= multiplier * 8 * fabs(rotx); + if (rotx < 0) + rotxvel += multiplier * 8 * fabs(rotx); + if (rotx > 0) + rotxvel -= multiplier * 4; + if (rotx < 0) + rotxvel += multiplier * 4; + if (rotxvel > 0) + rotxvel -= multiplier * 4; + if (rotxvel < 0) + rotxvel += multiplier * 4; if (fabs(rotx) < multiplier * 4) rotx = 0; if (fabs(rotxvel) < multiplier * 4) @@ -264,12 +271,18 @@ void Object::handleRot(int divide) rotx += rotxvel * multiplier * 4; } if (rotyvel || roty) { - if (roty > 0) rotyvel -= multiplier * 8 * fabs(roty); - if (roty < 0) rotyvel += multiplier * 8 * fabs(roty); - if (roty > 0) rotyvel -= multiplier * 4; - if (roty < 0) rotyvel += multiplier * 4; - if (rotyvel > 0) rotyvel -= multiplier * 4; - if (rotyvel < 0) rotyvel += multiplier * 4; + if (roty > 0) + rotyvel -= multiplier * 8 * fabs(roty); + if (roty < 0) + rotyvel += multiplier * 8 * fabs(roty); + if (roty > 0) + rotyvel -= multiplier * 4; + if (roty < 0) + rotyvel += multiplier * 4; + if (rotyvel > 0) + rotyvel -= multiplier * 4; + if (rotyvel < 0) + rotyvel += multiplier * 4; if (fabs(roty) < multiplier * 4) roty = 0; if (fabs(rotyvel) < multiplier * 4) @@ -309,9 +322,9 @@ void Object::draw() if (!hidden) { if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment) - glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness ); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness); else - glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); + 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) distance = 1; @@ -561,7 +574,7 @@ void Object::AddObjectsToTerrain() } } -void Object::SphereCheckPossible(XYZ *p1, float radius) +void Object::SphereCheckPossible(XYZ* p1, float radius) { int whichpatchx = p1->x / (terrain.size / subdivision * terrain.scale); int whichpatchz = p1->z / (terrain.size / subdivision * terrain.scale); @@ -585,12 +598,12 @@ void Object::Draw() objects[i]->draw(); } - glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0); for (unsigned i = 0; i < objects.size(); i++) { objects[i]->drawSecondPass(); } if (environment == desertenvironment) { - glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0); } glEnable(GL_ALPHA_TEST); SetUpLight(&light, 0); @@ -644,7 +657,7 @@ int Object::checkcollide(XYZ startpoint, XYZ endpoint) for (unsigned int i = 0; i < objects.size(); i++) { if (checkcollide(startpoint, endpoint, i, minx, miny, minz, maxx, maxy, maxz) != -1) { - return (int) i; + return (int)i; } } @@ -674,15 +687,15 @@ int Object::checkcollide(XYZ startpoint, XYZ endpoint, int what, float minx, flo return what; } } else { - if ( objects[what]->position.x > minx - objects[what]->model.boundingsphereradius && - objects[what]->position.x < maxx + objects[what]->model.boundingsphereradius && - objects[what]->position.y > miny - objects[what]->model.boundingsphereradius && - objects[what]->position.y < maxy + objects[what]->model.boundingsphereradius && - objects[what]->position.z > minz - objects[what]->model.boundingsphereradius && - objects[what]->position.z < maxz + objects[what]->model.boundingsphereradius) { - if ( objects[what]->type != treeleavestype && - objects[what]->type != bushtype && - objects[what]->type != firetype) { + if (objects[what]->position.x > minx - objects[what]->model.boundingsphereradius && + objects[what]->position.x < maxx + objects[what]->model.boundingsphereradius && + objects[what]->position.y > miny - objects[what]->model.boundingsphereradius && + objects[what]->position.y < maxy + objects[what]->model.boundingsphereradius && + objects[what]->position.z > minz - objects[what]->model.boundingsphereradius && + objects[what]->position.z < maxz + objects[what]->model.boundingsphereradius) { + if (objects[what]->type != treeleavestype && + objects[what]->type != bushtype && + objects[what]->type != firetype) { colviewer = startpoint; coltarget = endpoint; if (objects[what]->model.LineCheck(&colviewer, &coltarget, &colpoint, &objects[what]->position, &objects[what]->yaw) != -1) { @@ -697,8 +710,8 @@ int Object::checkcollide(XYZ startpoint, XYZ endpoint, int what, float minx, flo //~ Object::~Objects() //~ { - //~ boxtextureptr.destroy(); - //~ treetextureptr.destroy(); - //~ bushtextureptr.destroy(); - //~ rocktextureptr.destroy(); +//~ boxtextureptr.destroy(); +//~ treetextureptr.destroy(); +//~ bushtextureptr.destroy(); +//~ rocktextureptr.destroy(); //~ } diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index a6f2bc1..3c89326 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -21,13 +21,13 @@ along with Lugaru. If not, see . #include "Objects/Person.hpp" #include "Animation/Animation.hpp" -#include "Audio/openal_wrapper.hpp" #include "Audio/Sounds.hpp" +#include "Audio/openal_wrapper.hpp" #include "Game.hpp" #include "Level/Awards.hpp" #include "Level/Dialog.hpp" -#include "Utils/Folders.hpp" #include "Tutorial.hpp" +#include "Utils/Folders.hpp" extern float multiplier; extern Terrain terrain; @@ -76,244 +76,299 @@ extern XYZ windvector; std::vector> Person::players(1, std::shared_ptr(new Person())); -Person::Person() : - whichpatchx(0), - whichpatchz(0), - animCurrent(bounceidleanim), - animTarget(bounceidleanim), - frameCurrent(0), - frameTarget(1), - oldanimCurrent(0), - oldanimTarget(0), - oldframeCurrent(0), - oldframeTarget(0), - howactive(typeactive), - parriedrecently(0), - superruntoggle(false), - lastattack(0), lastattack2(0), lastattack3(0), - currentoffset(), targetoffset(), offset(), - target(0), - transspeed(0), - - realoldcoords(), - oldcoords(), - coords(), - velocity(), - - proportionhead(), - proportionlegs(), - proportionarms(), - proportionbody(), - - unconscioustime(0), - - immobile(false), - - velspeed(0), - targetyaw(0), - targetrot(0), - rot(0), - oldrot(0), - lookyaw(0), - lookpitch(0), - yaw(0), - pitch(0), - lowyaw(0), - tilt(0), - targettilt(0), - tilt2(0), - targettilt2(0), - rabbitkickenabled(false), - - bloodloss(0), - bleeddelay(0), - skiddelay(0), - skiddingdelay(0), - deathbleeding(0), - tempdeltav(0), - - damagetolerance(200), - damage(0), - permanentdamage(0), - superpermanentdamage(0), - lastcollide(0), - dead(0), - - jumppower(5), - onground(false), - - wentforweapon(0), - - calcrot(false), - - facing(), - - bleeding(0), - bleedx(0), bleedy(0), - direction(0), - texupdatedelay(0), - - headyaw(0), headpitch(0), - targetheadyaw(0), targetheadpitch(0), - - onterrain(false), - pause(false), - - grabdelay(0), - - victim(nullptr), - hasvictim(false), - - updatedelay(0), - normalsupdatedelay(0), - - jumpstart(false), - forwardkeydown(false), - forwardstogglekeydown(false), - rightkeydown(false), - leftkeydown(false), - backkeydown(false), - jumpkeydown(false), - jumptogglekeydown(false), - crouchkeydown(false), - crouchtogglekeydown(false), - drawkeydown(false), - drawtogglekeydown(false), - throwkeydown(false), - throwtogglekeydown(false), - attackkeydown(false), - feint(false), - lastfeint(false), - headless(false), - - crouchkeydowntime(0), - jumpkeydowntime(0), - freefall(false), - - turnspeed(0), - - aitype(passivetype), - aiupdatedelay(0), - losupdatedelay(0), - ally(0), - collide(0), - collided(-10), - avoidcollided(0), - loaded(false), - whichdirection(false), - whichdirectiondelay(0), - avoidsomething(false), - avoidwhere(), - blooddimamount(0), - - staggerdelay(0), - blinkdelay(0), - twitchdelay(0), - twitchdelay2(0), - twitchdelay3(0), - lefthandmorphness(0), - righthandmorphness(0), - headmorphness(0), - chestmorphness(0), - tailmorphness(0), - targetlefthandmorphness(0), - targetrighthandmorphness(0), - targetheadmorphness(1), - targetchestmorphness(0), - targettailmorphness(0), - lefthandmorphstart(0), lefthandmorphend(0), - righthandmorphstart(0), righthandmorphend(0), - headmorphstart(0), headmorphend(0), - chestmorphstart(0), chestmorphend(0), - tailmorphstart(0), tailmorphend(0), - - weaponmissdelay(0), - highreversaldelay(0), - lowreversaldelay(0), - - creature(rabbittype), - - id(0), - - skeleton(), - - speed(0), - scale(-1), - power(0), - speedmult(0), - - protectionhead(0), - protectionhigh(0), - protectionlow(0), - armorhead(0), - armorhigh(0), - armorlow(0), - metalhead(false), - metalhigh(false), - metallow(false), - - numclothes(0), - - landhard(false), - bled(false), - spurt(false), - onfire(false), - onfiredelay(0), - burnt(0), - - flamedelay(0), - - playerdetail(0), - - num_weapons(0), - weaponactive(-1), - weaponstuck(-1), - weaponstuckwhere(0), - - numwaypoints(0), - pausetime(0), - - headtarget(), - interestdelay(0), - - finalfinaltarget(), - finaltarget(), - finalpathfindpoint(0), - targetpathfindpoint(0), - lastpathfindpoint(0), - lastpathfindpoint2(0), - lastpathfindpoint3(0), - lastpathfindpoint4(0), - - waypoint(0), - - lastseen(), - lastseentime(0), - lastchecktime(0), - stunned(0), - surprised(0), - runninghowlong(0), - occluded(0), - lastoccluded(0), - laststanding(0), - escapednum(0), - - speechdelay(0), - neckspurtdelay(0), - neckspurtparticledelay(0), - neckspurtamount(0), - - whichskin(0), - rabbitkickragdoll(false), - - tempanimation(), +Person::Person() + : whichpatchx(0) + , whichpatchz(0) + , animCurrent(bounceidleanim) + , animTarget(bounceidleanim) + , frameCurrent(0) + , frameTarget(1) + , oldanimCurrent(0) + , oldanimTarget(0) + , oldframeCurrent(0) + , oldframeTarget(0) + , howactive(typeactive) + , parriedrecently(0) + , superruntoggle(false) + , lastattack(0) + , lastattack2(0) + , lastattack3(0) + , currentoffset() + , targetoffset() + , offset() + , target(0) + , transspeed(0) + , + + realoldcoords() + , oldcoords() + , coords() + , velocity() + , + + proportionhead() + , proportionlegs() + , proportionarms() + , proportionbody() + , + + unconscioustime(0) + , + + immobile(false) + , + + velspeed(0) + , targetyaw(0) + , targetrot(0) + , rot(0) + , oldrot(0) + , lookyaw(0) + , lookpitch(0) + , yaw(0) + , pitch(0) + , lowyaw(0) + , tilt(0) + , targettilt(0) + , tilt2(0) + , targettilt2(0) + , rabbitkickenabled(false) + , + + bloodloss(0) + , bleeddelay(0) + , skiddelay(0) + , skiddingdelay(0) + , deathbleeding(0) + , tempdeltav(0) + , + + damagetolerance(200) + , damage(0) + , permanentdamage(0) + , superpermanentdamage(0) + , lastcollide(0) + , dead(0) + , + + jumppower(5) + , onground(false) + , + + wentforweapon(0) + , + + calcrot(false) + , + + facing() + , + + bleeding(0) + , bleedx(0) + , bleedy(0) + , direction(0) + , texupdatedelay(0) + , + + headyaw(0) + , headpitch(0) + , targetheadyaw(0) + , targetheadpitch(0) + , + + onterrain(false) + , pause(false) + , + + grabdelay(0) + , + + victim(nullptr) + , hasvictim(false) + , + + updatedelay(0) + , normalsupdatedelay(0) + , + + jumpstart(false) + , forwardkeydown(false) + , forwardstogglekeydown(false) + , rightkeydown(false) + , leftkeydown(false) + , backkeydown(false) + , jumpkeydown(false) + , jumptogglekeydown(false) + , crouchkeydown(false) + , crouchtogglekeydown(false) + , drawkeydown(false) + , drawtogglekeydown(false) + , throwkeydown(false) + , throwtogglekeydown(false) + , attackkeydown(false) + , feint(false) + , lastfeint(false) + , headless(false) + , + + crouchkeydowntime(0) + , jumpkeydowntime(0) + , freefall(false) + , + + turnspeed(0) + , + + aitype(passivetype) + , aiupdatedelay(0) + , losupdatedelay(0) + , ally(0) + , collide(0) + , collided(-10) + , avoidcollided(0) + , loaded(false) + , whichdirection(false) + , whichdirectiondelay(0) + , avoidsomething(false) + , avoidwhere() + , blooddimamount(0) + , + + staggerdelay(0) + , blinkdelay(0) + , twitchdelay(0) + , twitchdelay2(0) + , twitchdelay3(0) + , lefthandmorphness(0) + , righthandmorphness(0) + , headmorphness(0) + , chestmorphness(0) + , tailmorphness(0) + , targetlefthandmorphness(0) + , targetrighthandmorphness(0) + , targetheadmorphness(1) + , targetchestmorphness(0) + , targettailmorphness(0) + , lefthandmorphstart(0) + , lefthandmorphend(0) + , righthandmorphstart(0) + , righthandmorphend(0) + , headmorphstart(0) + , headmorphend(0) + , chestmorphstart(0) + , chestmorphend(0) + , tailmorphstart(0) + , tailmorphend(0) + , + + weaponmissdelay(0) + , highreversaldelay(0) + , lowreversaldelay(0) + , + + creature(rabbittype) + , + + id(0) + , + + skeleton() + , + + speed(0) + , scale(-1) + , power(0) + , speedmult(0) + , + + protectionhead(0) + , protectionhigh(0) + , protectionlow(0) + , armorhead(0) + , armorhigh(0) + , armorlow(0) + , metalhead(false) + , metalhigh(false) + , metallow(false) + , + + numclothes(0) + , + + landhard(false) + , bled(false) + , spurt(false) + , onfire(false) + , onfiredelay(0) + , burnt(0) + , + + flamedelay(0) + , + + playerdetail(0) + , + + num_weapons(0) + , weaponactive(-1) + , weaponstuck(-1) + , weaponstuckwhere(0) + , + + numwaypoints(0) + , pausetime(0) + , + + headtarget() + , interestdelay(0) + , + + finalfinaltarget() + , finaltarget() + , finalpathfindpoint(0) + , targetpathfindpoint(0) + , lastpathfindpoint(0) + , lastpathfindpoint2(0) + , lastpathfindpoint3(0) + , lastpathfindpoint4(0) + , + + waypoint(0) + , + + lastseen() + , lastseentime(0) + , lastchecktime(0) + , stunned(0) + , surprised(0) + , runninghowlong(0) + , occluded(0) + , lastoccluded(0) + , laststanding(0) + , escapednum(0) + , + + speechdelay(0) + , neckspurtdelay(0) + , neckspurtparticledelay(0) + , neckspurtamount(0) + , + + whichskin(0) + , rabbitkickragdoll(false) + , + + tempanimation() + , jumpclimb(false) { } /* Read a person in tfile. Throws an error if it’s not valid */ -Person::Person(FILE *tfile, int mapvers, unsigned i) : Person() +Person::Person(FILE* tfile, int mapvers, unsigned i) + : Person() { id = i; funpackf(tfile, "Bi Bi Bf Bf Bf Bi", &whichskin, &creature, &coords.x, &coords.y, &coords.z, &num_weapons); @@ -437,8 +492,7 @@ void Person::skeletonLoad(bool clothes) "Models/Body7.solid", "Models/BodyLow.solid", "Models/Belt.solid", - clothes - ); + clothes); } else { skeleton.Load( "Skeleton/BasicFigureWolf", @@ -453,8 +507,7 @@ void Person::skeletonLoad(bool clothes) "Models/Wolf7.solid", "Models/WolfLow.solid", "Models/Belt.solid", - clothes - ); + clothes); } skeleton.drawmodel.textureptr.load(creatureskin[creature][whichskin], 1, &skeleton.skinText[0], &skeleton.skinsize); @@ -467,14 +520,7 @@ 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) { @@ -567,8 +613,8 @@ int Person::getIdle() 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())) { + victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && + victim->id < Person::players.size())) { if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) { if (creature == rabbittype) return fightidleanim; @@ -591,15 +637,24 @@ int Person::getIdle() } if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype) return hurtidleanim; - if (howactive == typesitting) return sitanim; - if (howactive == typesittingwall) return sitwallanim; - if (howactive == typesleeping) return sleepanim; - if (howactive == typedead1) return dead1anim; - if (howactive == typedead2) return dead2anim; - if (howactive == typedead3) return dead3anim; - if (howactive == typedead4) return dead4anim; - if (creature == rabbittype) return bounceidleanim; - if (creature == wolftype) return wolfidle; + if (howactive == typesitting) + return sitanim; + if (howactive == typesittingwall) + return sitwallanim; + if (howactive == typesleeping) + return sleepanim; + if (howactive == typedead1) + return dead1anim; + if (howactive == typedead2) + return dead2anim; + if (howactive == typedead3) + return dead3anim; + if (howactive == typedead4) + return dead4anim; + if (creature == rabbittype) + return bounceidleanim; + if (creature == wolftype) + return wolfidle; return 0; } @@ -702,8 +757,8 @@ void Person::DoBlood(float howmuch, int which) bloodvel.z = 10; bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale; bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale; - Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1); - Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1); + Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1); + 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 @@ -723,7 +778,7 @@ void Person::DoBlood(float howmuch, int which) if (skeleton.free) { Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1); } else { - Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1); + Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1); } Sprite::setLastSpriteSpecial(3); // sets it to teeth } @@ -750,7 +805,6 @@ void Person::DoBlood(float howmuch, int which) bleedx /= realtexdetail; direction = abs(Random() % 2) * 2 - 1; } - } if (bleeding > 2) bleeding = 2; @@ -813,8 +867,8 @@ void Person::DoBloodBig(float howmuch, int which) bloodvel.z = 10; bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale; bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale; - Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1); - Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1); + Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1); + Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1); } } } @@ -844,7 +898,6 @@ void Person::DoBloodBig(float howmuch, int which) offsetx = 20; } - int startx = 512; int starty = 512; int endx = 0; @@ -854,10 +907,14 @@ void Person::DoBloodBig(float howmuch, int which) 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) startx = i; - if (j < starty) starty = j; - if (i > endx) endx = i; - if (j > endy) endy = j; + if (i < startx) + startx = i; + if (j < starty) + starty = j; + if (i > endx) + endx = i; + if (j > endy) + endy = j; } } } @@ -865,10 +922,14 @@ void Person::DoBloodBig(float howmuch, int which) 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) startx = i; - if (j < starty) starty = j; - if (i > endx) endx = i; - if (j > endy) endy = j; + if (i < startx) + startx = i; + if (j < starty) + starty = j; + if (i > endx) + endx = i; + if (j > endy) + endy = j; } } } @@ -878,12 +939,18 @@ void Person::DoBloodBig(float howmuch, int which) starty += offsety; endy += offsety; - if (startx < 0) startx = 0; - if (starty < 0) starty = 0; - if (endx > 512 - 1) endx = 512 - 1; - if (endy > 512 - 1) endy = 512 - 1; - if (endx < startx) endx = startx; - if (endy < starty) endy = starty; + if (startx < 0) + startx = 0; + if (starty < 0) + starty = 0; + if (endx > 512 - 1) + endx = 512 - 1; + if (endy > 512 - 1) + endy = 512 - 1; + if (endx < startx) + endx = startx; + if (endy < starty) + endy = starty; startx /= realtexdetail; starty /= realtexdetail; @@ -946,7 +1013,6 @@ void Person::DoBloodBig(float howmuch, int which) if (bleedy > skeleton.skinsize - 1) bleedy = skeleton.skinsize - 1; direction = abs(Random() % 2) * 2 - 1; - } bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25; deathbleeding += bleeding; @@ -1018,7 +1084,6 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) bary.y /= total; bary.z /= total; - gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0]; gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1]; gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2]; @@ -1043,8 +1108,8 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) bloodvel.z = 10; bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale; bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale; - Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1); - Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1); + Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1); + Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1); } } } @@ -1064,10 +1129,14 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) 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) startx = i; - if (j < starty) starty = j; - if (i > endx) endx = i; - if (j > endy) endy = j; + if (i < startx) + startx = i; + if (j < starty) + starty = j; + if (i > endx) + endx = i; + if (j > endy) + endy = j; } } } @@ -1075,10 +1144,14 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) 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) startx = i; - if (j < starty) starty = j; - if (i > endx) endx = i; - if (j > endy) endy = j; + if (i < startx) + startx = i; + if (j < starty) + starty = j; + if (i > endx) + endx = i; + if (j > endy) + endy = j; } } } @@ -1087,12 +1160,18 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) starty += offsety; endy += offsety; - if (startx < 0) startx = 0; - if (starty < 0) starty = 0; - if (endx > 512 - 1) endx = 512 - 1; - if (endy > 512 - 1) endy = 512 - 1; - if (endx < startx) endx = startx; - if (endy < starty) endy = starty; + if (startx < 0) + startx = 0; + if (starty < 0) + starty = 0; + if (endx > 512 - 1) + endx = 512 - 1; + if (endy > 512 - 1) + endy = 512 - 1; + if (endx < startx) + endx = startx; + if (endy < starty) + endy = starty; startx /= realtexdetail; starty /= realtexdetail; @@ -1178,25 +1257,15 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) return 1; } - - /* EFFECT * guessing this performs a reversal */ 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) { @@ -1426,8 +1495,6 @@ void Person::Reverse() for (unsigned i = 0; i < Person::players.size(); i++) { Person::players[i]->wentforweapon = 0; } - - } } if (hasvictim) @@ -1614,8 +1681,10 @@ void Person::DoHead() targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100; targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100; - while (targetheadyaw > 180)targetheadyaw -= 360; - while (targetheadyaw < -180)targetheadyaw += 360; + while (targetheadyaw > 180) + targetheadyaw -= 360; + while (targetheadyaw < -180) + targetheadyaw += 360; if (targetheadyaw > 160) targetheadpitch = targetheadpitch * -1; @@ -1724,20 +1793,29 @@ void Person::RagDoll(bool checkcollision) freefall = 1; skeleton.freefall = 1; - if (!isnormal(velocity.x)) velocity.x = 0; - if (!isnormal(velocity.y)) velocity.y = 0; - if (!isnormal(velocity.z)) velocity.z = 0; - if (!isnormal(yaw)) yaw = 0; - if (!isnormal(coords.x)) coords = 0; - if (!isnormal(tilt)) tilt = 0; - if (!isnormal(tilt2)) tilt2 = 0; + if (!isnormal(velocity.x)) + velocity.x = 0; + if (!isnormal(velocity.y)) + velocity.y = 0; + if (!isnormal(velocity.z)) + velocity.z = 0; + if (!isnormal(yaw)) + yaw = 0; + if (!isnormal(coords.x)) + coords = 0; + if (!isnormal(tilt)) + tilt = 0; + 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)) skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0); - if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = coords; + 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)) + 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; @@ -1845,8 +1923,6 @@ void Person::RagDoll(bool checkcollision) } } - - /* EFFECT */ void Person::FootLand(bodypart whichfoot, float opacity) @@ -1953,7 +2029,7 @@ void Person::DoAnimations() if (!crouchkeydown && velocity.y >= -15) landhard = 0; } - if ((animCurrent == jumpupanim || animTarget == jumpdownanim)/*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) { + if ((animCurrent == jumpupanim || animTarget == jumpdownanim) /*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) { XYZ targfacing; targfacing = 0; targfacing.z = 1; @@ -1985,7 +2061,6 @@ void Person::DoAnimations() crouchtogglekeydown = 1; } - if (Animation::animations[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) { if (detail) normalsupdatedelay = 0; @@ -2059,7 +2134,6 @@ void Person::DoAnimations() FootLand(rightfoot, 1); FootLand(leftfoot, 1); } - } if (terrain.getOpacity(coords.x, coords.z) >= .2) { if (targetFrame().label == 1) @@ -2124,16 +2198,24 @@ void Person::DoAnimations() if (Animation::animations[animTarget].attack != neutral) { unsigned r = abs(Random() % 4); if (creature == rabbittype) { - if (r == 0) whichsound = rabbitattacksound; - if (r == 1) whichsound = rabbitattack2sound; - if (r == 2) whichsound = rabbitattack3sound; - if (r == 3) whichsound = rabbitattack4sound; + if (r == 0) + whichsound = rabbitattacksound; + if (r == 1) + whichsound = rabbitattack2sound; + if (r == 2) + whichsound = rabbitattack3sound; + if (r == 3) + whichsound = rabbitattack4sound; } if (creature == wolftype) { - if (r == 0) whichsound = barksound; - if (r == 1) whichsound = bark2sound; - if (r == 2) whichsound = bark3sound; - if (r == 3) whichsound = barkgrowlsound; + if (r == 0) + whichsound = barksound; + if (r == 1) + whichsound = bark2sound; + if (r == 2) + whichsound = bark3sound; + if (r == 3) + whichsound = barkgrowlsound; } speechdelay = .3; } @@ -2144,8 +2226,6 @@ void Person::DoAnimations() } } - - if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) { FootLand(leftfoot, 1); FootLand(rightfoot, 1); @@ -2268,7 +2348,6 @@ void Person::DoAnimations() } } - if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) { XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0); Normalise(&rotatetarget); @@ -2288,7 +2367,7 @@ void Person::DoAnimations() 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 (distsq(&victim->coords, &/*Person::players[i]->*/ coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1) dojumpattack = 1; if (!hostile) dojumpattack = 0; @@ -2604,8 +2683,6 @@ void Person::DoAnimations() staggerdelay = .5; if (!victim->dead) staggerdelay = 1.2; - - } } @@ -2684,7 +2761,6 @@ void Person::DoAnimations() //victim->skeleton.joints[i].velocity=0; } emit_sound_at(fleshstabsound, coords, 128); - } if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) { weapons[weaponids[weaponactive]].blooddrip += 5; @@ -2834,7 +2910,6 @@ 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; @@ -2929,7 +3004,7 @@ void Person::DoAnimations() if (animTarget == knifeslashstartanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) { 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) { + 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) { victim->DoBloodBig(1.5 / victim->armorhigh, 225); @@ -3039,7 +3114,6 @@ void Person::DoAnimations() } } - XYZ aim; victim->Puff(righthand); victim->target = 0; @@ -3060,7 +3134,6 @@ void Person::DoAnimations() for (unsigned i = 0; i < Person::players.size(); i++) { Person::players[i]->wentforweapon = 0; } - } } } @@ -3237,7 +3310,6 @@ void Person::DoAnimations() victim->DoBloodBig(2 / victim->armorhigh, 170); } } - } } @@ -3295,7 +3367,6 @@ void Person::DoAnimations() } SolidHitBonus(id); - } } } @@ -3443,8 +3514,6 @@ void Person::DoAnimations() } } - - if (animTarget == swordslashreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) { escapednum = 0; victim->RagDoll(1); @@ -3566,7 +3635,6 @@ void Person::DoAnimations() Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9); Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1); Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1); - } victim->bloodloss += 10000; victim->velocity = 0; @@ -3738,7 +3806,6 @@ void Person::DoAnimations() } } - //Animation end if (frameTarget > int(Animation::animations[animCurrent].frames.size()) - 1) { frameTarget = 0; @@ -4239,12 +4306,18 @@ void Person::DoAnimations() skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 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) skeleton.muscles[i].newrotate3 -= 360; - 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) skeleton.muscles[i].newrotate2 -= 360; - 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) skeleton.muscles[i].newrotate1 -= 360; - if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) skeleton.muscles[i].newrotate1 += 360; + 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) + skeleton.muscles[i].newrotate3 += 360; + 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) + skeleton.muscles[i].newrotate2 += 360; + 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) + skeleton.muscles[i].newrotate1 += 360; } } } @@ -4431,12 +4504,12 @@ void Person::DoStuff() if (skeleton.free) { bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0); bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale; - Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9); + Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5) * scale + coords, bloodvel, 1, 1, 1, .05, .9); } else { bloodvel.z = 5 * neckspurtamount; bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale; bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale; - Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9); + Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, .9); } neckspurtparticledelay = .05; } @@ -4460,7 +4533,7 @@ void Person::DoStuff() Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1); } else { bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale; - Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1); + Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1); } } } @@ -4710,7 +4783,8 @@ void Person::DoStuff() righthandmorphness = 0; targetrighthandmorphness = 1; righthandmorphend = 1; - if (Random() % 2 == 0)twitchdelay3 = (float)(abs(Random() % 40)) / 5; + if (Random() % 2 == 0) + twitchdelay3 = (float)(abs(Random() % 40)) / 5; } if (righthandmorphstart == 1 && righthandmorphend == 1) { righthandmorphness = 0; @@ -4828,7 +4902,6 @@ void Person::DoStuff() targetheadmorphness = 1; } - if (howactive > typesleeping) { XYZ headpoint; headpoint = coords; @@ -4897,8 +4970,6 @@ void Person::DoStuff() } } - - if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) { slomo = 1; slomodelay = .2; @@ -5169,7 +5240,6 @@ void Person::DoStuff() targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1; - if (skeleton.forward.y < 0) { animTarget = getupfrombackanim; frameTarget = 0; @@ -5203,7 +5273,7 @@ void Person::DoStuff() targetyaw += 45; } if (backkeydown) { - if ( !leftkeydown && !rightkeydown) + if (!leftkeydown && !rightkeydown) targetyaw += 180; } targetyaw += 180; @@ -5271,14 +5341,13 @@ void Person::DoStuff() } if (skeleton.freefall == 0) freefall = 0; - } 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 (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 (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) { emit_sound_at(firestartsound, Object::objects[i]->position); @@ -5292,7 +5361,7 @@ void Person::DoStuff() } } 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 (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) { emit_sound_at(firestartsound, Object::objects[i]->position); @@ -5364,7 +5433,7 @@ void Person::DoStuff() tempcoord = DoRotation(tempcoord, -Object::objects[i]->pitch, 0, 0); tempcoord += Object::objects[i]->position; } - if (distsqflat(&tempcoord, &Object::objects[i]->position) < Object::objects[i]->scale*Object::objects[i]->scale * 8 && distsq(&tempcoord, &Object::objects[i]->position) < Object::objects[i]->scale*Object::objects[i]->scale * 300 && tempcoord.y > Object::objects[i]->position.y + 3 * Object::objects[i]->scale) { + if (distsqflat(&tempcoord, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 8 && distsq(&tempcoord, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 300 && tempcoord.y > Object::objects[i]->position.y + 3 * Object::objects[i]->scale) { if (Object::objects[i]->messedwith <= 0) { XYZ tempvel; XYZ pos; @@ -5547,45 +5616,45 @@ void Person::DoStuff() } if (animTarget == spinkickanim || - animTarget == staffspinhitreversalanim || - animTarget == staffspinhitreversedanim || - animTarget == staffhitreversalanim || - animTarget == staffhitreversedanim || - animTarget == hurtidleanim || - animTarget == winduppunchanim || - animTarget == swordslashreversalanim || - animTarget == swordslashreversedanim || - animTarget == knifeslashreversalanim || - animTarget == knifeslashreversedanim || - animTarget == knifethrowanim || - animTarget == knifefollowanim || - animTarget == knifefollowedanim || - animTarget == killanim || - animTarget == dropkickanim || - animTarget == upunchanim || - animTarget == knifeslashstartanim || - animTarget == swordslashanim || - animTarget == staffhitanim || - animTarget == staffspinhitanim || - animTarget == staffgroundsmashanim || - animTarget == spinkickreversalanim || - animTarget == sweepreversalanim || - animTarget == lowkickanim || - animTarget == sweepreversedanim || - animTarget == rabbitkickreversalanim || - animTarget == rabbitkickreversedanim || - animTarget == jumpreversalanim || - animTarget == jumpreversedanim) { + animTarget == staffspinhitreversalanim || + animTarget == staffspinhitreversedanim || + animTarget == staffhitreversalanim || + animTarget == staffhitreversedanim || + animTarget == hurtidleanim || + animTarget == winduppunchanim || + animTarget == swordslashreversalanim || + animTarget == swordslashreversedanim || + animTarget == knifeslashreversalanim || + animTarget == knifeslashreversedanim || + animTarget == knifethrowanim || + animTarget == knifefollowanim || + animTarget == knifefollowedanim || + animTarget == killanim || + animTarget == dropkickanim || + animTarget == upunchanim || + animTarget == knifeslashstartanim || + animTarget == swordslashanim || + animTarget == staffhitanim || + animTarget == staffspinhitanim || + animTarget == staffgroundsmashanim || + animTarget == spinkickreversalanim || + animTarget == sweepreversalanim || + animTarget == lowkickanim || + animTarget == sweepreversedanim || + animTarget == rabbitkickreversalanim || + animTarget == rabbitkickreversedanim || + animTarget == jumpreversalanim || + animTarget == jumpreversedanim) { //close hands and yell if (righthandmorphend != 1 && - righthandmorphness == targetrighthandmorphness) { + righthandmorphness == targetrighthandmorphness) { righthandmorphness = 0; righthandmorphend = 1; targetrighthandmorphness = 1; } if (lefthandmorphend != 1 && - lefthandmorphness == targetlefthandmorphness) { + lefthandmorphness == targetlefthandmorphness) { lefthandmorphness = 0; lefthandmorphend = 1; targetlefthandmorphness = 1; @@ -5646,7 +5715,7 @@ void Person::DoStuff() Normalise(&facing); if (isRun() || - animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) { + animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) { if (onterrain) targettilt2 = -facing.y * 20; else @@ -5791,7 +5860,6 @@ void Person::DoStuff() velocity = flatfacing * velspeed; } - if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) { velocity -= facing * multiplier * speed * 700 * scale; velspeed = findLength(&velocity); @@ -5862,7 +5930,6 @@ void Person::DoStuff() velspeed = findLength(&velocity); } - if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) { velocity.y += gravity * multiplier; } @@ -5888,7 +5955,8 @@ void Person::DoStuff() } if (animTarget == jumpdownanim || isFlip()) { - if (isFlip())jumppower = -4; + if (isFlip()) + jumppower = -4; animTarget = getLanding(); emit_sound_at(landsound, coords, 128.); @@ -5905,7 +5973,6 @@ void Person::DoStuff() onterrain = 1; } - if (isIdle() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || isStop() || animTarget == removeknifeanim || animTarget == crouchremoveknifeanim || isLanding() || isCrouch() || Animation::animations[animTarget].attack || (animTarget == rollanim && targetFrame().label == 6)) { velspeed = findLength(&velocity); velocity.y = 0; @@ -5986,11 +6053,10 @@ void Person::DoStuff() } } - /* EFFECT * inverse kinematics helper function */ -void IKHelper(Person *p, float interp) +void IKHelper(Person* p, float interp) { XYZ point, change, change2; float heightleft, heightright; @@ -6093,10 +6159,8 @@ int Person::DrawSkeleton() if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) { if (!isSleeping() && !isSitting()) { // TODO: give these meaningful names - const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard() - || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim); - const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() - || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim); + const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim); + const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim); if (onterrain && (cond1 && cond2) && !skeleton.free) { IKHelper(this, 1); @@ -6183,7 +6247,6 @@ int Person::DrawSkeleton() if (!skeleton.free) glRotatef(tilt, 0, 0, 1); - glTranslatef(mid.x, mid.y, mid.z); skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1; @@ -6197,8 +6260,8 @@ int Person::DrawSkeleton() if (playerdetail || skeleton.free == 3) { for (unsigned j = 0; j < skeleton.muscles[i].vertices.size(); j++) { - XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]]; - XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]]; + XYZ& v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]]; + XYZ& v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]]; glMatrixMode(GL_MODELVIEW); glPushMatrix(); if (p1 == abdomen || p2 == abdomen) @@ -6226,7 +6289,7 @@ int Person::DrawSkeleton() } if (!playerdetail || skeleton.free == 3) { for (unsigned j = 0; j < skeleton.muscles[i].verticeslow.size(); j++) { - XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]]; + XYZ& v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]]; glMatrixMode(GL_MODELVIEW); glPushMatrix(); if (p1 == abdomen || p2 == abdomen) @@ -6276,7 +6339,7 @@ int Person::DrawSkeleton() glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0); for (unsigned j = 0; j < skeleton.muscles[i].verticesclothes.size(); j++) { - XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]]; + XYZ& v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]]; glMatrixMode(GL_MODELVIEW); glPushMatrix(); if (p1 == abdomen || p2 == abdomen) @@ -6350,7 +6413,7 @@ int Person::DrawSkeleton() glBegin(GL_POINTS); if (playerdetail) { for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) { - XYZ &v0 = skeleton.drawmodel.vertex[i]; + XYZ& v0 = skeleton.drawmodel.vertex[i]; glVertex3f(v0.x, v0.y, v0.z); } } @@ -6359,9 +6422,9 @@ int Person::DrawSkeleton() if (playerdetail) { for (unsigned int i = 0; i < skeleton.drawmodel.Triangles.size(); i++) { - const XYZ &v0 = skeleton.drawmodel.getTriangleVertex(i, 0); - const XYZ &v1 = skeleton.drawmodel.getTriangleVertex(i, 1); - const XYZ &v2 = skeleton.drawmodel.getTriangleVertex(i, 2); + const XYZ& v0 = skeleton.drawmodel.getTriangleVertex(i, 0); + const XYZ& v1 = skeleton.drawmodel.getTriangleVertex(i, 1); + const XYZ& v2 = skeleton.drawmodel.getTriangleVertex(i, 2); glVertex3f(v0.x, v0.y, v0.z); glVertex3f(v1.x, v1.y, v1.z); glVertex3f(v1.x, v1.y, v1.z); @@ -6461,7 +6524,6 @@ int Person::DrawSkeleton() } } - if (Tutorial::active && id != 0) { glPopMatrix(); glMatrixMode(GL_MODELVIEW); @@ -6714,10 +6776,9 @@ int Person::DrawSkeleton() return 0; } - /* FUNCTION? */ -int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model) +int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, Model* model) { static float distance; static float olddistance; @@ -6743,7 +6804,7 @@ 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) intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]], @@ -6807,18 +6868,13 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, intersecting = 0; start = *p1; start.y -= radius / 4; - XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]]; - XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]]; - XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]]; - 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))); + XYZ& v0 = model->vertex[model->Triangles[j].vertex[0]]; + XYZ& v1 = model->vertex[model->Triangles[j].vertex[1]]; + XYZ& v2 = model->vertex[model->Triangles[j].vertex[2]]; + 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) intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2); @@ -6873,12 +6929,14 @@ int findPathDist(int start, int end) connected = 0; if (Game::numpathpointconnect[j]) for (int k = 0; k < Game::numpathpointconnect[j]; k++) { - if (Game::pathpointconnect[j][k] == last)connected = 1; + if (Game::pathpointconnect[j][k] == last) + connected = 1; } if (!connected) if (Game::numpathpointconnect[last]) for (int k = 0; k < Game::numpathpointconnect[last]; k++) { - if (Game::pathpointconnect[last][k] == j)connected = 1; + if (Game::pathpointconnect[last][k] == j) + connected = 1; } if (connected) if (closest == -1 || Random() % 2 == 0) { @@ -6938,13 +6996,19 @@ bool Person::addClothes(const int& clothesId) float tintg = clothestintg[clothesId]; float tintb = clothestintb[clothesId]; - if (tintr > 1) tintr = 1; - if (tintg > 1) tintg = 1; - if (tintb > 1) tintb = 1; + if (tintr > 1) + tintr = 1; + if (tintg > 1) + tintg = 1; + if (tintb > 1) + tintb = 1; - if (tintr < 0) tintr = 0; - if (tintg < 0) tintg = 0; - if (tintb < 0) tintb = 0; + if (tintr < 0) + tintr = 0; + if (tintg < 0) + tintg = 0; + if (tintb < 0) + tintb = 0; int bytesPerPixel = texture.bpp / 8; @@ -6982,8 +7046,8 @@ void Person::doAI() 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]->coords.y > coords.y + 2 && + !Person::players[0]->onterrain) pause = 1; //pathfinding @@ -7008,7 +7072,7 @@ void Person::doAI() DistancePointLine(&finalfinaltarget, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint); 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) { + findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) { closestdistance = sq(tempdist); closest = j; finaltarget = colpoint; @@ -7016,7 +7080,6 @@ void Person::doAI() } } finalpathfindpoint = closest; - } if (targetpathfindpoint == -1) { float closestdistance; @@ -7037,10 +7100,10 @@ void Person::doAI() 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 ); + DistancePointLine(&coords, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint); 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) { + findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) { closestdistance = sq(tempdist); closest = j; } @@ -7050,9 +7113,9 @@ void Person::doAI() } else { for (int j = 0; j < Game::numpathpoints; j++) if (j != lastpathfindpoint && - j != lastpathfindpoint2 && - j != lastpathfindpoint3 && - j != lastpathfindpoint4) { + j != lastpathfindpoint2 && + j != lastpathfindpoint3 && + j != lastpathfindpoint4) { bool connected = 0; if (Game::numpathpointconnect[j]) for (int k = 0; k < Game::numpathpointconnect[j]; k++) @@ -7093,10 +7156,10 @@ void Person::doAI() lastpathfindpoint4 = lastpathfindpoint3; targetpathfindpoint = -1; } - if ( distsqflat(&coords, &finalfinaltarget) < - distsqflat(&coords, &finaltarget) || - distsqflat(&coords, &finaltarget) < .6 * sq(scale * 5) || - lastpathfindpoint == finalpathfindpoint) { + if (distsqflat(&coords, &finalfinaltarget) < + distsqflat(&coords, &finaltarget) || + distsqflat(&coords, &finaltarget) < .6 * sq(scale * 5) || + lastpathfindpoint == finalpathfindpoint) { aitype = passivetype; } @@ -7117,18 +7180,18 @@ void Person::doAI() jumpkeydown = 1; if ((!Tutorial::active || cananger) && - hostile && - !Person::players[0]->dead && - distsq(&coords, &Person::players[0]->coords) < 400 && - occluded < 25) { + hostile && + !Person::players[0]->dead && + 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 && - (Person::players[0]->coords.y < coords.y + 5 || Person::players[0]->onterrain)) + Animation::animations[Person::players[0]->animTarget].height != lowheight && + !Game::editorenabled && + (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) + Animation::animations[Person::players[0]->animTarget].height == highheight && + !Game::editorenabled) aitype = attacktypecutoff; if (losupdatedelay < 0 && !Game::editorenabled && occluded < 2) { @@ -7139,13 +7202,9 @@ void Person::doAI() 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)) { + 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)) { aitype = searchtype; lastchecktime = 12; lastseen = Person::players[j]->coords; @@ -7183,7 +7242,6 @@ void Person::doAI() waypoint++; if (waypoint > numwaypoints - 1) waypoint = 0; - } } @@ -7220,15 +7278,13 @@ void Person::doAI() if ((collided > .8 && jumppower >= 5)) jumpkeydown = 1; - //hearing sounds if (!Game::editorenabled) { 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; } @@ -7240,15 +7296,15 @@ void Person::doAI() } if (howactive < typesleeping && - ((!Tutorial::active || cananger) && hostile) && - !Person::players[0]->dead && - distsq(&coords, &Person::players[0]->coords) < 400 && - occluded < 25) { + ((!Tutorial::active || cananger) && hostile) && + !Person::players[0]->dead && + 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 @@ -7283,13 +7339,15 @@ void Person::doAI() 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 + coords, - DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0)* - Person::players[j]->scale + Person::players[j]->coords) && - !Person::players[j]->isWallJump()) || - (Person::players[j]->animTarget == hanganim && - normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) { + 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]->isWallJump()) || + (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) lastseentime -= .4; @@ -7408,10 +7466,10 @@ void Person::doAI() } if (!Person::players[0]->dead && - losupdatedelay < 0 && - !Game::editorenabled && - occluded < 2 && - ((!Tutorial::active || cananger) && hostile)) { + losupdatedelay < 0 && + !Game::editorenabled && + occluded < 2 && + ((!Tutorial::active || cananger) && hostile)) { losupdatedelay = .2; if (distsq(&coords, &Person::players[0]->coords) < 4 && Animation::animations[animTarget].height != lowheight) { aitype = attacktypecutoff; @@ -7422,12 +7480,13 @@ void Person::doAI() 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 + coords, - DoRotation(Person::players[0]->jointPos(head), 0, Person::players[0]->yaw, 0)* - Person::players[0]->scale + Person::players[0]->coords) == -1) || - (Person::players[0]->animTarget == hanganim && normaldotproduct( - Person::players[0]->facing, coords - Person::players[0]->coords) < 0)) { + DoRotation(jointPos(head), 0, yaw, 0) * + scale + + coords, + DoRotation(Person::players[0]->jointPos(head), 0, Person::players[0]->yaw, 0) * + Person::players[0]->scale + + Person::players[0]->coords) == -1) || + (Person::players[0]->animTarget == hanganim && normaldotproduct(Person::players[0]->facing, coords - Person::players[0]->coords) < 0)) { /* //TODO: changed j to 0 on a whim, make sure this is correct (Person::players[j]->animTarget==hanganim&&normaldotproduct( Person::players[j]->facing,coords-Person::players[j]->coords)<0) @@ -7469,9 +7528,9 @@ void Person::doAI() float closestdist = -1; for (unsigned k = 0; k < Person::players.size(); k++) { if ((k != id) && (k != 0) && !Person::players[k]->dead && - (Person::players[k]->howactive < typedead1) && - !Person::players[k]->skeleton.free && - (Person::players[k]->aitype == passivetype)) { + (Person::players[k]->howactive < typedead1) && + !Person::players[k]->skeleton.free && + (Person::players[k]->aitype == passivetype)) { float distance = distsq(&coords, &Person::players[k]->coords); if (closestdist == -1 || distance < closestdist) { closestdist = distance; @@ -7489,7 +7548,6 @@ void Person::doAI() lastseentime = 12; } - lastchecktime = 12; XYZ facing = coords; @@ -7501,9 +7559,9 @@ void Person::doAI() //no available ally, run back to player if (ally <= 0 || - Person::players[ally]->skeleton.free || - Person::players[ally]->aitype != passivetype || - lastseentime <= 0) { + Person::players[ally]->skeleton.free || + Person::players[ally]->aitype != passivetype || + lastseentime <= 0) { aitype = searchtype; lastseentime = 12; } @@ -7593,7 +7651,7 @@ void Person::doAI() if (!Person::players[0]->dead) if (ally >= 0) { if (weapons[ally].owner != -1 || - distsq(&coords, &weapons[ally].position) > 16) { + distsq(&coords, &weapons[ally].position) > 16) { aitype = attacktypecutoff; lastseentime = 1; } @@ -7603,7 +7661,6 @@ void Person::doAI() aiupdatedelay = .05; forwardkeydown = 1; - if (avoidcollided > .8 && !jumpkeydown && collided < .8) { if (!avoidsomething) targetyaw += 90 * (whichdirection * 2 - 1); @@ -7629,7 +7686,7 @@ void Person::doAI() throwkeydown = 1; crouchkeydown = 0; if (animTarget != crouchremoveknifeanim && - animTarget != removeknifeanim) + animTarget != removeknifeanim) throwtogglekeydown = 0; drawkeydown = 0; } @@ -7644,11 +7701,11 @@ void Person::doAI() //dodge or reverse rabbit kicks, knife throws, flips if (damage < damagetolerance * 2 / 3) if ((Person::players[0]->animTarget == rabbitkickanim || - Person::players[0]->animTarget == knifethrowanim || - (Person::players[0]->isFlip() && - normaldotproduct(Person::players[0]->facing, Person::players[0]->coords - coords) < 0)) && - !Person::players[0]->skeleton.free && - (aiupdatedelay < .1)) { + Person::players[0]->animTarget == knifethrowanim || + (Person::players[0]->isFlip() && + normaldotproduct(Person::players[0]->facing, Person::players[0]->coords - coords) < 0)) && + !Person::players[0]->skeleton.free && + (aiupdatedelay < .1)) { attackkeydown = 0; if (isIdle()) crouchkeydown = 1; @@ -7673,9 +7730,9 @@ void Person::doAI() } //get confused by flips if (Person::players[0]->isFlip() && - !Person::players[0]->skeleton.free && - Person::players[0]->animTarget != walljumprightkickanim && - Person::players[0]->animTarget != walljumpleftkickanim) { + !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) stunned = 1; @@ -7700,12 +7757,12 @@ void Person::doAI() if (damage < damagetolerance / 2) if (Animation::animations[animTarget].height != highheight) if (damage < damagetolerance * .5 && - ((Person::players[0]->animTarget == walljumprightkickanim || - Person::players[0]->animTarget == walljumpleftkickanim) && - ((aiupdatedelay < .15 && - difficulty == 2) || - (aiupdatedelay < .08 && - difficulty != 2)))) { + ((Person::players[0]->animTarget == walljumprightkickanim || + Person::players[0]->animTarget == walljumpleftkickanim) && + ((aiupdatedelay < .15 && + difficulty == 2) || + (aiupdatedelay < .08 && + difficulty != 2)))) { crouchkeydown = 1; } //walked off a ledge (?) @@ -7736,8 +7793,8 @@ void Person::doAI() } //lose sight of player in the air (?) if (Person::players[0]->coords.y > coords.y + 5 && - Animation::animations[Person::players[0]->animTarget].height != highheight && - !Person::players[0]->onterrain) { + Animation::animations[Person::players[0]->animTarget].height != highheight && + !Person::players[0]->onterrain) { aitype = pathfindtype; finalfinaltarget = waypoints[waypoint]; finalpathfindpoint = -1; @@ -7749,11 +7806,11 @@ void Person::doAI() } //it's time to think (?) if (aiupdatedelay < 0 && - !Animation::animations[animTarget].attack && - animTarget != staggerbackhighanim && - animTarget != staggerbackhardanim && - animTarget != backhandspringanim && - animTarget != dodgebackanim) { + !Animation::animations[animTarget].attack && + animTarget != staggerbackhighanim && + animTarget != staggerbackhardanim && + animTarget != backhandspringanim && + animTarget != dodgebackanim) { //draw weapon if (weaponactive == -1 && num_weapons > 0) drawkeydown = Random() % 2; @@ -7764,7 +7821,7 @@ void Person::doAI() 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); @@ -7815,37 +7872,37 @@ void Person::doAI() //TODO: wat if (aitype != playercontrolled && - (isIdle() || - isCrouch() || - isRun())) { + (isIdle() || + isCrouch() || + isRun())) { int target = -2; for (unsigned j = 0; j < Person::players.size(); j++) if (j != id && !Person::players[j]->skeleton.free && - Person::players[j]->hasvictim && - (Tutorial::active && reversaltrain || - Random() % 2 == 0 && difficulty == 2 || - Random() % 4 == 0 && difficulty == 1 || - Random() % 8 == 0 && difficulty == 0 || - Person::players[j]->lastattack2 == Person::players[j]->animTarget && + Person::players[j]->hasvictim && + (Tutorial::active && reversaltrain || + Random() % 2 == 0 && difficulty == 2 || + Random() % 4 == 0 && difficulty == 1 || + Random() % 8 == 0 && difficulty == 0 || + Person::players[j]->lastattack2 == Person::players[j]->animTarget && Person::players[j]->lastattack3 == Person::players[j]->animTarget && (Random() % 2 == 0 || difficulty == 2) || - (isIdle() || isRun()) && + (isIdle() || isRun()) && Person::players[j]->weaponactive != -1 || - Person::players[j]->animTarget == swordslashanim && + Person::players[j]->animTarget == swordslashanim && weaponactive != -1 || - Person::players[j]->animTarget == staffhitanim || - Person::players[j]->animTarget == staffspinhitanim)) + Person::players[j]->animTarget == staffhitanim || + 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 || - Person::players[j]->animTarget == spinkickanim || - Person::players[j]->animTarget == staffhitanim || - Person::players[j]->animTarget == staffspinhitanim || - Person::players[j]->animTarget == winduppunchanim || - Person::players[j]->animTarget == upunchanim || - Person::players[j]->animTarget == wolfslapanim || - Person::players[j]->animTarget == knifeslashstartanim || - Person::players[j]->animTarget == swordslashanim && + Person::players[j]->victim == Person::players[id] && + (Person::players[j]->animTarget == sweepanim || + Person::players[j]->animTarget == spinkickanim || + Person::players[j]->animTarget == staffhitanim || + Person::players[j]->animTarget == staffspinhitanim || + Person::players[j]->animTarget == winduppunchanim || + Person::players[j]->animTarget == upunchanim || + Person::players[j]->animTarget == wolfslapanim || + Person::players[j]->animTarget == knifeslashstartanim || + Person::players[j]->animTarget == swordslashanim && (distsq(&Person::players[j]->coords, &coords) < 2 || weaponactive != -1))) { if (target >= 0) { @@ -7861,7 +7918,7 @@ void Person::doAI() if (collided < 1) jumpkeydown = 0; if (collided > .8 && jumppower >= 5 || - distsq(&coords, &Person::players[0]->coords) > 400 && + distsq(&coords, &Person::players[0]->coords) > 400 && onterrain && creature == rabbittype) jumpkeydown = 1; @@ -7869,7 +7926,7 @@ void Person::doAI() 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) attackkeydown = 0; @@ -7878,7 +7935,6 @@ void Person::doAI() if (!canattack) attackkeydown = 0; - XYZ facing = coords; XYZ flatfacing = Person::players[0]->coords; facing.y += jointPos(head).y * scale; @@ -7888,8 +7944,8 @@ void Person::doAI() if (!pause) lastseentime -= .2; if (lastseentime <= 0 && - (creature != wolftype || - weaponstuck == -1)) { + (creature != wolftype || + weaponstuck == -1)) { aitype = searchtype; lastchecktime = 12; lastseen = Person::players[0]->coords; @@ -7900,8 +7956,8 @@ void Person::doAI() } } if (Animation::animations[Person::players[0]->animTarget].height == highheight && - (aitype == attacktypecutoff || - aitype == searchtype)) + (aitype == attacktypecutoff || + 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; @@ -7910,8 +7966,8 @@ void Person::doAI() } //stunned if (aitype == passivetype && !(numwaypoints > 1) || - stunned > 0 || - pause && damage > superpermanentdamage) { + stunned > 0 || + pause && damage > superpermanentdamage) { if (pause) lastseentime = 1; targetyaw = yaw; @@ -7925,7 +7981,6 @@ void Person::doAI() throwkeydown = 0; } - XYZ facing; facing = 0; facing.z = -1; diff --git a/Source/Objects/Weapons.cpp b/Source/Objects/Weapons.cpp index f1ba770..42ee250 100644 --- a/Source/Objects/Weapons.cpp +++ b/Source/Objects/Weapons.cpp @@ -23,8 +23,8 @@ along with Lugaru. If not, see . #include "Objects/Weapons.hpp" #include "Animation/Animation.hpp" -#include "Audio/openal_wrapper.hpp" #include "Audio/Sounds.hpp" +#include "Audio/openal_wrapper.hpp" #include "Game.hpp" #include "Level/Awards.hpp" #include "Tutorial.hpp" @@ -64,7 +64,8 @@ Texture Weapon::bloodswordtextureptr; Model Weapon::staffmodel; Texture Weapon::stafftextureptr; -Weapon::Weapon(int t, int o) : owner(o) +Weapon::Weapon(int t, int o) + : owner(o) { setType(t); bloody = 0; @@ -253,11 +254,11 @@ void Weapon::doStuff(int i) footvel = 0; footpoint = DoRotation((Person::players[j]->jointPos(abdomen) + Person::players[j]->jointPos(neck)) / 2, 0, Person::players[j]->yaw, 0) * Person::players[j]->scale + Person::players[j]->coords; if (owner == -1 && distsqflat(&position, &Person::players[j]->coords) < 1.5 && - distsq(&position, &Person::players[j]->coords) < 4 && Person::players[j]->weaponstuck == -1 && - !Person::players[j]->skeleton.free && (int(j) != oldowner)) { + distsq(&position, &Person::players[j]->coords) < 4 && Person::players[j]->weaponstuck == -1 && + !Person::players[j]->skeleton.free && (int(j) != oldowner)) { if ((Person::players[j]->aitype != attacktypecutoff || abs(Random() % 6) == 0 || (Person::players[j]->animTarget != backhandspringanim && Person::players[j]->animTarget != rollanim && Person::players[j]->animTarget != flipanim && Random() % 2 == 0)) && !missed) { - if ( (Person::players[j]->creature == wolftype && Random() % 3 != 0 && Person::players[j]->weaponactive == -1 && (Person::players[j]->isIdle() || Person::players[j]->isRun() || Person::players[j]->animTarget == walkanim)) || - (Person::players[j]->creature == rabbittype && Random() % 2 == 0 && Person::players[j]->aitype == attacktypecutoff && Person::players[j]->weaponactive == -1)) { + if ((Person::players[j]->creature == wolftype && Random() % 3 != 0 && Person::players[j]->weaponactive == -1 && (Person::players[j]->isIdle() || Person::players[j]->isRun() || Person::players[j]->animTarget == walkanim)) || + (Person::players[j]->creature == rabbittype && Random() % 2 == 0 && Person::players[j]->aitype == attacktypecutoff && Person::players[j]->weaponactive == -1)) { emit_sound_at(knifedrawsound, Person::players[j]->coords, 128.); Person::players[j]->animTarget = removeknifeanim; @@ -406,7 +407,6 @@ void Weapon::doStuff(int i) if (temppoint1.x > temppoint2.x) rotation1 = 360 - rotation1; } - } //Sword physics @@ -437,7 +437,6 @@ void Weapon::doStuff(int i) position = newpoint1; tippoint = newpoint2; - //Object collisions whichpatchx = (position.x) / (terrain.size / subdivision * terrain.scale); whichpatchz = (position.z) / (terrain.size / subdivision * terrain.scale); @@ -623,26 +622,26 @@ void Weapon::doStuff(int i) point[0] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 0), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position; point[1] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 1), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position; point[2] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 2), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position; - if (DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance, &colpoint )) { + if (DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance, &colpoint)) { if (distance < closestdistance || closestdistance == -1) { closestpoint = colpoint; closestdistance = distance; } } - if (DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance, &colpoint )) { + if (DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance, &colpoint)) { if (distance < closestdistance || closestdistance == -1) { closestpoint = colpoint; closestdistance = distance; } } - if (DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance, &colpoint )) { + if (DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance, &colpoint)) { if (distance < closestdistance || closestdistance == -1) { closestpoint = colpoint; closestdistance = distance; } } if (closestdistance != -1 && isnormal(closestdistance)) { - if (DistancePointLine(&closestpoint, &position, &tippoint, &distance, &colpoint )) { + if (DistancePointLine(&closestpoint, &position, &tippoint, &distance, &colpoint)) { closestswordpoint = colpoint; velocity += (closestpoint - closestswordpoint); tipvelocity += (closestpoint - closestswordpoint); @@ -691,8 +690,7 @@ void Weapon::doStuff(int i) whichsound = footstepsound + abs(Random() % 2); } emit_sound_at(whichsound, position, - findLengthfast(&bounceness) - * (terrain.getOpacity(position.x, position.z) > .2 ? 128. : 32.)); + findLengthfast(&bounceness) * (terrain.getOpacity(position.x, position.z) > .2 ? 128. : 32.)); if (terrain.getOpacity(position.x, position.z) < .2) { XYZ terrainlight; @@ -745,8 +743,7 @@ void Weapon::doStuff(int i) whichsound = footstepsound + abs(Random() % 2); } emit_sound_at(whichsound, tippoint, - findLengthfast(&bounceness) - * (terrain.getOpacity(tippoint.x, tippoint.z) > .2 ? 128. : 32.)); + findLengthfast(&bounceness) * (terrain.getOpacity(tippoint.x, tippoint.z) > .2 ? 128. : 32.)); if (terrain.getOpacity(tippoint.x, tippoint.z) < .2) { XYZ terrainlight; @@ -802,10 +799,9 @@ void Weapon::doStuff(int i) whichsound = footstepsound + abs(Random() % 2); } emit_sound_at(whichsound, mid, - findLengthfast(&bounceness) - * (terrain.getOpacity(position.x, position.z) > .2 - ? 128. - : 32.)); + findLengthfast(&bounceness) * (terrain.getOpacity(position.x, position.z) > .2 + ? 128. + : 32.)); } position += (mid - oldmid) * 20; } @@ -846,10 +842,9 @@ void Weapon::doStuff(int i) whichsound = footstepsound + abs(Random() % 2); } emit_sound_at(whichsound, mid, - findLengthfast(&bounceness) - * (terrain.getOpacity(position.x, position.z) > .2 - ? 128. - : 32.)); + findLengthfast(&bounceness) * (terrain.getOpacity(position.x, position.z) > .2 + ? 128. + : 32.)); } tippoint += (mid - oldmid) * 20; } @@ -964,7 +959,7 @@ void Weapon::draw() static GLfloat M[16]; if ((frustum.SphereInFrustum(position.x, position.y, position.z, 1) && - distsq(&viewer, &position) < viewdistance * viewdistance)) { + distsq(&viewer, &position) < viewdistance * viewdistance)) { bool draw = false; if (owner == -1) { draw = true; @@ -992,8 +987,7 @@ void Weapon::draw() Person::players[owner]->animTarget == swordgroundstabanim || Person::players[owner]->animTarget == knifethrowanim) && Person::players[owner]->animTarget == lastdrawnanim && - !Person::players[owner]->skeleton.free - ) { + !Person::players[owner]->skeleton.free) { drawhowmany = 10; } else { drawhowmany = 1; @@ -1042,29 +1036,29 @@ void Weapon::draw() glEnable(GL_LIGHTING); switch (type) { - case knife: - if (!bloody || !bloodtoggle) - throwingknifemodel.drawdifftex(knifetextureptr); - if (bloodtoggle) { - if (bloody == 1) - throwingknifemodel.drawdifftex(lightbloodknifetextureptr); - if (bloody == 2) - throwingknifemodel.drawdifftex(bloodknifetextureptr); - } - break; - case sword: - if (!bloody || !bloodtoggle) - swordmodel.drawdifftex(swordtextureptr); - if (bloodtoggle) { - if (bloody == 1) - swordmodel.drawdifftex(lightbloodswordtextureptr); - if (bloody == 2) - swordmodel.drawdifftex(bloodswordtextureptr); - } - break; - case staff: - staffmodel.drawdifftex(stafftextureptr); - break; + case knife: + if (!bloody || !bloodtoggle) + throwingknifemodel.drawdifftex(knifetextureptr); + if (bloodtoggle) { + if (bloody == 1) + throwingknifemodel.drawdifftex(lightbloodknifetextureptr); + if (bloody == 2) + throwingknifemodel.drawdifftex(bloodknifetextureptr); + } + break; + case sword: + if (!bloody || !bloodtoggle) + swordmodel.drawdifftex(swordtextureptr); + if (bloodtoggle) { + if (bloody == 1) + swordmodel.drawdifftex(lightbloodswordtextureptr); + if (bloody == 2) + swordmodel.drawdifftex(bloodswordtextureptr); + } + break; + case staff: + staffmodel.drawdifftex(stafftextureptr); + break; } glPopMatrix(); diff --git a/Source/Tutorial.cpp b/Source/Tutorial.cpp index 3a134ff..3d5fed1 100644 --- a/Source/Tutorial.cpp +++ b/Source/Tutorial.cpp @@ -19,9 +19,9 @@ along with Lugaru. If not, see . */ #include "Tutorial.hpp" -#include "Game.hpp" #include "Audio/Sounds.hpp" #include "Audio/openal_wrapper.hpp" +#include "Game.hpp" #include "Level/Awards.hpp" #include "Objects/Person.hpp" #include "Utils/Input.hpp" @@ -103,8 +103,7 @@ void Tutorial::Do(float multiplier) Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); } } - } - break; + } break; case 15: case 16: case 17: @@ -204,8 +203,7 @@ void Tutorial::Do(float multiplier) w.physics = 1; weapons.push_back(w); - } - break; + } break; case 40: case 41: case 43: @@ -282,8 +280,7 @@ void Tutorial::Do(float multiplier) Person::players[1]->num_weapons = 1; Person::players[1]->weaponids[0] = 0; - } - break; + } break; case 48: canattack = 0; cananger = 0; @@ -350,8 +347,7 @@ void Tutorial::Do(float multiplier) Person::players[1]->weaponactive = -1; weapons.clear(); - } - break; + } break; case 51: maxtime = 80000; break; @@ -527,7 +523,7 @@ void Tutorial::DrawTextInfo() switch (stage) { case 0: default: - break; + break; case 1: string = "Welcome to the Lugaru training level!"; break; @@ -539,10 +535,10 @@ void Tutorial::DrawTextInfo() break; case 4: string = std::string("Try using the ") + - Input::keyToChar(Game::forwardkey) + ", " + - Input::keyToChar(Game::leftkey) + ", " + - Input::keyToChar(Game::backkey) + " and " + - Input::keyToChar(Game::rightkey) + " keys to move around."; + Input::keyToChar(Game::forwardkey) + ", " + + Input::keyToChar(Game::leftkey) + ", " + + Input::keyToChar(Game::backkey) + " and " + + Input::keyToChar(Game::rightkey) + " keys to move around."; string2 = "All movement is relative to the camera."; break; case 5: @@ -753,17 +749,17 @@ void Tutorial::DrawTextInfo() opacity = 0; } - Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); - Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); - Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string.size() * screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string2.size() * screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string3.size() * screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); string = "Press 'tab' to skip to the next item."; string2 = "Press escape at any time to"; string3 = "pause or exit the tutorial."; - Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10, string, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); - Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); - Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); + Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string.size() * screenwidth / 1024 * .8, 0 + screenheight * 1 / 10, string, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); + Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string2.size() * screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); + Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string3.size() * screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); } void Tutorial::DoStuff(float multiplier) @@ -786,7 +782,7 @@ void Tutorial::DoStuff(float multiplier) oldtemp2 = temp2; if (stage >= 51) { if (distsq(&temp, &Person::players[0]->coords) >= distsq(&temp, &temp2) - 1 || distsq(&temp3, &Person::players[0]->coords) < 4) { - OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu... + OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu... OPENAL_SetFrequency(OPENAL_ALL); emit_stream_np(stream_menutheme); diff --git a/Source/User/Account.cpp b/Source/User/Account.cpp index ed0a654..52f863e 100644 --- a/Source/User/Account.cpp +++ b/Source/User/Account.cpp @@ -34,7 +34,9 @@ extern bool devtools; vector Account::accounts; int Account::i_active = -1; -Account::Account(const string& name) : name(name), campaignProgress() +Account::Account(const string& name) + : name(name) + , campaignProgress() { difficulty = 0; progress = 0; @@ -46,7 +48,8 @@ Account::Account(const string& name) : name(name), campaignProgress() setCurrentCampaign("main"); } -Account::Account(FILE* tfile) : Account("") +Account::Account(FILE* tfile) + : Account("") { funpackf(tfile, "Bi", &difficulty); funpackf(tfile, "Bi", &progress); @@ -57,9 +60,9 @@ Account::Account(FILE* tfile) : Account("") string campaignName = ""; int t; char c; - funpackf(tfile, "Bi", &t); + funpackf(tfile, "Bi", &t); for (int j = 0; j < t; j++) { - funpackf(tfile, "Bb", &c); + funpackf(tfile, "Bb", &c); campaignName.append(1, c); } funpackf(tfile, "Bf", &(campaignProgress[campaignName].time)); @@ -80,9 +83,9 @@ Account::Account(FILE* tfile) : Account("") currentCampaign = ""; int t; char c; - funpackf(tfile, "Bi", &t); + funpackf(tfile, "Bi", &t); for (int i = 0; i < t; i++) { - funpackf(tfile, "Bb", &c); + funpackf(tfile, "Bb", &c); currentCampaign.append(1, c); } @@ -92,13 +95,13 @@ Account::Account(FILE* tfile) : Account("") funpackf(tfile, "Bf", &(fasttime[i])); } for (int i = 0; i < 60; i++) { - funpackf(tfile, "Bb", &(unlocked[i])); + funpackf(tfile, "Bb", &(unlocked[i])); } int temp; char ctemp; - funpackf(tfile, "Bi", &temp); + funpackf(tfile, "Bi", &temp); for (int i = 0; i < temp; i++) { - funpackf(tfile, "Bb", &ctemp); + funpackf(tfile, "Bb", &ctemp); name.append(1, ctemp); } if (name.empty()) { @@ -114,9 +117,9 @@ void Account::save(FILE* tfile) map::const_iterator it; for (it = campaignProgress.begin(); it != campaignProgress.end(); ++it) { - fpackf(tfile, "Bi", it->first.size()); + fpackf(tfile, "Bi", it->first.size()); for (unsigned j = 0; j < it->first.size(); j++) { - fpackf(tfile, "Bb", it->first[j]); + fpackf(tfile, "Bb", it->first[j]); } fpackf(tfile, "Bf", it->second.time); fpackf(tfile, "Bf", it->second.score); @@ -139,11 +142,11 @@ void Account::save(FILE* tfile) fpackf(tfile, "Bf", fasttime[j]); } for (unsigned j = 0; j < 60; j++) { - fpackf(tfile, "Bb", unlocked[j]); + fpackf(tfile, "Bb", unlocked[j]); } - fpackf(tfile, "Bi", name.size()); + fpackf(tfile, "Bi", name.size()); for (unsigned j = 0; j < name.size(); j++) { - fpackf(tfile, "Bb", name[j]); + fpackf(tfile, "Bb", name[j]); } } @@ -232,12 +235,12 @@ void Account::winLevel(int level, float score, float time) void Account::loadFile(string filename) { - FILE *tfile; + FILE* tfile; int numaccounts; int iactive; errno = 0; - tfile = fopen(filename.c_str(), "rb" ); + tfile = fopen(filename.c_str(), "rb"); if (tfile) { funpackf(tfile, "Bi", &numaccounts); @@ -258,10 +261,10 @@ void Account::loadFile(string filename) void Account::saveFile(string filename) { - FILE *tfile; + FILE* tfile; errno = 0; - tfile = fopen(filename.c_str(), "wb" ); + tfile = fopen(filename.c_str(), "wb"); if (tfile) { fpackf(tfile, "Bi", getNbAccounts()); fpackf(tfile, "Bi", i_active); diff --git a/Source/User/Settings.cpp b/Source/User/Settings.cpp index b1970d3..e3f709e 100644 --- a/Source/User/Settings.cpp +++ b/Source/User/Settings.cpp @@ -174,7 +174,7 @@ bool LoadSettings() { errno = 0; ifstream ipstream(Folders::getConfigFilePath(), std::ios::in); - if ( ipstream.fail() ) { + if (ipstream.fail()) { perror(("Couldn't read config file " + Folders::getConfigFilePath()).c_str()); return false; } @@ -183,118 +183,117 @@ bool LoadSettings() printf("Loading config\n"); while (!ipstream.eof()) { - ipstream.getline( setting, sizeof(setting) ); + ipstream.getline(setting, sizeof(setting)); // 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() ) { + if (ipstream.eof() || ipstream.fail()) { fprintf(stderr, "Error reading config file: Got setting name '%s', but value can't be read\n", setting); ipstream.close(); return false; } - - if ( !strncmp(setting, "Screenwidth", 11) ) { + if (!strncmp(setting, "Screenwidth", 11)) { ipstream >> kContextWidth; - } else if ( !strncmp(setting, "Screenheight", 12) ) { + } else if (!strncmp(setting, "Screenheight", 12)) { ipstream >> kContextHeight; - } else if ( !strncmp(setting, "Fullscreen", 10) ) { + } else if (!strncmp(setting, "Fullscreen", 10)) { ipstream >> fullscreen; - } else if ( !strncmp(setting, "Mouse sensitivity", 17) ) { + } else if (!strncmp(setting, "Mouse sensitivity", 17)) { ipstream >> usermousesensitivity; - } else if ( !strncmp(setting, "Blur", 4) ) { + } else if (!strncmp(setting, "Blur", 4)) { ipstream >> ismotionblur; - } else if ( !strncmp(setting, "Overall Detail", 14) ) { + } else if (!strncmp(setting, "Overall Detail", 14)) { ipstream >> detail; - } else if ( !strncmp(setting, "Floating jump", 13) ) { + } else if (!strncmp(setting, "Floating jump", 13)) { ipstream >> floatjump; - } else if ( !strncmp(setting, "Mouse jump", 10) ) { + } else if (!strncmp(setting, "Mouse jump", 10)) { ipstream >> mousejump; - } else if ( !strncmp(setting, "Ambient sound", 13) ) { + } else if (!strncmp(setting, "Ambient sound", 13)) { ipstream >> ambientsound; - } else if ( !strncmp(setting, "Blood", 5) ) { + } else if (!strncmp(setting, "Blood", 5)) { ipstream >> bloodtoggle; - } else if ( !strncmp(setting, "Auto slomo", 10) ) { + } else if (!strncmp(setting, "Auto slomo", 10)) { ipstream >> autoslomo; - } else if ( !strncmp(setting, "Foliage", 7) ) { + } else if (!strncmp(setting, "Foliage", 7)) { ipstream >> foliage; - } else if ( !strncmp(setting, "Music", 5) ) { + } else if (!strncmp(setting, "Music", 5)) { ipstream >> musictoggle; - } else if ( !strncmp(setting, "Trilinear", 9) ) { + } else if (!strncmp(setting, "Trilinear", 9)) { ipstream >> trilinear; - } else if ( !strncmp(setting, "Decals", 6) ) { + } else if (!strncmp(setting, "Decals", 6)) { ipstream >> decalstoggle; - } else if ( !strncmp(setting, "Invert mouse", 12) ) { + } else if (!strncmp(setting, "Invert mouse", 12)) { ipstream >> invertmouse; - } else if ( !strncmp(setting, "Gamespeed", 9) ) { + } else if (!strncmp(setting, "Gamespeed", 9)) { ipstream >> gamespeed; oldgamespeed = gamespeed; if (oldgamespeed == 0) { gamespeed = 1; oldgamespeed = 1; } - } else if ( !strncmp(setting, "Damage effects", 14) ) { + } else if (!strncmp(setting, "Damage effects", 14)) { ipstream >> damageeffects; - } else if ( !strncmp(setting, "Text", 4) ) { + } else if (!strncmp(setting, "Text", 4)) { ipstream >> texttoggle; - } else if ( !strncmp(setting, "Devtools", 8) ) { + } else if (!strncmp(setting, "Devtools", 8)) { ipstream >> devtools; - } else if ( !strncmp(setting, "Show Points", 11) ) { + } else if (!strncmp(setting, "Show Points", 11)) { ipstream >> showpoints; - } else if ( !strncmp(setting, "Always Blur", 11) ) { + } else if (!strncmp(setting, "Always Blur", 11)) { ipstream >> alwaysblur; - } else if ( !strncmp(setting, "Immediate mode ", 15) ) { + } else if (!strncmp(setting, "Immediate mode ", 15)) { ipstream >> immediate; - } else if ( !strncmp(setting, "Velocity blur", 13) ) { + } else if (!strncmp(setting, "Velocity blur", 13)) { ipstream >> velocityblur; - } else if ( !strncmp(setting, "Volume", 6) ) { + } else if (!strncmp(setting, "Volume", 6)) { ipstream >> volume; - } else if ( !strncmp(setting, "Forward key", 11) ) { + } else if (!strncmp(setting, "Forward key", 11)) { ipstream >> forwardkey; - } else if ( !strncmp(setting, "Back key", 8) ) { + } else if (!strncmp(setting, "Back key", 8)) { ipstream >> backkey; - } else if ( !strncmp(setting, "Left key", 8) ) { + } else if (!strncmp(setting, "Left key", 8)) { ipstream >> leftkey; - } else if ( !strncmp(setting, "Right key", 9) ) { + } else if (!strncmp(setting, "Right key", 9)) { ipstream >> rightkey; - } else if ( !strncmp(setting, "Jump key", 8) ) { + } else if (!strncmp(setting, "Jump key", 8)) { ipstream >> jumpkey; - } else if ( !strncmp(setting, "Crouch key", 10) ) { + } else if (!strncmp(setting, "Crouch key", 10)) { ipstream >> crouchkey; - } else if ( !strncmp(setting, "Draw key", 8) ) { + } else if (!strncmp(setting, "Draw key", 8)) { ipstream >> drawkey; - } else if ( !strncmp(setting, "Throw key", 9) ) { + } else if (!strncmp(setting, "Throw key", 9)) { ipstream >> throwkey; - } else if ( !strncmp(setting, "Attack key", 10) ) { + } else if (!strncmp(setting, "Attack key", 10)) { ipstream >> attackkey; - } else if ( !strncmp(setting, "Console key", 11) ) { + } else if (!strncmp(setting, "Console key", 11)) { ipstream >> consolekey; - } else if ( !strncmp(setting, "Damage bar", 10) ) { + } else if (!strncmp(setting, "Damage bar", 10)) { ipstream >> showdamagebar; - } else if ( !strncmp(setting, "StereoMode", 10) ) { + } else if (!strncmp(setting, "StereoMode", 10)) { int i; ipstream >> i; stereomode = (StereoMode)i; - } else if ( !strncmp(setting, "StereoSeparation", 16) ) { + } else if (!strncmp(setting, "StereoSeparation", 16)) { ipstream >> stereoseparation; - } else if ( !strncmp(setting, "StereoReverse", 13) ) { + } else if (!strncmp(setting, "StereoReverse", 13)) { ipstream >> stereoreverse; } else { ipstream >> string; fprintf(stderr, "Unknown config option '%s' with value '%s'. Ignoring.\n", setting, string); } - if ( ipstream.fail() ) { + if (ipstream.fail()) { fprintf(stderr, "Error reading config file: EOF reached when trying to read value for setting '%s'.\n", setting); ipstream.close(); return false; } - if ( ipstream.bad() ) { + if (ipstream.bad()) { fprintf(stderr, "Error reading config file: Failed to read value for setting '%s'.\n", setting); ipstream.close(); return false; diff --git a/Source/Utils/Folders.cpp b/Source/Utils/Folders.cpp index 3fa0402..2bf9bda 100644 --- a/Source/Utils/Folders.cpp +++ b/Source/Utils/Folders.cpp @@ -20,9 +20,9 @@ along with Lugaru. If not, see . #include "Folders.hpp" -#include -#include #include +#include +#include #include #if PLATFORM_UNIX @@ -51,7 +51,7 @@ std::string Folders::getUserDataPath() #ifdef _WIN32 char path[MAX_PATH]; // %APPDATA% (%USERPROFILE%\Application Data) - if(SUCCEEDED(SHGetFolderPathA(nullptr, CSIDL_APPDATA, nullptr, 0, path))) { + if (SUCCEEDED(SHGetFolderPathA(nullptr, CSIDL_APPDATA, nullptr, 0, path))) { userDataPath = std::string(path) + "/Lugaru/"; } else { return dataDir; @@ -84,7 +84,8 @@ std::string Folders::getConfigFilePath() #if PLATFORM_LINUX /* Generic code for XDG ENVVAR test and fallback */ -std::string Folders::getGenericDirectory(const char* ENVVAR, const std::string& fallback) { +std::string Folders::getGenericDirectory(const char* ENVVAR, const std::string& fallback) +{ const char* path = getenv(ENVVAR); std::string ret; if ((path != NULL) && (strlen(path) != 0)) { @@ -104,17 +105,18 @@ std::string Folders::getGenericDirectory(const char* ENVVAR, const std::string& #if PLATFORM_UNIX const char* Folders::getHomeDirectory() { - const char *homedir = getenv("HOME"); + const char* homedir = getenv("HOME"); if (homedir != NULL) return homedir; - struct passwd *pw = getpwuid(getuid()); + struct passwd* pw = getpwuid(getuid()); if (pw != NULL) return pw->pw_dir; return NULL; } #endif -bool Folders::makeDirectory(const std::string& path) { +bool Folders::makeDirectory(const std::string& path) +{ #ifdef _WIN32 int status = CreateDirectory(path.c_str(), NULL); return ((status != 0) || (GetLastError() == ERROR_ALREADY_EXISTS)); diff --git a/Source/Utils/ImageIO.cpp b/Source/Utils/ImageIO.cpp index 95f8954..cff8dd1 100644 --- a/Source/Utils/ImageIO.cpp +++ b/Source/Utils/ImageIO.cpp @@ -32,13 +32,13 @@ along with Lugaru. If not, see . extern int kContextWidth; extern int kContextHeight; -static bool load_png(const char * fname, ImageRec & tex); -static bool load_jpg(const char * fname, ImageRec & tex); -static bool save_screenshot_png(const char * fname); +static bool load_png(const char* fname, ImageRec& tex); +static bool load_jpg(const char* fname, ImageRec& tex); +static bool save_screenshot_png(const char* fname); ImageRec::ImageRec() { - data = ( GLubyte* )malloc( 1024 * 1024 * 4 ); + data = (GLubyte*)malloc(1024 * 1024 * 4); } ImageRec::~ImageRec() @@ -47,15 +47,15 @@ ImageRec::~ImageRec() data = NULL; } -bool load_image(const char *file_name, ImageRec &tex) +bool load_image(const char* file_name, ImageRec& tex) { Game::LoadingScreen(); - if ( tex.data == NULL ) { + if (tex.data == NULL) { return false; } - const char *ptr = strrchr((char *)file_name, '.'); + const char* ptr = strrchr((char*)file_name, '.'); if (ptr) { if (strcasecmp(ptr + 1, "png") == 0) { return load_png(file_name, tex); @@ -68,9 +68,9 @@ bool load_image(const char *file_name, ImageRec &tex) return false; } -bool save_screenshot(const char *file_name) +bool save_screenshot(const char* file_name) { - const char *ptr = strrchr((char *)file_name, '.'); + const char* ptr = strrchr((char*)file_name, '.'); if (ptr) { if (strcasecmp(ptr + 1, "png") == 0) { return save_screenshot_png((Folders::getScreenshotDir() + '/' + file_name).c_str()); @@ -81,27 +81,28 @@ bool save_screenshot(const char *file_name) return false; } -struct my_error_mgr { +struct my_error_mgr +{ struct jpeg_error_mgr pub; /* "public" fields */ - jmp_buf setjmp_buffer; /* for return to caller */ + jmp_buf setjmp_buffer; /* for return to caller */ }; -typedef struct my_error_mgr * my_error_ptr; +typedef struct my_error_mgr* my_error_ptr; static void my_error_exit(j_common_ptr cinfo) { - struct my_error_mgr *err = (struct my_error_mgr *)cinfo->err; + struct my_error_mgr* err = (struct my_error_mgr*)cinfo->err; longjmp(err->setjmp_buffer, 1); } /* stolen from public domain example.c code in libjpg distribution. */ -static bool load_jpg(const char *file_name, ImageRec &tex) +static bool load_jpg(const char* file_name, ImageRec& tex) { struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; JSAMPROW buffer[1]; /* Output row buffer */ - int row_stride; /* physical row width in output buffer */ + int row_stride; /* physical row width in output buffer */ errno = 0; - FILE *infile = fopen(file_name, "rb"); + FILE* infile = fopen(file_name, "rb"); if (infile == NULL) { perror((std::string("Couldn't open file ") + file_name).c_str()); @@ -118,12 +119,12 @@ static bool load_jpg(const char *file_name, ImageRec &tex) jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo, infile); - (void) jpeg_read_header(&cinfo, TRUE); + (void)jpeg_read_header(&cinfo, TRUE); cinfo.out_color_space = JCS_RGB; cinfo.quantize_colors = 0; - (void) jpeg_calc_output_dimensions(&cinfo); - (void) jpeg_start_decompress(&cinfo); + (void)jpeg_calc_output_dimensions(&cinfo); + (void)jpeg_start_decompress(&cinfo); row_stride = cinfo.output_width * cinfo.output_components; tex.sizeX = cinfo.output_width; @@ -131,12 +132,12 @@ static bool load_jpg(const char *file_name, ImageRec &tex) tex.bpp = 24; while (cinfo.output_scanline < cinfo.output_height) { - buffer[0] = (JSAMPROW)(char *)tex.data + + buffer[0] = (JSAMPROW)(char*)tex.data + ((cinfo.output_height - 1) - cinfo.output_scanline) * row_stride; - (void) jpeg_read_scanlines(&cinfo, buffer, 1); + (void)jpeg_read_scanlines(&cinfo, buffer, 1); } - (void) jpeg_finish_decompress(&cinfo); + (void)jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); fclose(infile); @@ -144,7 +145,7 @@ static bool load_jpg(const char *file_name, ImageRec &tex) } /* stolen from public domain example.c code in libpng distribution. */ -static bool load_png(const char *file_name, ImageRec &tex) +static bool load_png(const char* file_name, ImageRec& tex) { bool hasalpha = false; png_structp png_ptr = NULL; @@ -152,9 +153,9 @@ static bool load_png(const char *file_name, ImageRec &tex) png_uint_32 width, height; int bit_depth, color_type, interlace_type; bool retval = false; - png_byte **row_pointers = NULL; + png_byte** row_pointers = NULL; errno = 0; - FILE *fp = fopen(file_name, "rb"); + FILE* fp = fopen(file_name, "rb"); if (fp == NULL) { perror((std::string("Couldn't open file ") + file_name).c_str()); @@ -179,13 +180,13 @@ 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); @@ -194,9 +195,9 @@ static bool load_png(const char *file_name, ImageRec &tex) goto png_done; if (!hasalpha) { - png_byte *dst = tex.data; + png_byte* dst = tex.data; for (int i = height - 1; i >= 0; i--) { - png_byte *src = row_pointers[i]; + png_byte* src = row_pointers[i]; for (unsigned j = 0; j < width; j++) { dst[0] = src[0]; dst[1] = src[1]; @@ -209,7 +210,7 @@ static bool load_png(const char *file_name, ImageRec &tex) } else { - png_byte *dst = tex.data; + png_byte* dst = tex.data; int pitch = width * 4; for (int i = height - 1; i >= 0; i--, dst += pitch) memcpy(dst, row_pointers[i], pitch); @@ -230,9 +231,9 @@ png_done: return (retval); } -static bool save_screenshot_png(const char *file_name) +static bool save_screenshot_png(const char* file_name) { - FILE *fp = NULL; + FILE* fp = NULL; png_structp png_ptr = NULL; png_infop info_ptr = NULL; bool retval = false; @@ -244,7 +245,7 @@ static bool save_screenshot_png(const char *file_name) return false; } - png_bytep *row_pointers = new png_bytep[kContextHeight]; + png_bytep* row_pointers = new png_bytep[kContextHeight]; png_bytep screenshot = new png_byte[kContextWidth * kContextHeight * 3]; if ((!screenshot) || (!row_pointers)) goto save_png_done; diff --git a/Source/Utils/Input.cpp b/Source/Utils/Input.cpp index 06a7b74..5249e68 100644 --- a/Source/Utils/Input.cpp +++ b/Source/Utils/Input.cpp @@ -27,7 +27,7 @@ void Input::Tick() { SDL_PumpEvents(); int numkeys; - const Uint8 *keyState = SDL_GetKeyboardState(&numkeys); + const Uint8* keyState = SDL_GetKeyboardState(&numkeys); for (int i = 0; i < numkeys; i++) { keyPressed[i] = !keyDown[i] && keyState[i]; keyDown[i] = keyState[i]; diff --git a/Source/WinDefs.cpp b/Source/WinDefs.cpp index 4557d1e..f30e129 100644 --- a/Source/WinDefs.cpp +++ b/Source/WinDefs.cpp @@ -25,15 +25,15 @@ along with Lugaru. If not, see . #include #include - class AppTime { -public: - AppTime() { + public: + AppTime() + { counterRate = 1; baseCounter = 0; - QueryPerformanceFrequency( (LARGE_INTEGER*)&counterRate); - QueryPerformanceCounter( (LARGE_INTEGER*)&baseCounter); + QueryPerformanceFrequency((LARGE_INTEGER*)&counterRate); + QueryPerformanceCounter((LARGE_INTEGER*)&baseCounter); } __int64 counterRate; // LARGE_INTEGER type has no math functions so use int64 __int64 baseCounter; @@ -43,7 +43,7 @@ static AppTime g_appTime; AbsoluteTime UpTime() { __int64 counter; - QueryPerformanceCounter( (LARGE_INTEGER*)&counter); + QueryPerformanceCounter((LARGE_INTEGER*)&counter); counter -= g_appTime.baseCounter; @@ -53,8 +53,7 @@ AbsoluteTime UpTime() return time; } - -Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b) +Duration AbsoluteDeltaToDuration(AbsoluteTime& a, AbsoluteTime& b) { __int64 value = a.hi; value <<= 32; diff --git a/Source/main.cpp b/Source/main.cpp index 79c139f..169809a 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -36,9 +36,9 @@ along with Lugaru. If not, see . using namespace Game; #ifdef WIN32 +#include "win-res/resource.hpp" #include #include -#include "win-res/resource.hpp" #endif extern float multiplier; @@ -56,11 +56,11 @@ extern float slomofreq; extern int difficulty; -extern SDL_Window *sdlwindow; +extern SDL_Window* sdlwindow; using namespace std; -set> resolutions; +set> resolutions; // statics/globals (internal only) ------------------------------------------ @@ -75,45 +75,45 @@ int kContextHeight; void initGL() { - glClear( GL_COLOR_BUFFER_BIT ); + glClear(GL_COLOR_BUFFER_BIT); swap_gl_buffers(); // clear all states - glDisable( GL_ALPHA_TEST); - glDisable( GL_BLEND); - glDisable( GL_DEPTH_TEST); - glDisable( GL_FOG); - glDisable( GL_LIGHTING); - glDisable( GL_LOGIC_OP); - glDisable( GL_TEXTURE_1D); - glDisable( GL_TEXTURE_2D); - glPixelTransferi( GL_MAP_COLOR, GL_FALSE); - glPixelTransferi( GL_RED_SCALE, 1); - glPixelTransferi( GL_RED_BIAS, 0); - glPixelTransferi( GL_GREEN_SCALE, 1); - glPixelTransferi( GL_GREEN_BIAS, 0); - glPixelTransferi( GL_BLUE_SCALE, 1); - glPixelTransferi( GL_BLUE_BIAS, 0); - glPixelTransferi( GL_ALPHA_SCALE, 1); - glPixelTransferi( GL_ALPHA_BIAS, 0); + glDisable(GL_ALPHA_TEST); + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glDisable(GL_FOG); + glDisable(GL_LIGHTING); + glDisable(GL_LOGIC_OP); + glDisable(GL_TEXTURE_1D); + glDisable(GL_TEXTURE_2D); + glPixelTransferi(GL_MAP_COLOR, GL_FALSE); + glPixelTransferi(GL_RED_SCALE, 1); + glPixelTransferi(GL_RED_BIAS, 0); + glPixelTransferi(GL_GREEN_SCALE, 1); + glPixelTransferi(GL_GREEN_BIAS, 0); + glPixelTransferi(GL_BLUE_SCALE, 1); + glPixelTransferi(GL_BLUE_BIAS, 0); + glPixelTransferi(GL_ALPHA_SCALE, 1); + glPixelTransferi(GL_ALPHA_BIAS, 0); // set initial rendering states - glShadeModel( GL_SMOOTH); - glClearDepth( 1.0f); - glDepthFunc( GL_LEQUAL); - glDepthMask( GL_TRUE); - glEnable( GL_DEPTH_TEST); - glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glCullFace( GL_FRONT); - glEnable( GL_CULL_FACE); - glEnable( GL_LIGHTING); - glEnable( GL_DITHER); - glEnable( GL_COLOR_MATERIAL); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glAlphaFunc( GL_GREATER, 0.5f); - - if ( CanInitStereo(stereomode) ) { + glShadeModel(GL_SMOOTH); + glClearDepth(1.0f); + glDepthFunc(GL_LEQUAL); + glDepthMask(GL_TRUE); + glEnable(GL_DEPTH_TEST); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glCullFace(GL_FRONT); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_DITHER); + glEnable(GL_COLOR_MATERIAL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glAlphaFunc(GL_GREATER, 0.5f); + + if (CanInitStereo(stereomode)) { InitStereo(stereomode); } else { fprintf(stderr, "Failed to initialize stereo, disabling.\n"); @@ -133,7 +133,7 @@ void toggleFullscreen() SDL_SetWindowFullscreen(sdlwindow, flags); } -SDL_bool sdlEventProc(const SDL_Event &e) +SDL_bool sdlEventProc(const SDL_Event& e) { switch (e.type) { case SDL_QUIT: @@ -143,12 +143,12 @@ SDL_bool sdlEventProc(const SDL_Event &e) if (e.window.event == SDL_WINDOWEVENT_CLOSE) { return SDL_FALSE; } - break; + break; case SDL_MOUSEMOTION: deltah += e.motion.xrel; deltav += e.motion.yrel; - break; + break; case SDL_KEYDOWN: if ((e.key.keysym.scancode == SDL_SCANCODE_G) && @@ -158,10 +158,10 @@ SDL_bool sdlEventProc(const SDL_Event &e) 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) ) { + } else if ((e.key.keysym.scancode == SDL_SCANCODE_RETURN) && (e.key.keysym.mod & KMOD_ALT)) { toggleFullscreen(); } - break; + break; } return SDL_TRUE; } @@ -170,7 +170,7 @@ SDL_bool sdlEventProc(const SDL_Event &e) static Point gMidPoint; -bool SetUp () +bool SetUp() { LOGFUNC; @@ -203,8 +203,8 @@ bool SetUp () if (SDL_GetDisplayMode(displayIdx, i, &mode) == -1) continue; if ((mode.w < 640) || (mode.h < 480)) - continue; // sane lower limit. - pair resolution(mode.w, mode.h); + continue; // sane lower limit. + pair resolution(mode.w, mode.h); resolutions.insert(resolution); } } @@ -220,7 +220,7 @@ bool SetUp () if (commandLineOptions[SHOWRESOLUTIONS]) { printf("Available resolutions:\n"); for (auto resolution = resolutions.begin(); resolution != resolutions.end(); resolution++) { - printf(" %d x %d\n", (int) resolution->first, (int) resolution->second); + printf(" %d x %d\n", (int)resolution->first, (int)resolution->second); } } @@ -272,14 +272,13 @@ bool SetUp () SDL_GL_MakeCurrent(sdlwindow, glctx); int dblbuf = 0; - if ((SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &dblbuf) == -1) || (!dblbuf)) - { + if ((SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &dblbuf) == -1) || (!dblbuf)) { fprintf(stderr, "Failed to get a double-buffered context.\n"); SDL_Quit(); 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); @@ -301,7 +300,7 @@ bool SetUp () newscreenheight = screenheight; /* If saved resolution is not in the list, add it to the list (so that it’s selectable in the options) */ - pair startresolution(width,height); + pair startresolution(width, height); if (resolutions.find(startresolution) == resolutions.end()) { resolutions.insert(startresolution); } @@ -311,11 +310,10 @@ bool SetUp () return true; } - static void DoMouse() { - if (mainmenu || ( (abs(deltah) < 10 * realmultiplier * 1000) && (abs(deltav) < 10 * realmultiplier * 1000) )) { + if (mainmenu || ((abs(deltah) < 10 * realmultiplier * 1000) && (abs(deltav) < 10 * realmultiplier * 1000))) { deltah *= usermousesensitivity; deltav *= usermousesensitivity; mousecoordh += deltah; @@ -329,17 +327,16 @@ static void DoMouse() else if (mousecoordv >= kContextHeight) mousecoordv = kContextHeight - 1; } - } -void DoFrameRate (int update) +void DoFrameRate(int update) { static long frames = 0; - static AbsoluteTime time = {0, 0}; - static AbsoluteTime frametime = {0, 0}; - AbsoluteTime currTime = UpTime (); - double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime); + static AbsoluteTime time = { 0, 0 }; + static AbsoluteTime frametime = { 0, 0 }; + AbsoluteTime currTime = UpTime(); + double deltaTime = (float)AbsoluteDeltaToDuration(currTime, frametime); if (0 > deltaTime) // if negative microseconds deltaTime /= -1000000.0; @@ -354,7 +351,7 @@ void DoFrameRate (int update) if (update) frametime = currTime; // reset for next time interval - deltaTime = (float) AbsoluteDeltaToDuration (currTime, time); + deltaTime = (float)AbsoluteDeltaToDuration(currTime, time); if (0 > deltaTime) // if negative microseconds deltaTime /= -1000000.0; @@ -369,8 +366,7 @@ void DoFrameRate (int update) } } - -void DoUpdate () +void DoUpdate() { static float sps = 200; static int count; @@ -444,7 +440,7 @@ void DoUpdate () num_channels = 0; } */ - if ( stereomode == stereoNone ) { + if (stereomode == stereoNone) { DrawGLScene(stereoCenter); } else { DrawGLScene(stereoLeft); @@ -454,8 +450,7 @@ void DoUpdate () // -------------------------------------------------------------------------- - -void CleanUp (void) +void CleanUp(void) { LOGFUNC; @@ -471,30 +466,28 @@ static bool IsFocused() return ((SDL_GetWindowFlags(sdlwindow) & SDL_WINDOW_INPUT_FOCUS) != 0); } - - #ifndef WIN32 // (code lifted from physfs: http://icculus.org/physfs/ ... zlib license.) -static char *findBinaryInPath(const char *bin, char *envr) +static char* findBinaryInPath(const char* bin, char* envr) { size_t alloc_size = 0; - char *exe = NULL; - char *start = envr; - char *ptr; + char* exe = NULL; + char* start = envr; + char* ptr; do { size_t size; - ptr = strchr(start, ':'); /* find next $PATH separator. */ + ptr = strchr(start, ':'); /* find next $PATH separator. */ if (ptr) *ptr = '\0'; size = strlen(start) + strlen(bin) + 2; if (size > alloc_size) { - char *x = (char *) realloc(exe, size); + char* x = (char*)realloc(exe, size); if (x == NULL) { if (exe != NULL) free(exe); - return(NULL); + return (NULL); } /* if */ alloc_size = size; @@ -508,31 +501,30 @@ static char *findBinaryInPath(const char *bin, char *envr) strcat(exe, bin); if (access(exe, X_OK) == 0) { /* Exists as executable? We're done. */ - strcpy(exe, start); /* i'm lazy. piss off. */ - return(exe); + strcpy(exe, start); /* i'm lazy. piss off. */ + return (exe); } /* if */ - start = ptr + 1; /* start points to beginning of next element. */ + start = ptr + 1; /* start points to beginning of next element. */ } while (ptr != NULL); if (exe != NULL) free(exe); - return(NULL); /* doesn't exist in path. */ + return (NULL); /* doesn't exist in path. */ } /* findBinaryInPath */ - -char *calcBaseDir(const char *argv0) +char* calcBaseDir(const char* argv0) { /* If there isn't a path on argv0, then look through the $PATH for it. */ - char *retval; - char *envr; + char* retval; + char* envr; if (strchr(argv0, '/')) { retval = strdup(argv0); if (retval) - *((char *) strrchr(retval, '/')) = '\0'; - return(retval); + *((char*)strrchr(retval, '/')) = '\0'; + return (retval); } envr = getenv("PATH"); @@ -543,21 +535,21 @@ char *calcBaseDir(const char *argv0) return NULL; retval = findBinaryInPath(argv0, envr); free(envr); - return(retval); + return (retval); } -static inline void chdirToAppPath(const char *argv0) +static inline void chdirToAppPath(const char* argv0) { - char *dir = calcBaseDir(argv0); + char* dir = calcBaseDir(argv0); if (dir) { #if (defined(__APPLE__) && defined(__MACH__)) // Chop off /Contents/MacOS if it's at the end of the string, so we // land in the base of the app bundle. const size_t len = strlen(dir); - const char *bundledirs = "/Contents/MacOS"; + const char* bundledirs = "/Contents/MacOS"; const size_t bundledirslen = strlen(bundledirs); if (len > bundledirslen) { - char *ptr = (dir + len) - bundledirslen; + char* ptr = (dir + len) - bundledirslen; if (strcasecmp(ptr, bundledirs) == 0) *ptr = '\0'; } @@ -569,28 +561,29 @@ static inline void chdirToAppPath(const char *argv0) #endif const option::Descriptor usage[] = -{ - {UNKNOWN, 0, "", "", option::Arg::None, "USAGE: lugaru [options]\n\n" - "Options:" }, - {HELP, 0, "h", "help", option::Arg::None, " -h, --help Print usage and exit." }, - {FULLSCREEN, 1, "f", "fullscreen", option::Arg::None, " -f, --fullscreen Start the game in fullscreen mode." }, - {FULLSCREEN, 0, "w", "windowed", option::Arg::None, " -w, --windowed Start the game in windowed mode (default)." }, - {NOMOUSEGRAB, 1, "", "nomousegrab", option::Arg::None, " --nomousegrab Disable mousegrab." }, - {NOMOUSEGRAB, 0, "", "mousegrab", option::Arg::None, " --mousegrab Enable mousegrab (default)." }, - {SOUND, 1, "", "nosound", option::Arg::None, " --nosound Disable sound." }, - {OPENALINFO, 0, "", "openal-info", option::Arg::None, " --openal-info Print info about OpenAL at launch." }, - {SHOWRESOLUTIONS, 0, "", "showresolutions", option::Arg::None, " --showresolutions List the resolutions found by SDL at launch." }, - {DEVTOOLS, 0, "d", "devtools", option::Arg::None, " -d, --devtools Enable dev tools: console, level editor and debug info." }, - {0,0,0,0,0,0} -}; + { + { UNKNOWN, 0, "", "", option::Arg::None, "USAGE: lugaru [options]\n\n" + "Options:" }, + { HELP, 0, "h", "help", option::Arg::None, " -h, --help Print usage and exit." }, + { FULLSCREEN, 1, "f", "fullscreen", option::Arg::None, " -f, --fullscreen Start the game in fullscreen mode." }, + { FULLSCREEN, 0, "w", "windowed", option::Arg::None, " -w, --windowed Start the game in windowed mode (default)." }, + { NOMOUSEGRAB, 1, "", "nomousegrab", option::Arg::None, " --nomousegrab Disable mousegrab." }, + { NOMOUSEGRAB, 0, "", "mousegrab", option::Arg::None, " --mousegrab Enable mousegrab (default)." }, + { SOUND, 1, "", "nosound", option::Arg::None, " --nosound Disable sound." }, + { OPENALINFO, 0, "", "openal-info", option::Arg::None, " --openal-info Print info about OpenAL at launch." }, + { SHOWRESOLUTIONS, 0, "", "showresolutions", option::Arg::None, " --showresolutions List the resolutions found by SDL at launch." }, + { DEVTOOLS, 0, "d", "devtools", option::Arg::None, " -d, --devtools Enable dev tools: console, level editor and debug info." }, + { 0, 0, 0, 0, 0, 0 } + }; option::Option commandLineOptions[commandLineOptionsNumber]; option::Option* commandLineOptionsBuffer; -int main(int argc, char **argv) +int main(int argc, char** argv) { - argc-=(argc>0); argv+=(argc>0); // skip program name argv[0] if present - option::Stats stats(true, usage, argc, argv); + argc -= (argc > 0); + argv += (argc > 0); // skip program name argv[0] if present + option::Stats stats(true, usage, argc, argv); if (commandLineOptionsNumber != stats.options_max) { std::cerr << "Found incorrect command line option number" << std::endl; return 1; @@ -616,7 +609,7 @@ int main(int argc, char **argv) return 1; } - // !!! FIXME: we could use a Win32 API for this. --ryan. +// !!! FIXME: we could use a Win32 API for this. --ryan. #ifndef WIN32 chdirToAppPath(argv[0]); #endif @@ -629,7 +622,7 @@ int main(int argc, char **argv) { newGame(); - if (!SetUp ()) { + if (!SetUp()) { delete[] commandLineOptionsBuffer; return 42; } @@ -652,7 +645,7 @@ int main(int argc, char **argv) SDL_Event e; if (!waiting) { // message pump - while ( SDL_PollEvent( &e ) ) { + while (SDL_PollEvent(&e)) { if (!sdlEventProc(e)) { gameDone = true; break; @@ -677,7 +670,7 @@ int main(int argc, char **argv) deleteGame(); } - CleanUp (); + CleanUp(); return 0; #ifdef NDEBUG -- 2.39.2