- if (terrain.patchobjectnum[whichpatchx][whichpatchz]) { // if there are Object::objects where the weapon is
- for (int j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) { // check for collision
- int k = terrain.patchobjects[whichpatchx][whichpatchz][j];
- start = oldtippoint;
- end = tippoint;
- whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
- if (whichhit != -1) {
- if (Object::objects[k]->type == treetrunktype) {
- Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .1, 1, Random() % 360);
- normalrot = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0);
- velocity = 0;
- if (type == knife)
- position = colpoint - normalrot * .1;
- else if (type == sword)
- position = colpoint - normalrot * .2;
- else if (type == staff)
- position = colpoint - normalrot * .2;
- XYZ temppoint1, temppoint2;
- 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;
- }
+ for (unsigned int j = 0; j < terrain.patchobjects[whichpatchx][whichpatchz].size(); j++) { // check for collision
+ unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][j];
+ start = oldtippoint;
+ end = tippoint;
+ whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
+ if (whichhit != -1) {
+ if (Object::objects[k]->type == treetrunktype) {
+ Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .1, 1, Random() % 360);
+ normalrot = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0);
+ velocity = 0;
+ if (type == knife)
+ position = colpoint - normalrot * .1;
+ else if (type == sword)
+ position = colpoint - normalrot * .2;
+ else if (type == staff)
+ position = colpoint - normalrot * .2;
+ XYZ temppoint1, temppoint2;
+ 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;