MCPcopy Create free account
hub / github.com/TurningWheel/Barony / buildGraph

Method buildGraph

src/paths.cpp:1317–1414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1315
1316
1317void GateGraph::buildGraph(const int parentMapType)
1318{
1319 mapSubzones = (int*)calloc(map.width * map.height, sizeof(int));
1320
1321 int* parentMap = nullptr;
1322 this->parentMapType = parentMapType;
1323 if ( parentMapType == GateGraph::GATE_GRAPH_GROUNDED )
1324 {
1325 parentMap = pathMapGrounded;
1326 }
1327 else if ( parentMapType == GateGraph::GATE_GRAPH_FLYING )
1328 {
1329 parentMap = pathMapFlying;
1330 }
1331 else
1332 {
1333 printlog("[Gate Graph]: No matching type found: %d", parentMapType);
1334 return;
1335 }
1336
1337 if ( !parentMap )
1338 {
1339 printlog("[Gate Graph]: Parent map was NULL: %d", parentMapType);
1340 return;
1341 }
1342
1343 bIsInit = true;
1344 numSubzones = 1;
1345 for ( int y = 0; y < map.height; y++ )
1346 {
1347 for ( int x = 0; x < map.width; x++ )
1348 {
1349 int zone = parentMap[y + x * map.height];
1350 if ( zone > 0 && !mapSubzones[y + x * map.height] )
1351 {
1352 fillPathMap(x, y);
1353 }
1354 }
1355 }
1356
1357 for ( node_t* entityNode = map.entities->first; entityNode != nullptr; entityNode = entityNode->next )
1358 {
1359 Entity* entity = (Entity*)entityNode->element;
1360 if ( entity->behavior == &actGate )
1361 {
1362 int ix = ((int)entity->x >> 4);
1363 int iy = ((int)entity->y >> 4);
1364 real_t angle = normaliseAngle2PI(entity->yaw);
1365 if ( limbAngleWithinRange(angle, .05, PI / 2) || limbAngleWithinRange(angle, .05, 3 * PI / 2) )
1366 {
1367 int zone1 = mapSubzones[(iy - 1) + ix * map.height];
1368 int zone2 = mapSubzones[(iy + 1) + ix * map.height];
1369 int& middleZone = mapSubzones[iy + ix * map.height];
1370 middleZone = zone1 + (zone2 * 10000);
1371 addGate(ix, iy, zone1, zone2, entity->getUID(), DIR_NORTHSOUTH);
1372 /*printlog("N/S Gate: %d, %d: subzones: %d | %d (i am %d)",
1373 ix, iy, zone1, zone2, middleZone);*/
1374 }

Callers 1

generatePathMapsFunction · 0.80

Calls 6

printlogFunction · 0.85
fillPathMapFunction · 0.85
normaliseAngle2PIFunction · 0.85
limbAngleWithinRangeFunction · 0.85
getUIDMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected