glEnable(GL_BLEND);
glEnable(GL_LIGHTING);
terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
- distance=findDistancefast(&viewer,&player[k].coords);
+ distance=distsq(&viewer,&player[k].coords);
distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
if(distance>=1)
}
if(!cameramode&&musictype==stream_fighttheme)
- playerdist=findDistancefastflat(&player[0].coords,&viewer);
+ playerdist=distsqflat(&player[0].coords,&viewer);
else
playerdist=-100;
glPushMatrix();
glTranslatef(hawkcoords.x,hawkcoords.y,hawkcoords.z);
glRotatef(hawkyaw,0,1,0);
glTranslatef(25,0,0);
- distance=findDistancefast(&viewer,&realhawkcoords)*1.2;
+ distance=distsq(&viewer,&realhawkcoords)*1.2;
glColor4f(light.color[0],light.color[1],light.color[2],(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance);
if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>1)
glColor4f(light.color[0],light.color[1],light.color[2],1);
glEnable(GL_BLEND);
glEnable(GL_LIGHTING);
terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
- distance=findDistancefast(&viewer,&player[k].coords);
+ distance=distsq(&viewer,&player[k].coords);
distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
if(distance>=1)
float distance=0;
closest=currenthotspot;
for(i=0;i<numhotspots;i++){
- distance=findDistancefast(&player[0].coords,&hotspot[i]);
+ distance=distsq(&player[0].coords,&hotspot[i]);
if(closestdist==-1||distance<closestdist){
- if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i]&&((hotspottype[i]<=10&&hotspottype[i]>=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){
+ if(distsq(&player[0].coords,&hotspot[i])<hotspotsize[i]&&((hotspottype[i]<=10&&hotspottype[i]>=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){
closestdist=distance;
closest=i;
}
currenthotspot=closest;
if(currenthotspot!=-1){
if(hotspottype[closest]<=10){
- if(findDistancefast(&player[0].coords,&hotspot[closest])<hotspotsize[closest])
+ if(distsq(&player[0].coords,&hotspot[closest])<hotspotsize[closest])
tutorialstagetime=0;
tutorialmaxtime=1;
tutorialopac=tutorialmaxtime-tutorialstagetime;
float tempdist;
//~ int whichclosest;
for(i=0;i<objects.numobjects;i++){
- tempdist=findDistancefast(¢er,&objects.position[i]);
+ tempdist=distsq(¢er,&objects.position[i]);
if(tempdist>maxdistance){
//~ whichclosest=i;
maxdistance=tempdist;
}
for(i=0;i<numplayers;i++){
if(!player[i].dead){
- tempdist=findDistancefast(¢er,&player[i].coords);
+ tempdist=distsq(¢er,&player[i].coords);
if(tempdist>maxdistance){
//~ whichclosest=i;
maxdistance=tempdist;
glTranslatef(-(center.x/terrain.scale/256*-2+1),(center.z/terrain.scale/256*-2+1),0);
for(i=0;i<objects.numobjects;i++){
if(objects.type[i]==treetrunktype){
- distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
+ distcheck=distsq(&player[0].coords,&objects.position[i]);
if(distcheck<mapviewdist){
Mapcircletexture.bind();
glColor4f(0,.3,0,opac*(1-distcheck/mapviewdist));
}
}
if(objects.type[i]==boxtype){
- distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
+ distcheck=distsq(&player[0].coords,&objects.position[i]);
if(distcheck<mapviewdist){
Mapboxtexture.bind();
glColor4f(.4,.4,.4,opac*(1-distcheck/mapviewdist));
}
}
for(i=0;i<numplayers;i++){
- distcheck=findDistancefast(&player[0].coords,&player[i].coords);
+ distcheck=distsq(&player[0].coords,&player[i].coords);
if(distcheck<mapviewdist){
glPushMatrix();
Maparrowtexture.bind();
float closestdist = std::numeric_limits<float>::max();
for(int i=1; i<numplayers; i++){
- float distance = findDistancefast(&player[i].coords, &player[0].coords);
+ float distance = distsq(&player[i].coords, &player[0].coords);
if(distance < closestdist){
closestdist = distance;
closest = i;
float closestdist = std::numeric_limits<float>::max();
for(int i=0; i<objects.numobjects; i++){
- float distance = findDistancefast(&objects.position[i], &player[0].coords);
+ float distance = distsq(&objects.position[i], &player[0].coords);
if(distance < closestdist){
closestdist = distance;
closest = i;
float tempdist;
//~ int whichclosest;
for(int i=0;i<objects.numobjects;i++){
- tempdist=findDistancefast(&objects.center,&objects.position[i]);
+ tempdist=distsq(&objects.center,&objects.position[i]);
if(tempdist>maxdistance){
//~ whichclosest=i;
maxdistance=tempdist;
float closestdist = std::numeric_limits<float>::max();
for(int i=1; i<numplayers; i++){
- float distance = findDistancefast(&player[i].coords, &player[0].coords);
+ float distance = distsq(&player[i].coords, &player[0].coords);
if(!player[i].headless)
if(distance < closestdist){
closestdist = distance;
XYZ flatfacing2,flatvelocity2;
XYZ blah;
- if(closest!=-1 && findDistancefast(&player[closest].coords, &player[0].coords)<144){
+ if(closest!=-1 && distsq(&player[closest].coords, &player[0].coords)<144){
blah = player[closest].coords;
XYZ headspurtdirection;
//int i = player[closest].skeleton.jointlabels[head];
int closest=findClosestPlayer();
XYZ flatfacing2,flatvelocity2;
XYZ blah;
- if(closest>=0 && findDistancefast(&player[closest].coords,&player[0].coords)<144){
+ if(closest>=0 && distsq(&player[closest].coords,&player[0].coords)<144){
blah=player[closest].coords;
emit_sound_at(splattersound, blah);
emit_sound_at(breaksound2, blah);
XYZ temppos;
for(int j=0;j<numplayers; j++){
if(j!=closest){
- if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
- player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
+ if(distsq(&player[j].coords,&player[closest].coords)<25){
+ player[j].DoDamage((25-distsq(&player[j].coords,&player[closest].coords))*60);
if(player[j].skeleton.free==2)
player[j].skeleton.free=1;
player[j].skeleton.longdead=0;
player[j].RagDoll(0);
for(int i=0;i<player[j].skeleton.num_joints; i++){
temppos=player[j].skeleton.joints[i].position+player[j].coords;
- if(findDistancefast(&temppos,&player[closest].coords)<25){
+ if(distsq(&temppos,&player[closest].coords)<25){
flatvelocity2=temppos-player[closest].coords;
Normalise(&flatvelocity2);
- player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
+ player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-distsq(&temppos,&player[closest].coords))*20);
}
}
}
connected=0;
if(numpathpoints>1)
for(int i=0;i<numpathpoints;i++){
- if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
+ if(distsq(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
alreadyconnected=0;
for(int j=0;j<numpathpointconnect[pathpointselected];j++){
if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
player[k].aitype==playercontrolled)&&
(player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
- if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
- findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
+ if( distsq(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
+ distsqflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
//TODO: refactor two huge similar ifs
if(player[i].targetanimation==jumpupanim&&
player[k].targetanimation!=getupfrombackanim&&
player[k].yaw=stepTowardf(player[k].yaw, player[k].targetyaw, multiplier*player[k].turnspeed*4);
}
- /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
+ /*if(player[k].aitype!=passivetype||(distsq(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
player[k].DoStuff();
if(player[k].immobile&&k!=0)
player[k].coords=player[k].realoldcoords;
//if player's position has changed (?)
- if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
+ if(distsq(&player[k].coords,&player[k].realoldcoords)>0&&
!player[k].skeleton.free&&
player[k].targetanimation!=climbanim&&
player[k].targetanimation!=hanganim){
player[i].targetanimation==knifeslashstartanim||
player[i].targetanimation==staffhitanim||
player[i].targetanimation==staffspinhitanim)
- if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
+ if(distsq(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
player[k].setAnimation(dodgebackanim);
player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords);
player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
if(!player[k].hasvictim)
if(animation[player[k].targetanimation].attack!=reversal){
//choose an attack
- const float distance=findDistancefast(&player[k].coords,&player[i].coords);
+ const float distance=distsq(&player[k].coords,&player[i].coords);
if(distance<4.5&&
!player[i].skeleton.free&&
player[i].howactive<typedead1&&
if(i==k)continue;
if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
animation[player[k].targetanimation].attack==neutral){
- const float distance=findDistancefast(&player[k].coords,&player[i].coords);
+ const float distance=distsq(&player[k].coords,&player[i].coords);
if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
if(player[i].skeleton.free)
if(distance<3.5*sq(player[k].scale*5)&&
if(i==k||!(i==0||k==0))continue;
if(!player[i].skeleton.free){
if(player[k].hasvictim){
- if(findDistancefast(&player[k].coords,&player[i].coords)<
- findDistancefast(&player[k].coords,&player[k].victim->coords))
+ if(distsq(&player[k].coords,&player[i].coords)<
+ distsq(&player[k].coords,&player[k].victim->coords))
player[k].victim=&player[i];
}else{
player[k].victim=&player[i];
player[k].isRun()&&
player[k].wasRun()&&
((player[k].hasvictim&&
- findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
- findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
+ distsq(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
+ distsq(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
!player[k].victim->skeleton.free&&
player[k].victim->targetanimation!=getupfrombackanim&&
player[k].victim->targetanimation!=getupfromfrontanim&&
if(player[i].coords.z>player[k].coords.z-3)
if(player[i].coords.z<player[k].coords.z+3){
//spread fire from player to player
- if(findDistancefast(&player[i].coords,&player[k].coords)
+ if(distsq(&player[i].coords,&player[k].coords)
<3*sq((player[i].scale+player[k].scale)*2.5)){
if(player[i].onfire||player[k].onfire){
if(!player[i].onfire)player[i].CatchFire();
if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
collisionradius=3;
if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
- (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
- findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
+ (distsq(&tempcoords1,&tempcoords2)<collisionradius||
+ distsq(&player[i].coords,&player[k].coords)<collisionradius)){
//jump down on a dead body
if(k==0||i==0){
int l=i?i:k;
player[l].dead&&
player[0].lastcollide<=0&&
fabs(player[l].coords.y-player[0].coords.y)<.2&&
- findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
+ distsq(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
player[0].coords.y=player[l].coords.y;
player[l].velocity=player[0].velocity;
player[l].skeleton.free=0;
animation[player[k].targetanimation].attack==normalattack)){
//If bumped
if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
- if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
+ if(distsq(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
rotatetarget=player[k].coords-player[i].coords;
Normalise(&rotatetarget);
player[k].coords=(player[k].coords+player[i].coords)/2;
player[i].stunned=1;
player[i].pause=0;
- if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
+ if(distsqflat(&player[0].coords,&player[i].coords)<30&&
player[0].coords.y>player[i].coords.y+2&&
!player[0].onterrain)
player[i].pause=1;
closest=-1;
closestdistance=-1;
for(int j=0;j<numpathpoints;j++)
- if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
- closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
+ if(closest==-1||distsq(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
+ closestdistance=distsq(&player[i].finalfinaltarget,&pathpoint[j]);
closest=j;
player[i].finaltarget=pathpoint[j];
}
if(player[i].lastpathfindpoint==-1){
for(int j=0;j<numpathpoints;j++){
if(j!=player[i].lastpathfindpoint)
- if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
- closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
+ if(closest==-1||(distsq(&player[i].coords,&pathpoint[j])<closestdistance)){
+ closestdistance=distsq(&player[i].coords,&pathpoint[j]);
closest=j;
}
}
player[i].lookyaw=player[i].targetyaw;
//reached target point
- if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
+ if(distsqflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
player[i].targetpathfindpoint=-1;
}
- if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
- findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
- findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
+ if( distsqflat(&player[i].coords,&player[i].finalfinaltarget)<
+ distsqflat(&player[i].coords,&player[i].finaltarget)||
+ distsqflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
player[i].lastpathfindpoint==player[i].finalpathfindpoint) {
player[i].aitype=passivetype;
}
if((tutoriallevel!=1||cananger)&&
hostile&&
!player[0].dead&&
- findDistancefast(&player[i].coords,&player[0].coords)<400&&
+ distsq(&player[i].coords,&player[0].coords)<400&&
player[i].occluded<25){
- if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
+ if(distsq(&player[i].coords,&player[0].coords)<12&&
animation[player[0].targetanimation].height!=lowheight&&
!editorenabled&&
(player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
player[i].aitype=attacktypecutoff;
- if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
+ if(distsq(&player[i].coords,&player[0].coords)<30&&
animation[player[0].targetanimation].height==highheight&&
!editorenabled)
player[i].aitype=attacktypecutoff;
for(int j=0;j<numplayers;j++)
if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
- if(findDistancefast(&player[i].coords,&player[j].coords)<400)
+ if(distsq(&player[i].coords,&player[j].coords)<400)
if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
if(!player[j].isWallJump()&&-1==checkcollide(
player[i].lookyaw=player[i].targetyaw;
player[i].aiupdatedelay=.05;
- if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
+ if(distsqflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
if(player[i].waypointtype[player[i].waypoint]==wppause)
player[i].pausetime=4;
player[i].waypoint++;
float leftdist,rightdist;
leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
- leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
- rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
+ leftdist = distsq(&leftpos, &player[i].avoidwhere);
+ rightdist = distsq(&rightpos, &player[i].avoidwhere);
if(leftdist<rightdist)
player[i].targetyaw+=90;
else
if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
for(int j=0;j<numenvsounds;j++){
float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
- if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
+ if(vol>0&&distsq(&player[i].coords,&envsound[j])<
2*(vol+vol*(player[i].creature==rabbittype)*3))
player[i].aitype=attacktypecutoff;
}
if(player[i].howactive<typesleeping&&
((tutoriallevel!=1||cananger)&&hostile)&&
!player[0].dead&&
- findDistancefast(&player[i].coords,&player[0].coords)<400&&
+ distsq(&player[i].coords,&player[0].coords)<400&&
player[i].occluded<25){
- if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
+ if(distsq(&player[i].coords,&player[0].coords)<12&&
animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
player[i].aitype=attacktypecutoff;
- if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
+ if(distsq(&player[i].coords,&player[0].coords)<30&&
animation[player[0].targetanimation].height==highheight&&!editorenabled)
player[i].aitype=attacktypecutoff;
windsmell=windvector;
Normalise(&windsmell);
windsmell=windsmell*2+player[j].coords;
- if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
+ if(distsq(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
player[i].aitype=attacktypecutoff;
}
}
for(int j=0;j<numplayers;j++){
if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
- if(findDistancefast(&player[i].coords,&player[j].coords)<400)
+ if(distsq(&player[i].coords,&player[j].coords)<400)
if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
if((-1==checkcollide(
DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*
player[i].aiupdatedelay=.05;
player[i].forwardkeydown=1;
- if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
+ if(distsqflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
player[i].forwardkeydown=0;
player[i].aiupdatedelay=1;
player[i].lastseen.x+=(float(Random()%100)-50)/25;
float leftdist,rightdist;
leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
- leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
- rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
+ leftdist = distsq(&leftpos, &player[i].avoidwhere);
+ rightdist = distsq(&rightpos, &player[i].avoidwhere);
if(leftdist<rightdist)player[i].targetyaw+=90;
else player[i].targetyaw-=90;
}
if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
for(int k=0;k<numenvsounds;k++){
- if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
+ if(distsq(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
player[i].aitype=attacktypecutoff;
}
}
player[i].occluded<2&&
((tutoriallevel!=1||cananger)&&hostile)){
player[i].losupdatedelay=.2;
- if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
+ if(distsq(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
player[i].aitype=attacktypecutoff;
player[i].lastseentime=1;
}
if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
//TODO: factor out canSeePlayer()
- if(findDistancefast(&player[i].coords,&player[0].coords)<400)
+ if(distsq(&player[i].coords,&player[0].coords)<400)
if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
if((checkcollide(
DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*
player[k].howactive<typedead1&&
!player[k].skeleton.free&&
player[k].aitype==passivetype) {
- float distance=findDistancefast(&player[i].coords,&player[k].coords);
+ float distance=distsq(&player[i].coords,&player[k].coords);
if(closestdist==-1||distance<closestdist) {
closestdist=distance;
closest=k;
player[i].aiupdatedelay=.05;
player[i].forwardkeydown=1;
- if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
+ if(distsqflat(&player[i].coords,&player[player[i].ally].coords)<3){
player[i].aitype=searchtype;
player[i].lastseentime=12;
player[player[i].ally].aitype=searchtype;
float leftdist,rightdist;
leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
- leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
- rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
+ leftdist = distsq(&leftpos, &player[i].avoidwhere);
+ rightdist = distsq(&rightpos, &player[i].avoidwhere);
if(leftdist<rightdist)
player[i].targetyaw+=90;
else
float closestdist=-1;
for(int k=0;k<weapons.size();k++)
if(weapons[k].owner==-1){
- float distance=findDistancefast(&player[i].coords,&weapons[k].position);
+ float distance=distsq(&player[i].coords,&weapons[k].position);
if(closestdist==-1||distance<closestdist){
closestdist=distance;
closest=k;
if(!player[0].dead)
if(player[i].ally>=0){
if(weapons[player[i].ally].owner!=-1||
- findDistancefast(&player[i].coords,&weapons[player[i].ally].position)>16){
+ distsq(&player[i].coords,&weapons[player[i].ally].position)>16){
player[i].aitype=attacktypecutoff;
player[i].lastseentime=1;
}
float leftdist,rightdist;
leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
- leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
- rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
+ leftdist = distsq(&leftpos, &player[i].avoidwhere);
+ rightdist = distsq(&rightpos, &player[i].avoidwhere);
if(leftdist<rightdist)
player[i].targetyaw+=90;
else
!player[0].skeleton.free&&
player[0].targetanimation!=walljumprightkickanim&&
player[0].targetanimation!=walljumpleftkickanim){
- if(findDistancefast(&player[0].coords,&player[i].coords)<25)
+ if(distsq(&player[0].coords,&player[i].coords)<25)
if((1-player[i].damage/player[i].damagetolerance)>.5)
player[i].stunned=1;
}
weapons[i].velocity.x==0&&
weapons[i].velocity.z==0&&
weapons[i].velocity.y==0){
- if(findDistancefast(&player[i].coords,&weapons[k].position)<16) {
+ if(distsq(&player[i].coords,&weapons[k].position)<16) {
player[i].wentforweapon++;
player[i].lastchecktime=6;
player[i].aitype=getweapontype;
//chase player
XYZ rotatetarget=player[0].coords+player[0].velocity;
XYZ targetpoint=player[0].coords;
- if(findDistancefast(&player[0].coords,&player[i].coords)<
- findDistancefast(&rotatetarget,&player[i].coords))
+ if(distsq(&player[0].coords,&player[i].coords)<
+ distsq(&rotatetarget,&player[i].coords))
targetpoint+=player[0].velocity*
findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
player[i].targetyaw=roughDirectionTo(player[i].coords,targetpoint);
player[i].lookyaw=player[i].targetyaw;
player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
- if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
+ if(distsq(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
player[i].forwardkeydown=1;
- else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
- findDistancefast(&player[i].coords,&player[0].coords)<9)&&
+ else if((distsq(&player[i].coords,&player[0].coords)>16||
+ distsq(&player[i].coords,&player[0].coords)<9)&&
player[0].weaponactive!=-1)
player[i].forwardkeydown=1;
else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
player[i].attackkeydown=1;
else
player[i].attackkeydown=0;
- if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
+ if(player[i].isRun()&&Random()%6&&distsq(&player[i].coords,&player[0].coords)>7)
player[i].attackkeydown=0;
//TODO: wat
player[i].weaponactive!=-1||
player[j].targetanimation==staffhitanim||
player[j].targetanimation==staffspinhitanim))
- if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
+ if(distsq(&player[j].coords,&player[j].victim->coords)<4&&
player[j].victim==&player[i]&&
(player[j].targetanimation==sweepanim||
player[j].targetanimation==spinkickanim||
player[j].targetanimation==wolfslapanim||
player[j].targetanimation==knifeslashstartanim||
player[j].targetanimation==swordslashanim&&
- (findDistancefast(&player[j].coords,&player[i].coords)<2||
+ (distsq(&player[j].coords,&player[i].coords)<2||
player[i].weaponactive!=-1))){
if(target>=0)
target=-1;
if(player[i].collided<1)
player[i].jumpkeydown=0;
if(player[i].collided>.8&&player[i].jumppower>=5||
- findDistancefast(&player[i].coords,&player[0].coords)>400&&
+ distsq(&player[i].coords,&player[0].coords)>400&&
player[i].onterrain&&
player[i].creature==rabbittype)
player[i].jumpkeydown=1;
if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
player[0].jumpkeydown=0;
if(player[0].targetanimation==jumpdownanim&&
- findDistancefast(&player[0].coords,&player[i].coords)<40)
+ distsq(&player[0].coords,&player[i].coords)<40)
player[i].crouchkeydown=1;
if(player[i].jumpkeydown)
player[i].attackkeydown=0;
realdialoguetype>0&&
(dialoguegonethrough[i]==0||!special)&&
(special||Input::isKeyPressed(attackkey))){
- if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
+ if(distsq(&player[0].coords,&player[realdialoguetype].coords)<6||
player[realdialoguetype].howactive>=typedead1||
dialoguetype[i]>40&&dialoguetype[i]<50){
whichdialogue=i;
//avoid flaming things
for(int j=0;j<objects.numobjects;j++)
if(objects.onfire[j])
- if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
- if( findDistancefast(&player[i].coords,&objects.position[j])<
- findDistancefast(&player[i].coords,&player[0].coords)){
+ if(distsq(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
+ if( distsq(&player[i].coords,&objects.position[j])<
+ distsq(&player[i].coords,&player[0].coords)){
player[i].collided=0;
player[i].avoidcollided=1;
if(player[i].avoidsomething==0||
- findDistancefast(&player[i].coords,&objects.position[j])<
- findDistancefast(&player[i].coords,&player[i].avoidwhere)){
+ distsq(&player[i].coords,&objects.position[j])<
+ distsq(&player[i].coords,&player[i].avoidwhere)){
player[i].avoidwhere=objects.position[j];
player[i].avoidsomething=1;
}
//avoid flaming players
for(int j=0;j<numplayers;j++)
if(player[j].onfire)
- if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
- if( findDistancefast(&player[i].coords,&player[j].coords)<
- findDistancefast(&player[i].coords,&player[0].coords)){
+ if(distsq(&player[j].coords,&player[i].coords)<sq(0.3)*200)
+ if( distsq(&player[i].coords,&player[j].coords)<
+ distsq(&player[i].coords,&player[0].coords)){
player[i].collided=0;
player[i].avoidcollided=1;
if(player[i].avoidsomething==0||
- findDistancefast(&player[i].coords,&player[j].coords)<
- findDistancefast(&player[i].coords,&player[i].avoidwhere)){
+ distsq(&player[i].coords,&player[j].coords)<
+ distsq(&player[i].coords,&player[i].avoidwhere)){
player[i].avoidwhere=player[j].coords;
player[i].avoidsomething=1;
}
player[i].aitype==playercontrolled)&&
weapons[j].owner==-1&&
player[i].weaponactive==-1)
- if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2){
- if(findDistancefast(&player[i].coords,&weapons[j].position)<2){
+ if(distsqflat(&player[i].coords,&weapons[j].position)<2){
+ if(distsq(&player[i].coords,&weapons[j].position)<2){
if(player[i].isCrouch()||
player[i].targetanimation==sneakanim||
player[i].isRun()||
weapons[j].owner==-1||
player[i].victim&&
weapons[j].owner==player[i].victim->id)
- if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
- if(findDistancefast(&player[i].coords,&weapons[j].position)<1||player[i].victim){
+ if(distsqflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
+ if(distsq(&player[i].coords,&weapons[j].position)<1||player[i].victim){
if(weapons[j].getType()!=staff)
emit_sound_at(knifedrawsound, player[i].coords, 128.);
}else if((player[i].isIdle()||
player[i].isFlip()||
player[i].aitype!=playercontrolled)&&
- findDistancefast(&player[i].coords,&weapons[j].position)<5&&
+ distsq(&player[i].coords,&weapons[j].position)<5&&
player[i].coords.y<weapons[j].position.y){
if(!player[i].isFlip()){
player[i].throwtogglekeydown=1;
weapons[k].owner==-1||
player[i].victim&&
weapons[k].owner==player[i].victim->id)
- if(findDistancefastflat(&player[i].coords,&weapons[k].position)<3&&
+ if(distsqflat(&player[i].coords,&weapons[k].position)<3&&
player[i].weaponactive==-1){
if(weapons[k].getType()!=staff)
emit_sound_at(knifedrawsound, player[i].coords, 128.);
if(j!=i)
if(player[j].num_weapons&&
player[j].skeleton.free&&
- findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
+ distsq(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
(((player[j].skeleton.forward.y<0&&
player[j].weaponstuckwhere==0)||
(player[j].skeleton.forward.y>0&&
if(tutoriallevel!=1||tutorialstage==49)
if(hostile)
if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
- findDistancefast(&player[i].coords,&player[j].coords)<100&&
- findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
+ distsq(&player[i].coords,&player[j].coords)<100&&
+ distsq(&player[i].coords,&player[j].coords)>1.5&&
!player[j].skeleton.free&&
-1==checkcollide(DoRotation(player[j].getJointFor(head).position,0,player[j].yaw,0)*player[j].scale+player[j].coords,DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*player[i].scale+player[i].coords)){
if(!player[i].isFlip()){
if(numplayers>1)
for(int j=0;j<numplayers;j++)
if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
- if(findDistancefast(&player[j].coords,&player[i].coords)<16)
+ if(distsq(&player[j].coords,&player[i].coords)<16)
player[i].superruntoggle=0;
}
if(numplayers>1)
for(int j=0;j<numplayers;j++){
if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
- if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
+ if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
player[j].victim==&player[i]&&
(player[j].targetanimation==sweepanim||
player[j].targetanimation==upunchanim||
player[j].targetanimation==knifeslashstartanim||
player[j].targetanimation==staffhitanim||
player[j].targetanimation==staffspinhitanim)&&
- findDistancefast(&player[j].coords,&player[i].coords)<2))){
+ distsq(&player[j].coords,&player[i].coords)<2))){
if(target>=0)
target=-1;
else
!player[j].skeleton.free&&
player[j].victim&&
player[i].highreversaldelay<=0){
- if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
+ if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
player[j].victim==&player[i]&&
(player[j].targetanimation==spinkickanim)&&
player[i].isCrouch()){
if(numplayers>1)
for(int j=0;j<numplayers;j++){
if(j!=i&&!player[j].skeleton.free&&player[j].victim){
- if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
+ if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
player[j].victim==&player[i]&&
(player[j].targetanimation==sweepanim)){
if(target>=0)target=-1;
oldtemp=temp;
oldtemp2=temp2;
if(tutorialstage>=51)
- if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
+ if(distsq(&temp,&player[0].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[0].coords)<4){
OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
OPENAL_SetFrequency(OPENAL_ALL, 0.001);
flash();
}
if(tutorialstage<51)
- if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
+ if(distsq(&temp,&player[0].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[0].coords)<4){
emit_sound_at(fireendsound, player[0].coords);
player[0].coords=(oldtemp+oldtemp2)/2;
flash();
}
if(tutorialstage>=14&&tutorialstage<50)
- if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
+ if(distsq(&temp,&player[1].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[1].coords)<4){
emit_sound_at(fireendsound, player[1].coords);
for(int i=0;i<player[1].skeleton.num_joints;i++){
winhotspot=false;
for(int i=0;i<numhotspots;i++)
if(hotspottype[i]==-1)
- if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
+ if(distsq(&player[0].coords,&hotspot[i])<hotspotsize[i])
winhotspot=true;
int numalarmed=0;
oldp1=*p1;
*p1=*p1-*move;
if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
- if(findDistancefast(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius)return -1;
+ if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius)return -1;
for(i=0;i<4;i++){
for (j=0;j<TriangleNum;j++){
numpossible=0;
if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
- if(findDistancefast(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;}
+ if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;}
for (j=0;j<TriangleNum;j++){
intersecting=0;
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+ if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+ boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
boundingspherecenter=(vertex[i]+vertex[j])/2;
}
}
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+ if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+ boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
boundingspherecenter=(vertex[i]+vertex[j])/2;
}
}
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+ if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+ boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
boundingspherecenter=(vertex[i]+vertex[j])/2;
}
}
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+ if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+ boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
boundingspherecenter=(vertex[i]+vertex[j])/2;
}
}
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+ if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+ boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
boundingspherecenter=(vertex[i]+vertex[j])/2;
}
}
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+ if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+ boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
boundingspherecenter=(vertex[i]+vertex[j])/2;
}
}
static int i,j;
if(*opacity>0)
- if(findDistancefast(where,&boundingspherecenter)<(boundingsphereradius+*size)*(boundingsphereradius+*size))
+ if(distsq(where,&boundingspherecenter)<(boundingsphereradius+*size)*(boundingsphereradius+*size))
for(i=0;i<TriangleNum;i++){
if(facenormals[i].y<-.1&&(vertex[Triangles[i].vertex[0]].y<where->y||vertex[Triangles[i].vertex[1]].y<where->y||vertex[Triangles[i].vertex[2]].y<where->y)){
decalposition[numdecals]=*where;
static int i,j;
if(opacity>0)
- if(findDistancefast(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size))
+ if(distsq(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size))
for(i=0;i<TriangleNum;i++){
distance=abs(((facenormals[i].x*where.x)+(facenormals[i].y*where.y)+(facenormals[i].z*where.z)-((facenormals[i].x*vertex[Triangles[i].vertex[0]].x)+(facenormals[i].y*vertex[Triangles[i].vertex[0]].y)+(facenormals[i].z*vertex[Triangles[i].vertex[0]].z))));
if(distance<.02&&abs(facenormals[i].y)>abs(facenormals[i].x)&&abs(facenormals[i].y)>abs(facenormals[i].z)){
if(type[i]!=firetype){
moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0);
if(type[i]==tunneltype||frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){
- distance=findDistancefast(&viewer,&position[i]);
+ distance=distsq(&viewer,&position[i]);
distance*=1.2;
- hidden=!(findDistancefastflat(&viewer,&position[i])>playerdist+3||(type[i]!=bushtype&&type[i]!=treeleavestype));
+ hidden=!(distsqflat(&viewer,&position[i])>playerdist+3||(type[i]!=bushtype&&type[i]!=treeleavestype));
if(!hidden){
if(detail==2&&distance>viewdistance*viewdistance/4&&environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness );
if(type[i]==treeleavestype||type[i]==bushtype){
moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0);
if(frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){
- hidden=findDistancefastflat(&viewer,&position[i])<=playerdist+3;
+ hidden=distsqflat(&viewer,&position[i])<=playerdist+3;
if(hidden){
distance=1;
if(distance>0){
&& victim != this
&& currentframe >= 2
&& currentanimation == rabbitkickanim)
- && (findDistancefast(&coords,&victim->coords) < 1.2)
+ && (distsq(&coords,&victim->coords) < 1.2)
&& (!victim->skeleton.free)))
return;
t = dotproduct(&temp,&N)/findLength(&N);
r = 1 - (s + t);*/
- bary.x=findDistancefast(&p0,&p1);
- bary.y=findDistancefast(&p0,&p2);
- bary.z=findDistancefast(&p0,&p3);
+ bary.x=distsq(&p0,&p1);
+ bary.y=distsq(&p0,&p2);
+ bary.z=distsq(&p0,&p3);
total=bary.x+bary.y+bary.z;
bary.x/=total;
victim->currentanimation=upunchreversalanim;
victim->targetanimation=upunchreversalanim;
}
- if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
+ if(targetanimation==staffhitanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
if(victim->weaponactive!=-1){
victim->throwtogglekeydown=1;
weapons[victim->weaponids[0]].owner=-1;
victim->currentanimation=staffhitreversalanim;
victim->targetanimation=staffhitreversalanim;
}
- if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
+ if(targetanimation==staffspinhitanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
if(victim->weaponactive!=-1){
victim->throwtogglekeydown=1;
weapons[victim->weaponids[0]].owner=-1;
victim->currentanimation=staffspinhitreversalanim;
victim->targetanimation=staffspinhitreversalanim;
}
- if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
+ if(targetanimation==swordslashanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
if(victim->weaponactive!=-1){
victim->throwtogglekeydown=1;
weapons[victim->weaponids[0]].owner=-1;
victim->currentanimation=swordslashreversalanim;
victim->targetanimation=swordslashreversalanim;
}
- if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
+ if(targetanimation==knifeslashstartanim&&distsq(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
if(victim->weaponactive!=-1){
victim->throwtogglekeydown=1;
weapons[victim->weaponids[0]].owner=-1;
}
if(hasvictim)
if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
- if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
+ if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||distsq(&coords,&victim->coords)>.2){
victim->targetanimation=dodgebackanim;
victim->targetframe=0;
victim->target=0;
if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
//footpoint.y=coords.y;
- if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
+ 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){
footvel=velocity/5;
if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
- if(findDistancefast(&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(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,yaw);
+ 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)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,yaw);
}
else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
footvel=velocity/5;
if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
- if(findDistancefast(&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);
+ 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(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
- if(findDistancefast(&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(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,yaw);
+ 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)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,yaw);
}
else if(isLanding()||targetanimation==jumpupanim||isLandhard())
{
if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
//footpoint.y=coords.y;
- if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
+ if(distsq(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
}
}
if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
for(i=0;i<weapons.size();i++){
if(weapons[i].owner==-1)
- if(findDistancefastflat(&coords,&weapons[i].position)<4&&weaponactive==-1){
- if(findDistancefast(&coords,&weapons[i].position)>=1){
+ if(distsqflat(&coords,&weapons[i].position)<4&&weaponactive==-1){
+ if(distsq(&coords,&weapons[i].position)>=1){
if(weapons[i].getType()!=staff){
emit_sound_at(knifedrawsound, coords, 128.);
}
if(player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck]==i)
if(player[weapons[i].owner].num_weapons>1)willwork=0;
if((weapons[i].owner==-1)||(hasvictim&&weapons[i].owner==victim->id&&victim->skeleton.free))
- if(willwork&&findDistancefastflat(&coords,&weapons[i].position)<3&&weaponactive==-1){
- if(findDistancefast(&coords,&weapons[i].position)<1||hasvictim){
+ if(willwork&&distsqflat(&coords,&weapons[i].position)<3&&weaponactive==-1){
+ if(distsq(&coords,&weapons[i].position)<1||hasvictim){
bool fleshstuck=false;
if(weapons[i].owner!=-1)
if(victim->weaponstuck!=-1){
dojumpattack=0;
if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
if(hasvictim)
- if(findDistancefast(&victim->coords,&/*player[i].*/coords)<5&&victim->aitype==gethelptype&&(attackkeydown)&&!victim->skeleton.free&&victim->isRun()&&victim->runninghowlong>=1)dojumpattack=1; if(!hostile)dojumpattack=0;
+ if(distsq(&victim->coords,&/*player[i].*/coords)<5&&victim->aitype==gethelptype&&(attackkeydown)&&!victim->skeleton.free&&victim->isRun()&&victim->runninghowlong>=1)dojumpattack=1; if(!hostile)dojumpattack=0;
if(dojumpattack){
if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
targetanimation=rabbittackleanim;
targetloc+=coords;
for(i=0;i<numplayers;i++){
if(i!=id)
- if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
- closestdist=findDistancefast(&targetloc,&player[i].coords);
+ if(distsq(&targetloc,&player[i].coords)<closestdist||closestdist==0){
+ closestdist=distsq(&targetloc,&player[i].coords);
closestid=i;
}
}
//if(onfire)damagemult=3;
if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
escapednum=0;
if(id==0)camerashake+=.4;
if(Random()%2||creature==wolftype){
}
if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
escapednum=0;
if(id==0)camerashake+=.4;
if(Random()%2||creature==wolftype){
}
if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
escapednum=0;
if(id==0)camerashake+=.4;
victim->spurt=1;
}
if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
escapednum=0;
if(id==0)camerashake+=.4;
victim->spurt=1;
}
if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
escapednum=0;
if(id==0)camerashake+=.4;
if(Random()%2){
}
if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
escapednum=0;
if(id==0)camerashake+=.2;
emit_sound_at(whooshhitsound, victim->coords, 128.);
}
if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
escapednum=0;
if(id==0)camerashake+=.4;
if(tutoriallevel!=1){
}
if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
escapednum=0;
if(id==0)camerashake+=.4;
if(tutoriallevel!=1){
}
if(victim&&hasvictim){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
XYZ where,startpoint,endpoint,movepoint,colpoint;
float rotationpoint;
}
hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
if(hasvictim){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
victim->skeleton.longdead=0;
victim->skeleton.free=1;
victim->skeleton.broken=0;
}
if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
escapednum=0;
if(id==0)camerashake+=.4;
if(Random()%2){
if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
escapednum=0;
if(id==0)camerashake+=.4;
if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
}
if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
if(victim->id==0)camerashake+=.4;
emit_sound_at(landsound2, victim->coords);
}
if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
if(victim->id==0)camerashake+=.4;
if(weaponactive!=-1){
if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
if(hasvictim)
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
escapednum=0;
if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
}
}
if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
award_bonus(id, Slashbonus);
escapednum=0;
float bloodlossamount;
bloodlossamount=200+abs((float)(Random()%40))-20;
victim->bloodloss+=bloodlossamount/victim->armorhigh;
- //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
+ //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
victim->DoDamage(damagemult*0);
XYZ footvel,footpoint;
}
if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
if(tutoriallevel!=1){
weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/250;
escapednum=0;
}
if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
if(tutoriallevel!=1){
weapons[weaponids[0]].damage+=.6+float(abs(Random()%100)-50)/250;
escapednum=0;
}
if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
escapednum=0;
if(tutoriallevel!=1){
if(!victim->dead)weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/500;
}
if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
- if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
+ if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
escapednum=0;
if(id==0)camerashake+=.4;
XYZ relative;
}
if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
- if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
+ if(victim->targetanimation!=jumpupanim&&distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
escapednum=0;
if(id==0)camerashake+=.2;
if(tutoriallevel!=1){
if(numplayers>1)
for(i=0;i<numplayers;i++){
if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
- distance=findDistancefast(&player[i].coords,&coords);
+ distance=distsq(&player[i].coords,&coords);
if(closestdist==-1||distance<closestdist){
closestdist=distance;
closest=i;
if(numplayers>1)
for(i=0;i<numplayers;i++){
if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
- distance=findDistancefast(&player[i].coords,&coords);
+ distance=distsq(&player[i].coords,&coords);
if(closestdist==-1||distance<closestdist){
closestdist=distance;
closest=i;
superruntoggle=0;
if(aitype!=passivetype){
superruntoggle=1;
- if(aitype==attacktypecutoff&&(player[0].isIdle()||player[0].isCrouch()||player[0].skeleton.free||player[0].targetanimation==getupfrombackanim||player[0].targetanimation==getupfromfrontanim||player[0].targetanimation==sneakanim)&&findDistancefast(&coords,&player[0].coords)<16){
+ if(aitype==attacktypecutoff&&(player[0].isIdle()||player[0].isCrouch()||player[0].skeleton.free||player[0].targetanimation==getupfrombackanim||player[0].targetanimation==getupfromfrontanim||player[0].targetanimation==sneakanim)&&distsq(&coords,&player[0].coords)<16){
superruntoggle=0;
}
}
}
}
- if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
+ if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&distsq(&viewer,&coords)<9){
texupdatedelay=.12;
bloodsize=5-realtexdetail;
- if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
+ if((id==0||distsq(&coords,&viewer)<50)&&autoslomo){
slomo=1;
slomodelay=.2;
}
if(findLengthfast(&velocity)>.1)
for(i=0;i<objects.numobjects;i++){
if(objects.type[i]==firetype)
- if(findDistancefastflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&findDistancefast(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
+ if(distsqflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&distsq(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
if(onfire){
if(!objects.onfire[i]){
emit_sound_at(firestartsound, objects.position[i]);
}
}
if(objects.type[i]==bushtype)
- if(findDistancefastflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&findDistancefast(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
+ if(distsqflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&distsq(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
if(onfire){
if(!objects.onfire[i]){
emit_sound_at(firestartsound, objects.position[i]);
tempcoord=DoRotation(tempcoord,-objects.pitch[i],0,0);
tempcoord+=objects.position[i];
}
- if(findDistancefastflat(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*8&&findDistancefast(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*300&&tempcoord.y>objects.position[i].y+3*objects.scale[i]){
+ if(distsqflat(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*8&&distsq(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*300&&tempcoord.y>objects.position[i].y+3*objects.scale[i]){
if(objects.messedwith[i]<=0){
XYZ tempvel;
XYZ pos;
midterrain=0;
midterrain.x=terrain.size*terrain.scale/2;
midterrain.z=terrain.size*terrain.scale/2;
- if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
+ if(distsqflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
XYZ tempposit;
tempposit=coords-midterrain;
tempposit.y=0;
int Person::DrawSkeleton(){
int oldplayerdetail;
- if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
+ if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&distsq(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
calcrot=1;
}
if(!isnormal(tilt2))tilt2=0;
oldplayerdetail=playerdetail;
playerdetail=0;
- if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
+ if(distsq(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
playerdetail=1;
}
- if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
+ if(distsq(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
playerdetail=1;
}
- if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
+ if(distsq(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
playerdetail=1;
}
if(id==0)
}
terrainlight=terrain.getLighting(coords.x,coords.z);
- distance=findDistancefast(&viewer,&coords);
+ distance=distsq(&viewer,&coords);
distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
if(distance>1)distance=1;
if(distance>0){
oldp1=*p1;
*p1=*p1-*move;
- if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
+ if(distsq(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
for(i=0;i<4;i++){
for (j=0;j<model->TriangleNum;j++){
inline float findDistance(XYZ *point1, XYZ *point2);
inline float findLength(XYZ *point1);
inline float findLengthfast(XYZ *point1);
-inline float findDistancefast(XYZ *point1, XYZ *point2);
-inline float findDistancefast(XYZ point1, XYZ point2);
-inline float findDistancefastflat(XYZ *point1, XYZ *point2);
+inline float distsq(XYZ *point1, XYZ *point2);
+inline float distsq(XYZ point1, XYZ point2);
+inline float distsqflat(XYZ *point1, XYZ *point2);
inline float dotproduct(const XYZ *point1, const XYZ *point2);
bool sphere_line_intersection (
float x1, float y1 , float z1,
return((point1->x)*(point1->x)+(point1->y)*(point1->y)+(point1->z)*(point1->z));
}
-inline float findDistancefast(XYZ *point1, XYZ *point2){
+inline float distsq(XYZ *point1, XYZ *point2){
return((point1->x-point2->x)*(point1->x-point2->x)+(point1->y-point2->y)*(point1->y-point2->y)+(point1->z-point2->z)*(point1->z-point2->z));
}
-inline float findDistancefast(XYZ point1, XYZ point2){
+inline float distsq(XYZ point1, XYZ point2){
return((point1.x-point2.x)*(point1.x-point2.x)+(point1.y-point2.y)*(point1.y-point2.y)+(point1.z-point2.z)*(point1.z-point2.z));
}
-inline float findDistancefastflat(XYZ *point1, XYZ *point2){
+inline float distsqflat(XYZ *point1, XYZ *point2){
return((point1->x-point2->x)*(point1->x-point2->x)+(point1->z-point2->z)*(point1->z-point2->z));
}
}
}
if(sprites[i]->type==snowsprite)
- distancemult=(144-(findDistancefast(&tempviewer,&sprites[i]->position)-(144*fadestart))*(1/(1-fadestart)))/144;
+ distancemult=(144-(distsq(&tempviewer,&sprites[i]->position)-(144*fadestart))*(1/(1-fadestart)))/144;
else
- distancemult=(viewdistsquared-(findDistancefast(&viewer,&sprites[i]->position)-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
+ distancemult=(viewdistsquared-(distsq(&viewer,&sprites[i]->position)-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
if(sprites[i]->type==flamesprite){
if(distancemult>=1) glColor4f(sprites[i]->color[0],sprites[i]->color[1],sprites[i]->color[2],sprites[i]->opacity);
else glColor4f(sprites[i]->color[0],sprites[i]->color[1],sprites[i]->color[2],sprites[i]->opacity*distancemult);
triangles[2].z=j;
intersecting=LineFacet(p1,p2,triangles[0],triangles[1],triangles[2],&point);
- distance=findDistancefast(&p1,&point);
+ distance=distsq(&p1,&point);
if((distance<olddistance||firstintersecting==-1)&&intersecting==1){olddistance=distance; firstintersecting=1; *p=point;}
triangles[0].x=i+1;
triangles[2].z=j+1;
intersecting=LineFacet(p1,p2,triangles[0],triangles[1],triangles[2],&point);
- distance=findDistancefast(&p1,&point);
+ distance=distsq(&p1,&point);
if((distance<olddistance||firstintersecting==-1)&&intersecting==1){olddistance=distance; firstintersecting=1; *p=point;}
}
}
vertex.x=i*scale;
vertex.z=j*scale;
vertex.y=heightmap[i][j]*scale;
- distance=findDistancefast(&viewer,&vertex);
+ distance=distsq(&viewer,&vertex);
if(distance>viewdistsquared)distance=viewdistsquared;
colors[i][j][3]=(viewdistsquared-(distance-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
}
vertex.x=i*scale;
vertex.z=j*scale;
vertex.y=heightmap[i][j]*scale;
- distance=findDistancefast(&viewer,&vertex);
+ distance=distsq(&viewer,&vertex);
if(distance>viewdistsquared)distance=viewdistsquared;
colors[i][j][3]=(viewdistsquared-(distance-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
}
terrainpoint.x=i*patch_size+(patch_size)/2;
terrainpoint.y=viewer.y;//heightmap[i][j]*scale;
terrainpoint.z=j*patch_size+(patch_size)/2;
- distance[i][j]=findDistancefast(&viewer,&terrainpoint);
+ distance[i][j]=distsq(&viewer,&terrainpoint);
}
}
}
}
}
if(decaltype[i]==shadowdecal||decaltype[i]==shadowdecalpermanent){
- distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
+ distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
if(distancemult>=1)glColor4f(1,1,1,decalopacity[i]);
if(distancemult<1)glColor4f(1,1,1,decalopacity[i]*distancemult);
}
if(decaltype[i]==footprintdecal||decaltype[i]==bodyprintdecal){
- distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
+ distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
if(distancemult>=1){
glColor4f(1,1,1,decalopacity[i]);
if(decalalivetime[i]>3)glColor4f(1,1,1,decalopacity[i]*(5-decalalivetime[i])/2);
}
}
if((decaltype[i]==blooddecal||decaltype[i]==blooddecalfast||decaltype[i]==blooddecalslow)){
- distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
+ distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
if(distancemult>=1){
glColor4f(decalbrightness[i],decalbrightness[i],decalbrightness[i],decalopacity[i]);
if(decalalivetime[i]<4)glColor4f(decalbrightness[i],decalbrightness[i],decalbrightness[i],decalopacity[i]*decalalivetime[i]*.25);
for(int j=0;j<numplayers;j++) {
footvel=0;
footpoint=DoRotation((player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].position+player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].position)/2,0,player[j].yaw,0)*player[j].scale+player[j].coords;
- if(owner==-1 && findDistancefastflat(&position,&player[j].coords)<1.5 &&
- findDistancefast(&position,&player[j].coords)<4 && player[j].weaponstuck==-1 &&
+ if(owner==-1 && distsqflat(&position,&player[j].coords)<1.5 &&
+ distsq(&position,&player[j].coords)<4 && player[j].weaponstuck==-1 &&
!player[j].skeleton.free && j!=oldowner) {
if((player[j].aitype!=attacktypecutoff||abs(Random()%6)==0||(player[j].targetanimation!=backhandspringanim&&player[j].targetanimation!=rollanim&&player[j].targetanimation!=flipanim&&Random()%2==0))&&!missed) {
if( (player[j].creature==wolftype && Random()%3!=0 && player[j].weaponactive==-1 && (player[j].isIdle()||player[j].isRun()||player[j].targetanimation==walkanim))||
XYZ terrainlight;
terrainlight=terrain.getLighting(position.x,position.z);
if(environment==snowyenvironment){
- if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
}
else if(environment==grassyenvironment){
- if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
}
else if(environment==desertenvironment){
- if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
}
XYZ terrainlight;
terrainlight=terrain.getLighting(position.x,position.z);
if(environment==snowyenvironment){
- if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
}
else if(environment==grassyenvironment){
- if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
}
else if(environment==desertenvironment){
- if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
}
}
XYZ terrainlight;
terrainlight=terrain.getLighting(tippoint.x,tippoint.z);
if(environment==snowyenvironment){
- if(findDistancefast(&tippoint,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
}
else if(environment==grassyenvironment){
- if(findDistancefast(&tippoint,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
}
else if(environment==desertenvironment){
- if(findDistancefast(&tippoint,&viewer)<viewdistance*viewdistance/4)
+ if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
}
}
flamedelay=.020;
flamedelay-=multiplier;
normalrot=0;
- if(Random()%50==0&&findDistancefast(&position,&viewer)>80) {
+ if(Random()%50==0&&distsq(&position,&viewer)>80) {
XYZ shinepoint;
shinepoint=position+(tippoint-position)*(((float)abs(Random()%100))/100);
Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
static GLfloat M[16];
if((frustum.SphereInFrustum(position.x,position.y,position.z,1)&&
- findDistancefast(&viewer,&position)<viewdistance*viewdistance))
+ distsq(&viewer,&position)<viewdistance*viewdistance))
{
bool draw=false;
if(owner==-1)
drawhowmany=1;
} else {
if(player[owner].occluded<25)
- if((frustum.SphereInFrustum(player[owner].coords.x,player[owner].coords.y+player[owner].scale*3,player[owner].coords.z,player[owner].scale*8)&&findDistancefast(&viewer,&player[owner].coords)<viewdistance*viewdistance)||player[owner].skeleton.free==3)
+ if((frustum.SphereInFrustum(player[owner].coords.x,player[owner].coords.y+player[owner].scale*3,player[owner].coords.z,player[owner].scale*8)&&distsq(&viewer,&player[owner].coords)<viewdistance*viewdistance)||player[owner].skeleton.free==3)
draw=true;
if (
(player[owner].targetanimation==knifeslashstartanim||