diff options
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r-- | src/GameTick.cpp | 471 |
1 files changed, 217 insertions, 254 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp index af64a25..04502d5 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -989,7 +989,6 @@ void Game::Tick() XYZ blah; int closesttarget = 0; float leastdistance = 0.0; - XYZ vel; float tooclose; float toofar; @@ -2189,286 +2188,250 @@ void Game::Tick() sprites.MakeSprite(rainsprite, .5, 1, 1, 1, start, velocity, 2.00); } - //Grenade collision - int wherex, wherey, whichsound; - bool impact; - for(int i=0;i<sprites.howmanysprites;i++){ - if(sprites.type[i]==grenadesprite||sprites.type[i]==spoonsprite||sprites.type[i]==pinsprite){ - impact=0; - if(sprites.type[i]!=grenadesprite){ - sprites.brightness[i]-=multiplier*.2; - } - - if(findLengthfast(sprites.velocity[i])>0){ - wherex=(sprites.location[i].x+block_spacing/2)/block_spacing; - wherey=(sprites.location[i].z+block_spacing/2)/block_spacing; - move = {(float) wherex * block_spacing, 0.0f, (float) wherey * block_spacing}; - whichtri=blocks[citytype[wherex][wherey]].LineCheck2(sprites.oldlocation[i],sprites.location[i],&wallhit,move,cityrotation[wherex][wherey]*90); - - if (whichtri != -1) { - impact = 1; - auto normalrotated = DoRotation(blocks[citytype[wherex][wherey]].normals[whichtri], 0, cityrotation[wherex][wherey] * 90, 0); - if (sprites.size[i] > 1) - decals.MakeDecal(crater, wallhit, 9, normalrotated, whichtri, &blocks[citytype[wherex][wherey]], move, cityrotation[wherex][wherey] * 90); - sprites.location[i] = wallhit + normalrotated * 0.02f; - ReflectVector(&sprites.velocity[i], &normalrotated); - sprites.velocity[i] *= 0.3f; - - if (sprites.type[i] == grenadesprite - && sprites.size[i] <= 1) { - auto soundpos = sprites.location[i] - camera.position; - auto v = findLengthfast(sprites.velocity[i]) * 0.2f; - ALfloat gLoc[] { - soundpos.x / v / soundscalefactor, - soundpos.y / v / soundscalefactor, - soundpos.z / v / soundscalefactor, - }; - whichsound = bouncesound + randUint(2); - alSourcefv(gSourceID[whichsound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[whichsound]); - } - - if (findLengthfast(sprites.velocity[i]) <= 10) - sprites.velocity[i] = {}; + // Grenade collision + for (int i = 0; i < sprites.howmanysprites; ++i) { + switch (sprites.type[i]) { + case grenadesprite: + sprites.brightness[i] -= multiplier * 0.3f; + break; + case pinsprite: + case spoonsprite: + sprites.brightness[i] -= multiplier * 0.2f; + break; + default: + continue; + } + bool impact = false; + if(findLengthfast(sprites.velocity[i])>0){ + int wherex = sprites.location[i].x / block_spacing + 0.5f; + int wherey = sprites.location[i].z / block_spacing + 0.5f; + move = {(float) wherex * block_spacing, 0.0f, (float) wherey * block_spacing}; + whichtri=blocks[citytype[wherex][wherey]].LineCheck2(sprites.oldlocation[i],sprites.location[i],&wallhit,move,cityrotation[wherex][wherey]*90); + + if (whichtri != -1) { + impact = true; + auto normalrotated = DoRotation(blocks[citytype[wherex][wherey]].normals[whichtri], 0, cityrotation[wherex][wherey] * 90, 0); + if (sprites.size[i] > 1) + decals.MakeDecal(crater, wallhit, 9, normalrotated, whichtri, &blocks[citytype[wherex][wherey]], move, cityrotation[wherex][wherey] * 90); + sprites.location[i] = wallhit + normalrotated * 0.02f; + ReflectVector(&sprites.velocity[i], &normalrotated); + sprites.velocity[i] *= 0.3f; + + if (sprites.type[i] == grenadesprite && sprites.size[i] <= 1) { + auto soundpos = sprites.location[i] - camera.position; + auto v = findLengthfast(sprites.velocity[i]) * 0.2f; + ALfloat gLoc[] { + soundpos.x / v / soundscalefactor, + soundpos.y / v / soundscalefactor, + soundpos.z / v / soundscalefactor, + }; + int whichsound = bouncesound + randUint(2); + alSourcefv(gSourceID[whichsound], AL_POSITION, gLoc); + alSourcePlay(gSourceID[whichsound]); } - if(sprites.location[i].y<0){ - impact=1; - sprites.velocity[i].y *= -1.0f; - sprites.velocity[i] *= 0.3f; - sprites.location[i].y = 0.0f; - - if(sprites.type[i]==grenadesprite){ - if(sprites.size[i]>1){ - move = {}; - sprites.location[i].y=-.5; - XYZ normish = {0.0f, 1.0f, 0.0f}; - decals.MakeDecal(crater, sprites.location[i],9,normish, 0, &blocks[citytype[wherex][wherey]], move, 0); - } + if (findLengthfast(sprites.velocity[i]) <= 10) + sprites.velocity[i] = {}; + } - auto soundpos = sprites.location[i] - camera.position; - auto v = findLengthfast(sprites.velocity[i]) * 0.2f; - ALfloat gLoc[] { - soundpos.x / v / soundscalefactor, - soundpos.y / v / soundscalefactor, - soundpos.z / v / soundscalefactor, - }; - whichsound = bouncesound + randUint(2); - alSourcefv(gSourceID[whichsound], AL_POSITION, gLoc); - if (sprites.size[i] <= 1) - alSourcePlay(gSourceID[whichsound]); + if(sprites.location[i].y<0){ + impact = true; + sprites.velocity[i].y *= -1.0f; + sprites.velocity[i] *= 0.3f; + sprites.location[i].y = 0.0f; + if(sprites.type[i]==grenadesprite){ + if(sprites.size[i]>1){ + move = {}; + sprites.location[i].y=-.5; + XYZ normish = {0.0f, 1.0f, 0.0f}; + decals.MakeDecal(crater, sprites.location[i],9,normish, 0, &blocks[citytype[wherex][wherey]], move, 0); } - if (findLengthfast(sprites.velocity[i]) <= 10) - sprites.velocity[i] = {}; + auto soundpos = sprites.location[i] - camera.position; + auto v = findLengthfast(sprites.velocity[i]) * 0.2f; + ALfloat gLoc[] { + soundpos.x / v / soundscalefactor, + soundpos.y / v / soundscalefactor, + soundpos.z / v / soundscalefactor, + }; + int whichsound = bouncesound + randUint(2); + alSourcefv(gSourceID[whichsound], AL_POSITION, gLoc); + if (sprites.size[i] <= 1) + alSourcePlay(gSourceID[whichsound]); } - if(sprites.type[i]==grenadesprite&&findLengthfast(sprites.velocity[i])>20){ - - HitStruct hitstruct; - - for(int j=0;j<numpeople;j++){ - - if((j!=0||sprites.brightness[i]<.9)&&person[j].existing){ - - hitstruct=person[j].BulletCollideWithPlayer(j, sprites.oldlocation[i], sprites.location[i]); - - if(hitstruct.collision){ - - impact=1; - - sprites.location[i] = hitstruct.hitlocation; - auto landpos = sprites.location[i] - camera.position; - auto v = findLengthfast(sprites.velocity[i]) * 0.2f; - ALfloat gLoc[] { - landpos.x / v / soundscalefactor, - landpos.y / v / soundscalefactor, - landpos.z / v / soundscalefactor, - }; - - if(person[j].skeleton.free<1){ - - if((hitstruct.joint1->label==head||hitstruct.joint2->label==head)&&person[j].type!=zombietype){ - - alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc); - - if(sprites.size[i]<=1)alSourcePlay(gSourceID[headwhacksound]); - - person[j].skeleton.free=1; - - person[j].longdead=1; - - for (auto& joint : person[j].skeleton.joints) { - joint.realoldposition = joint.position - = DoRotation(joint.position, - 0, person[j].playerrotation, 0) - + person[j].playercoords; - - joint.velocity = person[j].velocity; - joint.velocity.x += randInt(-4, 4); - joint.velocity.y += randInt(-4, 4); - joint.velocity.z += randInt(-4, 4); - } - - hitstruct.joint1->velocity += sprites.velocity[i]; - hitstruct.joint2->velocity += sprites.velocity[i]; + if (findLengthfast(sprites.velocity[i]) <= 10) + sprites.velocity[i] = {}; + } - if (person[j].type == civiliantype) - civkills++; - if (person[j].type == eviltype) - goodkills++; - } else { - float totalarea = 0.0f; + if(sprites.type[i]==grenadesprite&&findLengthfast(sprites.velocity[i])>20){ + for (int j = 0; j < numpeople; ++j) { + if (j == 0 && sprites.brightness[i] > 0.9f || !person[j].existing) + continue; + auto hitstruct = person[j].BulletCollideWithPlayer(j, sprites.oldlocation[i], sprites.location[i]); + if (!hitstruct.collision) + continue; + impact = true; + sprites.location[i] = hitstruct.hitlocation; + auto landpos = sprites.location[i] - camera.position; + auto v = findLengthfast(sprites.velocity[i]) * 0.2f; + ALfloat gLoc[] { + landpos.x / v / soundscalefactor, + landpos.y / v / soundscalefactor, + landpos.z / v / soundscalefactor, + }; - alSourcefv(gSourceID[bodywhacksound], AL_POSITION, gLoc); + sprites.velocity[i] *= -0.3f; + if (person[j].skeleton.free) + continue; + if((hitstruct.joint1->label==head||hitstruct.joint2->label==head)&&person[j].type!=zombietype){ + alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc); + if(sprites.size[i]<=1)alSourcePlay(gSourceID[headwhacksound]); + person[j].skeleton.free=1; + person[j].longdead=1; + for (auto& joint : person[j].skeleton.joints) { + joint.realoldposition = joint.position + = DoRotation(joint.position, + 0, person[j].playerrotation, 0) + + person[j].playercoords; + + joint.velocity = person[j].velocity; + joint.velocity.x += randInt(-4, 4); + joint.velocity.y += randInt(-4, 4); + joint.velocity.z += randInt(-4, 4); + } - if(sprites.size[i]<=1)alSourcePlay(gSourceID[bodywhacksound]); + hitstruct.joint1->velocity += sprites.velocity[i]; + hitstruct.joint2->velocity += sprites.velocity[i]; - person[j].skeleton.offset=1; + if (person[j].type == civiliantype) + civkills++; + if (person[j].type == eviltype) + goodkills++; + } else { + float totalarea = 0.0f; + alSourcefv(gSourceID[bodywhacksound], AL_POSITION, gLoc); + if(sprites.size[i]<=1)alSourcePlay(gSourceID[bodywhacksound]); + person[j].skeleton.offset=1; - for (auto& joint : person[j].skeleton.joints) { - auto distance = findDistancefast(DoRotation(joint.position, 0, person[j].playerrotation, 0) + person[j].playercoords, hitstruct.hitlocation); - if (distance < 200) { - totalarea += 200 / distance; - joint.offset += DoRotation(sprites.velocity[i] * 0.1 * 200 / distance / totalarea * 10, 0, -person[j].playerrotation, 0); - } - if (findLengthfast(joint.offset) > 9) { - Normalise(&joint.offset); - joint.offset *= 3; - } - } - }} - sprites.velocity[i]*=-.3; + for (auto& joint : person[j].skeleton.joints) { + auto distance = findDistancefast(DoRotation(joint.position, 0, person[j].playerrotation, 0) + person[j].playercoords, hitstruct.hitlocation); + if (distance < 200) { + totalarea += 200 / distance; + joint.offset += DoRotation(sprites.velocity[i] * 0.1 * 200 / distance / totalarea * 10, 0, -person[j].playerrotation, 0); + } + if (findLengthfast(joint.offset) > 9) { + Normalise(&joint.offset); + joint.offset *= 3; } } } } - sprites.oldlocation[i]=sprites.location[i]; } + sprites.oldlocation[i]=sprites.location[i]; + } - //Explode - - if(sprites.type[i]==grenadesprite){ - - sprites.brightness[i]-=multiplier*.3; - - if(sprites.brightness[i]<=0||(impact&&sprites.size[i]>1)){ - sprites.brightness[i]=0; - sprites.MakeSprite(smokesprite, 1, 1, 1, 1, sprites.location[i], facing*0, 60); - sprites.MakeSprite(muzzleflashsprite, 1, 1, 1, 1, sprites.location[i], facing*0, 9); - - auto explodepos = sprites.location[i] - - camera.position; - ALfloat gLoc[] { - explodepos.x / 3 / soundscalefactor, - explodepos.y / 3 / soundscalefactor, - explodepos.z / 3 / soundscalefactor, - }; - alSourcefv(gSourceID[explosionsound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[explosionsound]); - - XYZ relation; - - camerashake=1-findDistance(person[0].playercoords,sprites.location[i])/200; - - //if(!sprites.size[i]>1){ - - overpoint=sprites.location[i]; - overpoint.y+=3000; - underpoint=sprites.location[i]; - underpoint.y-=3000; - wherex=(sprites.location[i].x+block_spacing/2)/block_spacing; - wherey=(sprites.location[i].z+block_spacing/2)/block_spacing; - move = {(float) wherex * block_spacing, 0.0f, (float) wherey * block_spacing}; - - - XYZ temp; - - whichtri=sidewalkcollide.LineCheck2(overpoint,underpoint,&temp,move,cityrotation[wherex][wherey]*90); - - XYZ normish = {0.0f, 1.0f, 0.0f}; - if(whichtri>=0){ - - decals.MakeDecal(crater, sprites.location[i],9,normish, 0, &sidewalkcollide, move, cityrotation[wherex][wherey]*90); - - } - - if(whichtri==-1){ - temp=sprites.location[i]; - temp.y=-.5; - move = {}; - decals.MakeDecal(crater, sprites.location[i],9,normish, 0, &sidewalkcollide, move, 0); - } - //} - - for(int k=0;k<numpeople;k++){ - - if(person[k].existing&&(person[k].longdead!=-1||person[k].skeleton.free<1)){ - - if((findDistancefast(person[k].playercoords,sprites.location[i])<700&&person[k].skeleton.free<1)||(findDistancefast(person[k].averageloc,sprites.location[i])<700&&person[k].skeleton.free>=1)){ - - if(person[k].skeleton.free!=1){ - - if(person[k].type==civiliantype)civkills++; - - if(person[k].type==eviltype)goodkills++; - - person[k].skeleton.free=1; + // Explode + if (sprites.type[i] == grenadesprite + && (sprites.brightness[i] <= 0 || impact && sprites.size[i] > 1)) { + sprites.brightness[i] = 0; + sprites.MakeSprite(smokesprite, 1, 1, 1, 1, sprites.location[i], facing*0, 60); + sprites.MakeSprite(muzzleflashsprite, 1, 1, 1, 1, sprites.location[i], facing*0, 9); + + auto explodepos = sprites.location[i] - camera.position; + ALfloat gLoc[] { + explodepos.x / 3 / soundscalefactor, + explodepos.y / 3 / soundscalefactor, + explodepos.z / 3 / soundscalefactor, + }; + alSourcefv(gSourceID[explosionsound], AL_POSITION, gLoc); + alSourcePlay(gSourceID[explosionsound]); + + XYZ relation; + camerashake=1-findDistance(person[0].playercoords,sprites.location[i])/200; + + overpoint=sprites.location[i]; + overpoint.y+=3000; + underpoint=sprites.location[i]; + underpoint.y-=3000; + int wherex=(sprites.location[i].x+block_spacing/2)/block_spacing; + int wherey=(sprites.location[i].z+block_spacing/2)/block_spacing; + move = {(float) wherex * block_spacing, 0.0f, (float) wherey * block_spacing}; + + XYZ temp; + whichtri=sidewalkcollide.LineCheck2(overpoint,underpoint,&temp,move,cityrotation[wherex][wherey]*90); + + XYZ normish = {0.0f, 1.0f, 0.0f}; + if(whichtri>=0){ + decals.MakeDecal(crater, sprites.location[i],9,normish, 0, &sidewalkcollide, move, cityrotation[wherex][wherey]*90); + } - person[k].killtargetvisible=0; + if(whichtri==-1){ + temp=sprites.location[i]; + temp.y=-.5; + move = {}; + decals.MakeDecal(crater, sprites.location[i],9,normish, 0, &sidewalkcollide, move, 0); + } - if((findDistancefast(person[k].playercoords,sprites.location[i])<600&&person[k].skeleton.free<1)||(findDistancefast(person[k].averageloc,sprites.location[i])<600&&person[k].skeleton.free>=1)||person[k].type==playertype){ + for(int k=0;k<numpeople;k++){ + if (!person[k].existing + || person[k].longdead == -1 && person[k].skeleton.free + || (findDistancefast(person[k].playercoords,sprites.location[i]) > 700 || person[k].skeleton.free) + && (findDistancefast(person[k].averageloc,sprites.location[i]) > 700 || !person[k].skeleton.free)) + continue; + if(person[k].skeleton.free!=1){ + if(person[k].type==civiliantype)civkills++; + if(person[k].type==eviltype)goodkills++; - person[k].health-=100; + person[k].skeleton.free=1; + person[k].killtargetvisible=0; - person[k].bleeding=1; + if((findDistancefast(person[k].playercoords,sprites.location[i])<600&&person[k].skeleton.free<1)||(findDistancefast(person[k].averageloc,sprites.location[i])<600&&person[k].skeleton.free>=1)||person[k].type==playertype){ + person[k].health-=100; + person[k].bleeding=1; + } - } + person[k].DoAnimations(k); + person[k].longdead = 1; + person[k].bleeddelay = 1; + + person[k].bjoint1 = &person[k].skeleton.joints[head]; + person[k].bjoint2 = &person[k].skeleton.joints[neck]; + + for (auto& joint : person[k].skeleton.joints) { + joint.position = DoRotation(joint.position, 0, person[k].playerrotation, 0); + joint.position += person[k].playercoords; + joint.realoldposition = joint.position; + joint.velocity = DoRotation(joint.velocity, 0, person[k].playerrotation, 0); + joint.velocity += person[k].velocity; + joint.velocity.x += randInt(-9, 9); + joint.velocity.y += randInt(-9, 9); + joint.velocity.z += randInt(-9, 9); + } + } - person[k].DoAnimations(k); - person[k].longdead = 1; - person[k].bleeddelay = 1; - - person[k].bjoint1 = &person[k].skeleton.joints[head]; - person[k].bjoint2 = &person[k].skeleton.joints[neck]; - - for (auto& joint : person[k].skeleton.joints) { - joint.position = DoRotation(joint.position, 0, person[k].playerrotation, 0); - joint.position += person[k].playercoords; - joint.realoldposition = joint.position; - joint.velocity = DoRotation(joint.velocity, 0, person[k].playerrotation, 0); - joint.velocity += person[k].velocity; - joint.velocity.x += randInt(-9, 9); - joint.velocity.y += randInt(-9, 9); - joint.velocity.z += randInt(-9, 9); - }} - - person[k].longdead=1; - for (auto& joint : person[k].skeleton.joints) { - relation = joint.position - sprites.location[i]; - Normalise(&relation); - auto distance = findDistance(joint.position, sprites.location[i]); - if (distance > 1) - joint.velocity += relation / distance * 300; - else - joint.velocity += relation * 300; - - // Sever stuff - if (findLengthfast(joint.velocity) > 1500 - && joint.existing && randUint(5)) { - sprites.MakeSprite(bloodspritedown, 0.8, 1, 0.2, 0.2, joint.position, joint.velocity / 3, 9); - person[k].skeleton.DeleteJoint(&joint - - person[k].skeleton.joints); - person[k].skeleton.broken=2; - person[k].health=-10000; - joint.existing = false; - } - } - } - } + person[k].longdead=1; + for (auto& joint : person[k].skeleton.joints) { + relation = joint.position - sprites.location[i]; + Normalise(&relation); + auto distance = findDistance(joint.position, sprites.location[i]); + if (distance > 1) + joint.velocity += relation / distance * 300; + else + joint.velocity += relation * 300; + + // Sever stuff + if (findLengthfast(joint.velocity) > 1500 + && joint.existing && randUint(5)) { + sprites.MakeSprite(bloodspritedown, 0.8, 1, 0.2, 0.2, joint.position, joint.velocity / 3, 9); + person[k].skeleton.DeleteJoint(&joint + - person[k].skeleton.joints); + person[k].skeleton.broken=2; + person[k].health=-10000; + joint.existing = false; } } } |