- oldposition[i]=position[i];
- oldtippoint[i]=tippoint[i];
- if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
- position[i]+=velocity[i]*multiplier;
- tippoint[i]+=velocity[i]*multiplier;
- whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale);
- whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale);
- if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
- if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
- for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
- k=terrain.patchobjects[whichpatchx][whichpatchz][j];
- start=oldtippoint[i];
- end=tippoint[i];
- whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
- if(whichhit!=-1){
- if(objects.type[k]==treetrunktype){
- objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
- normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
- velocity[i]=0;
- if(type[i]==knife)position[i]=colpoint-normalrot*.1;
- if(type[i]==sword)position[i]=colpoint-normalrot*.2;
- if(type[i]==staff)position[i]=colpoint-normalrot*.2;
- XYZ temppoint1,temppoint2,tempforward;
- float distance;
-
- temppoint1=0;
- temppoint2=normalrot;
- distance=findDistance(&temppoint1,&temppoint2);
- rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
- rotation2[i]*=360/6.28;
- temppoint1.y=0;
- temppoint2.y=0;
- rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
- rotation1[i]*=360/6.28;
- if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
-
- rotation3[i]=0;
- smallrotation[i]=90;
- smallrotation2[i]=0;
- bigtilt[i]=0;
- bigtilt2[i]=0;
- bigrotation[i]=0;
-
- emit_sound_at(knifesheathesound, position[i], 128.);
-
- bloody[i]=0;
-
- Sprite::MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
- }
- else {
- physics[i]=1;
- firstfree[i]=1;
- position[i]-=velocity[i]*multiplier;
- tippoint[i]-=velocity[i]*multiplier;
- tipvelocity[i]=velocity[i];
- }
+ }
+ oldposition=position;
+ oldtippoint=tippoint;
+ if(owner==-1&&(velocity.x||velocity.y||velocity.z)&&!physics){
+ position+=velocity*multiplier;
+ tippoint+=velocity*multiplier;
+ whichpatchx=position.x/(terrain.size/subdivision*terrain.scale);
+ whichpatchz=position.z/(terrain.size/subdivision*terrain.scale);
+ if(whichpatchx>0 && whichpatchz>0 && whichpatchx<subdivision && whichpatchz<subdivision)
+ if(terrain.patchobjectnum[whichpatchx][whichpatchz]) {
+ for(int j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
+ int k=terrain.patchobjects[whichpatchx][whichpatchz][j];
+ start=oldtippoint;
+ end=tippoint;
+ whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
+ if(whichhit!=-1){
+ if(objects.type[k]==treetrunktype){
+ objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
+ normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
+ velocity=0;
+ if(type==knife)position=colpoint-normalrot*.1;
+ if(type==sword)position=colpoint-normalrot*.2;
+ if(type==staff)position=colpoint-normalrot*.2;
+ XYZ temppoint1,temppoint2,tempforward;
+ float distance;
+
+ temppoint1=0;
+ temppoint2=normalrot;
+ distance=findDistance(&temppoint1,&temppoint2);
+ rotation2=asin((temppoint1.y-temppoint2.y)/distance);
+ rotation2*=360/6.28;
+ temppoint1.y=0;
+ temppoint2.y=0;
+ rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
+ rotation1*=360/6.28;
+ if(temppoint1.x>temppoint2.x)rotation1=360-rotation1;
+
+ rotation3=0;
+ smallrotation=90;
+ smallrotation2=0;
+ bigtilt=0;
+ bigtilt2=0;
+ bigrotation=0;
+
+ emit_sound_at(knifesheathesound, position, 128.);
+
+ bloody=0;
+
+ Sprite::MakeSprite(cloudimpactsprite, position,velocity, 1,1,1, .8, .3);
+ }
+ else {
+ physics=1;
+ firstfree=1;
+ position-=velocity*multiplier;
+ tippoint-=velocity*multiplier;
+ tipvelocity=velocity;