X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FPerson.cpp;h=59994f890a4284b714593c85d3130db8ed4baa82;hb=a85869d3f9d2e627781068acc2595e8fa8a6aad9;hp=a95794520d7684204181c46ac80fc39693509209;hpb=7d89354018ef03ca4256ae63db3a8c89df5f277d;p=lugaru.git diff --git a/Source/Person.cpp b/Source/Person.cpp index a957945..59994f8 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -25,6 +25,8 @@ along with Lugaru. If not, see . #include "Sounds.h" #include "Awards.h" #include "Game.h" +#include "Dialog.h" +#include "Utils/Folders.h" extern float multiplier; extern Terrain terrain; @@ -53,8 +55,6 @@ extern bool decals; extern float fadestart; extern bool freeze; extern bool winfreeze; -extern float flashamount, flashr, flashg, flashb; -extern int flashdelay; extern bool showpoints; extern bool immediate; extern int tutoriallevel; @@ -67,8 +67,6 @@ extern float damagedealt; extern int hostile; extern float hostiletime; -extern int indialogue; - extern bool gamestarted; std::vector> Person::players(1, std::shared_ptr(new Person())); @@ -290,6 +288,7 @@ Person::Person() : stunned(0), surprised(0), runninghowlong(0), + occluded(0), lastoccluded(0), laststanding(0), escapednum(0), @@ -304,12 +303,104 @@ Person::Person() : tempanimation(), - occluded(0), - jumpclimb(false) { } +/* Read a person in tfile. Throws an error if it’s not valid */ +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); + if (mapvers >= 5) { + funpackf(tfile, "Bi", &howactive); + } else { + howactive = typeactive; + } + if (mapvers >= 3) { + funpackf(tfile, "Bf", &scale); + } else { + scale = -1; + } + if (mapvers >= 11) { + funpackf(tfile, "Bb", &immobile); + } else { + immobile = 0; + } + if (mapvers >= 12) { + funpackf(tfile, "Bf", &yaw); + } else { + yaw = 0; + } + targetyaw = yaw; + if (num_weapons < 0 || num_weapons > 5) { + throw InvalidPersonException(); + } + if (num_weapons > 0 && num_weapons < 5) { + for (int j = 0; j < num_weapons; j++) { + weaponids[j] = weapons.size(); + int type; + funpackf(tfile, "Bi", &type); + weapons.push_back(Weapon(type, id)); + } + } + funpackf(tfile, "Bi", &numwaypoints); + for (int j = 0; j < numwaypoints; j++) { + funpackf(tfile, "Bf", &waypoints[j].x); + funpackf(tfile, "Bf", &waypoints[j].y); + funpackf(tfile, "Bf", &waypoints[j].z); + if (mapvers >= 5) { + funpackf(tfile, "Bi", &waypointtype[j]); + } else { + waypointtype[j] = wpkeepwalking; + } + } + + funpackf(tfile, "Bi", &waypoint); + if (waypoint > (numwaypoints - 1)) { + waypoint = 0; + } + + funpackf(tfile, "Bf Bf Bf", &armorhead, &armorhigh, &armorlow); + funpackf(tfile, "Bf Bf Bf", &protectionhead, &protectionhigh, &protectionlow); + funpackf(tfile, "Bf Bf Bf", &metalhead, &metalhigh, &metallow); + funpackf(tfile, "Bf Bf", &power, &speedmult); + + float headprop, legprop, armprop, bodyprop; + + if (mapvers >= 4) { + funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop); + } else { + headprop = 1; + bodyprop = 1; + armprop = 1; + legprop = 1; + } + + if (creature == wolftype) { + proportionhead = 1.1 * headprop; + proportionbody = 1.1 * bodyprop; + proportionarms = 1.1 * armprop; + proportionlegs = 1.1 * legprop; + } else if (creature == rabbittype) { + proportionhead = 1.2 * headprop; + proportionbody = 1.05 * bodyprop; + proportionarms = 1.00 * armprop; + proportionlegs = 1.1 * legprop; + proportionlegs.y = 1.05 * legprop; + } + + funpackf(tfile, "Bi", &numclothes); + for (int k = 0; k < numclothes; k++) { + int templength; + funpackf(tfile, "Bi", &templength); + for (int l = 0; l < templength; l++) + funpackf(tfile, "Bb", &clothes[k][l]); + clothes[k][templength] = '\0'; + funpackf(tfile, "Bf Bf Bf", &clothestintr[k], &clothestintg[k], &clothestintb[k]); + } +} + /* EFFECT * * USES: @@ -413,7 +504,7 @@ void Person::CatchFire() */ int Person::getIdle() { - if (indialogue != -1 && howactive == typeactive && creature == rabbittype) + if (Dialog::inDialog() && (howactive == typeactive) && (creature == rabbittype)) return talkidleanim; if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/) if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype && @@ -643,12 +734,7 @@ void Person::DoBloodBig(float howmuch, int which) } if (id == 0 && howmuch > 0) { - // FIXME: manipulating attributes - flashamount = .5; - flashr = 1; - flashg = 0; - flashb = 0; - flashdelay = 0; + Game::flash(.5, 0); } if (bloodtoggle && decals && tutoriallevel != 1) { @@ -1699,76 +1785,52 @@ void Person::RagDoll(bool checkcollision) /* EFFECT */ -void Person::FootLand(int which, float opacity) +void Person::FootLand(bodyparts whichfoot, float opacity) { + if ((whichfoot != leftfoot) && (whichfoot != rightfoot)) { + cerr << "FootLand called on wrong bodypart" << endl; + return; + } static XYZ terrainlight; static XYZ footvel, footpoint; - if (opacity >= 1 || skiddelay <= 0) + if (opacity >= 1 || skiddelay <= 0) { if (opacity > 1) { footvel = 0; - if (which == 0) - footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords; - if (which == 1) - footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords; - //footpoint.y=coords.y; + footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords; if (distsq(&footpoint, &viewer)) Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity); - } else if (environment == snowyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) { + } else if (onterrain && terrain.getOpacity(coords.x, coords.z) < .2) { footvel = velocity / 5; if (footvel.y < .8) footvel.y = .8; - if (which == 0) - footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords; - if (which == 1) - footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords; + footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords; footpoint.y = terrain.getHeight(footpoint.x, footpoint.z); terrainlight = terrain.getLighting(footpoint.x, footpoint.z); - if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) - Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity); - if (opacity >= 1 || detail == 2) - if (detail == 2) - if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) + if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) { + if (environment == snowyenvironment) { + Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity); + if (detail == 2) { terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw); - } else if (environment == grassyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) { - footvel = velocity / 5; - if (footvel.y < .8) - footvel.y = .8; - if (which == 0) - footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords; - if (which == 1) - footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords; - footpoint.y = terrain.getHeight(footpoint.x, footpoint.z); - terrainlight = terrain.getLighting(footpoint.x, footpoint.z); - if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) - Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity); - } else if (environment == desertenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) { - footvel = velocity / 5; - if (footvel.y < .8) - footvel.y = .8; - if (which == 0) - footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords; - if (which == 1) - footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords; - footpoint.y = terrain.getHeight(footpoint.x, footpoint.z); - terrainlight = terrain.getLighting(footpoint.x, footpoint.z); - if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) - Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity); - if (opacity >= 1 || detail == 2) - if (detail == 2) - if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) + } + } else if (environment == grassyenvironment) { + Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity); + } else if (environment == desertenvironment) { + Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity); + if (detail == 2) { terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw); - } else if (isLanding() || animTarget == jumpupanim || isLandhard()) { + } + } + } + } else if (isLanding() || (animTarget == jumpupanim) || isLandhard()) { footvel = velocity / 5; if (footvel.y < .8) footvel.y = .8; - if (which == 0) - footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords; - if (which == 1) - footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords; - //footpoint.y=coords.y; - if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) + footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords; + if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) { Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity); + } } + } } /* EFFECT @@ -1926,12 +1988,12 @@ void Person::DoAnimations() else whichsound = footstepsound2; if (animation[animTarget].label[frameTarget] == 1) - FootLand(0, 1); + FootLand(leftfoot, 1); if (animation[animTarget].label[frameTarget] == 2) - FootLand(1, 1); + FootLand(rightfoot, 1); if (animation[animTarget].label[frameTarget] == 3 && isRun()) { - FootLand(1, 1); - FootLand(0, 1); + FootLand(rightfoot, 1); + FootLand(leftfoot, 1); } } @@ -2015,8 +2077,8 @@ void Person::DoAnimations() if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) { - FootLand(0, 1); - FootLand(1, 1); + FootLand(leftfoot, 1); + FootLand(rightfoot, 1); } transspeed = 0; @@ -2243,7 +2305,6 @@ void Person::DoAnimations() victim->skeleton.joints[i].velocity += relative * damagemult * 40; } victim->jointVel(head) += relative * damagemult * 200; - //FootLand(1,2); victim->Puff(head); victim->DoDamage(damagemult * 100 / victim->protectionhead); @@ -2279,7 +2340,6 @@ void Person::DoAnimations() victim->skeleton.joints[i].velocity += relative * damagemult * 20; } victim->jointVel(head) += relative * damagemult * 100; - //FootLand(1,2); victim->Puff(head); victim->DoDamage(damagemult * 50 / victim->protectionhead); } @@ -2310,7 +2370,6 @@ void Person::DoAnimations() victim->skeleton.joints[i].velocity += relative * damagemult * 40; } victim->jointVel(head) += relative * damagemult * 200; - //FootLand(1,2); victim->Puff(head); victim->DoDamage(damagemult * 150 / victim->protectionhead); @@ -2346,7 +2405,6 @@ void Person::DoAnimations() victim->skeleton.joints[i].velocity += relative * damagemult * 40; } victim->jointVel(head) += relative * damagemult * 200; - //FootLand(1,2); victim->Puff(head); victim->DoDamage(damagemult * 150 / victim->protectionhead); @@ -2376,7 +2434,6 @@ void Person::DoAnimations() victim->skeleton.joints[i].velocity += relative * damagemult * 30; } victim->jointVel(head) += relative * damagemult * 100; - //FootLand(1,2); victim->Puff(head); victim->DoDamage(damagemult * 50 / victim->protectionhead); } @@ -2967,7 +3024,6 @@ void Person::DoAnimations() } victim->jointVel(head) += relative * damagemult * 230; victim->jointVel(neck) += relative * damagemult * 230; - //FootLand(1,2); victim->Puff(head); if (tutoriallevel != 1) { victim->DoDamage(damagemult * 120 / victim->protectionhigh); @@ -3000,7 +3056,6 @@ void Person::DoAnimations() } victim->jointVel(head) += relative * damagemult * 220; victim->jointVel(neck) += relative * damagemult * 220; - //FootLand(1,2); victim->Puff(head); if (tutoriallevel != 1) { victim->DoDamage(damagemult * 350 / victim->protectionhead); @@ -3036,25 +3091,18 @@ void Person::DoAnimations() victim->RagDoll(0); XYZ relative; relative = 0; - /*relative=victim->coords-coords; - relative.y=0; - Normalise(&relative); - relative=DoRotation(relative,0,90,0);*/ relative.y = -1; Normalise(&relative); if (!victim->dead) { for (int i = 0; i < victim->skeleton.num_joints; i++) { victim->skeleton.joints[i].velocity = relative * damagemult * 40; } - //FootLand(1,2); victim->jointVel(abdomen) += relative * damagemult * 40; } if (victim->dead) { for (int i = 0; i < victim->skeleton.num_joints; i++) { victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20); } - //FootLand(1,2); - //victim->jointVel(abdomen)+=relative*damagemult*20; } victim->Puff(abdomen); if (tutoriallevel != 1) { @@ -3207,12 +3255,10 @@ void Person::DoAnimations() relative = victim->coords - oldcoords; relative.y = 0; Normalise(&relative); - //relative=DoRotation(relative,0,-90,0); for (int i = 0; i < victim->skeleton.num_joints; i++) { victim->skeleton.joints[i].velocity += relative * damagemult * 40; } victim->jointVel(abdomen) += relative * damagemult * 200; - //FootLand(1,2); victim->Puff(abdomen); victim->DoDamage(damagemult * 150 / victim->protectionhigh); @@ -3324,7 +3370,6 @@ void Person::DoAnimations() weapons[weaponids[weaponactive]].blooddrip += 3; } if (weaponactive == -1 && creature == wolftype) { - ; emit_sound_at(clawslicesound, victim->coords, 128.); victim->spurt = 1; victim->DoBloodBig(2 / victim->armorhigh, 175); @@ -3633,8 +3678,8 @@ void Person::DoAnimations() frameTarget = 0; if (wasStop()) { animTarget = getIdle(); - FootLand(0, 1); - FootLand(1, 1); + FootLand(leftfoot, 1); + FootLand(rightfoot, 1); } if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) { animTarget = rollanim; @@ -3688,8 +3733,8 @@ void Person::DoAnimations() } if (animCurrent == rollanim) { animTarget = getCrouch(); - FootLand(0, 1); - FootLand(1, 1); + FootLand(leftfoot, 1); + FootLand(rightfoot, 1); } if (isFlip()) { if (animTarget == walljumprightkickanim) { @@ -4375,11 +4420,7 @@ void Person::DoStuff() } if (id == 0) { - flashamount = .5; - flashr = 1; - flashg = 0; - flashb = 0; - flashdelay = 0; + Game::flash(.5, 0); } } @@ -5781,8 +5822,8 @@ void Person::DoStuff() if (velspeed > 5 && (isLanding() || isLandhard())) { skiddingdelay += multiplier; if (skiddelay <= 0) { - FootLand(0, .5); - FootLand(1, .5); + FootLand(leftfoot, .5); + FootLand(rightfoot, .5); skiddelay = .02; } } else @@ -5800,8 +5841,8 @@ void Person::DoStuff() if (velspeed > 5 && (isLanding() || isLandhard())) { skiddingdelay += multiplier; if (skiddelay <= 0) { - FootLand(0, .5); - FootLand(1, .5); + FootLand(leftfoot, .5); + FootLand(rightfoot, .5); skiddelay = .02; } } else @@ -6251,7 +6292,6 @@ int Person::DrawSkeleton() if (terrainheight > 1.7) terrainheight = 1.7; - //burnt=0; glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance); glDisable(GL_BLEND); glAlphaFunc(GL_GREATER, 0.0001); @@ -6751,7 +6791,7 @@ bool Person::addClothes(const int& clothesId) //Load Image ImageRec texture; - bool opened = load_image(fileName, texture); + bool opened = load_image(Folders::getResourcePath(fileName).c_str(), texture); float alphanum; //Is it valid?