//========================================= // What is nodenum of this origin, if any? //========================================= int GetNodeNum(vec3_t origin) { vec3_t vtmp; float dist; //float best=99999, bestd=99999, d;//GHz int i; //gi.dprintf("GetNodeNum() is checking %d nodes\n", numnodes); // Search all of my node[i]'s for (i=0;i < numnodes;i++) { VectorSubtract(pathnode[i],origin,vtmp); dist=VectorLengthSqr(vtmp); //if (dist < best)//GHz: added for debugging only // best = dist; //d=distance(node[i].origin, origin); //if (d < bestd) // bestd=d; if (dist < 1.0F)//FIXME: wtf does this mean? return i; } //gi.dprintf("best result=%f, need=%f, actual=%f\n", best, 1.0F, bestd); return -1; }
/** * @brief Applies morale changes to actors who find themselves in the general direction of a shot. * @param shooter The shooting actor. * @param fd The firedef used to shoot. * @param from The weapon's muzzle location. * @param weapon The weapon used to shoot. * @param impact The shoot's impact location. */ static void G_ShotMorale (const Actor* shooter, const fireDef_t* fd, const vec3_t from, const Item* weapon, const vec3_t impact) { /* Skip not detectable shoots */ if (weapon->def()->dmgtype == gi.csi->damLaser || fd->irgoggles) return; Actor* check = nullptr; const float minDist = UNIT_SIZE * 1.5f; while ((check = G_EdictsGetNextLivingActor(check))) { /* Skip yourself */ if (check == shooter) continue; pos3_t target; VecToPos(impact, target); /* Skip the hit actor -- morale was already handled */ if (check->isSamePosAs(target)) continue; vec3_t dir1, dir2; VectorSubtract(check->origin, from, dir1); VectorSubtract(impact, from, dir2); const float len1 = VectorLength(dir1); const float len2 = VectorLength(dir2); const float dot = DotProduct(dir1, dir2); if (dot / (len1 * len2) < 0.7f) continue; /* Skip if shooting next or over an ally */ if (check->isSameTeamAs(shooter) && VectorDistSqr(check->origin, shooter->origin) <= minDist * minDist) continue; vec3_t vec1; if (len1 > len2) { VectorSubtract(dir2, dir1, vec1); } else { VectorScale(dir2, dot / (len2 * len2), vec1); VectorSubtract(dir1, vec1, vec1); } const float morDist = (check->isSamePosAs(target) ? UNIT_SIZE * 0.5f : minDist); if (VectorLengthSqr(vec1) <= morDist * morDist) { /* @todo Add a visibility check here? */ G_Morale(ML_SHOOT, check, shooter, fd->damage[0]); } } }