2023-04-08 16:09:56 +00:00
|
|
|
#include "utils.h"
|
2023-04-08 17:23:26 +00:00
|
|
|
#include <cstdlib>
|
2023-04-08 16:09:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
int Utils_CrapDist(const CVector& a,const CVector& b){
|
|
|
|
|
|
|
|
|
|
|
|
int dX = a.vx - b.vx;
|
|
|
|
int dY = a.vy - b.vy;
|
|
|
|
int dZ = a.vz - b.vz;
|
|
|
|
|
|
|
|
if (dX < 0) {
|
|
|
|
dX = -dX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dY < 0) {
|
|
|
|
dY = -dY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dZ < 0) {
|
|
|
|
dZ = -dZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dX < dY){
|
|
|
|
|
|
|
|
if (dY < dZ){
|
|
|
|
return (dZ + (dX >>2) + (dY >>1)) >> 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dZ < dY){
|
|
|
|
return ((dZ >> 2) + (dX >> 1) + dY) >> 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((dZ >> 1) + (dX >> 2) + dY) >> 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dX < dZ){
|
|
|
|
return (dZ + (dX >>1) + (dY >>2)) >> 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dZ < dY){
|
|
|
|
return ((dZ >> 2) + dX + (dY >>1)) >> 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((dZ >> 1) + dX + (dY >>2)) >> 12;
|
|
|
|
}
|
2023-04-08 16:21:19 +00:00
|
|
|
|
|
|
|
int Utils_CrapXZDist(const CVector& a,const CVector& b) {
|
|
|
|
CVector tmp = a;
|
|
|
|
tmp.vy = b.vy;
|
|
|
|
return Utils_CrapDist(tmp, b);
|
|
|
|
}
|
2023-04-08 17:23:26 +00:00
|
|
|
|
|
|
|
int Utils_CompareStrings(const char* left, const char* right) {
|
|
|
|
|
2023-04-11 17:12:46 +00:00
|
|
|
if (left == NULL && right == NULL){
|
2023-04-08 17:23:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-04-11 17:12:46 +00:00
|
|
|
if (left == NULL || right == NULL){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-08 17:23:26 +00:00
|
|
|
|
|
|
|
if (right != NULL){
|
|
|
|
|
|
|
|
char currLeft = *left;
|
|
|
|
char currRight = *right;
|
|
|
|
if (currLeft >= 'A' && currLeft <= 'Z'){
|
|
|
|
currLeft += ' ';
|
|
|
|
}
|
|
|
|
if (currRight >= 'A' && currRight <= 'Z'){
|
|
|
|
currRight += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currLeft == currRight){
|
|
|
|
|
|
|
|
if (currLeft != 0 && currRight != 0) {
|
|
|
|
currLeft = *++left;
|
|
|
|
currRight = *++right;
|
|
|
|
|
|
|
|
if (currLeft >= 'A' && currLeft <= 'Z'){
|
|
|
|
currLeft += ' ';
|
|
|
|
}
|
|
|
|
if (currRight >= 'A' && currRight <= 'Z'){
|
|
|
|
currRight += ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currLeft == 0 && currRight == 0){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|