// Checks if a robot is going to collide it is positionned at robotPosition. // robotPosition : Predicted position of the robot. // robotIndex : Index of the current robot in the robot array. // Returns 1 if there will be a collision, 0 otherwise. int checkCollision(double robotPosition[3], int robotIndex) { int i=0; int collision = 0; Object** bender = getBender(robotPosition); // Bounding shapes of the robot. One as a box, the other as a cylinder. // Each will be used for collisions with an object of the same type. Object** otherBender; // Represents the bounding shapes of other robots. Object* building; // Represents the bounding shape of the buildings. // Check if it collides with the other robots. for(i = 0; i<NBROBOTS && collision == 0; i++) { if (i != robotIndex) { otherBender = getBender(robot[i].position); if (inCollision(bender[TYPE_CYLINDER], otherBender[TYPE_CYLINDER])) collision = 1; free(otherBender[0]); free(otherBender[1]); free(otherBender); } } // Check if it collides with buildings. for(i = 0; i<NBBUILDINGS && collision == 0; i++) { building = getBuilding(buildingPosition[i], buildingType[i]); if (inCollision(bender[building->type], building)) collision = 1; free(building); } free(bender[0]); free(bender[1]); free(bender); return collision; }
df::building *DFHack::findBuildingRef(std::vector<df::general_ref*> &vec, df::general_ref_type type) { auto ref = findRef(vec, type); return ref ? ref->getBuilding() : NULL; }