MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / AdjacentCost

Method AdjacentCost

Source/Map/Random.cpp:395–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395void cRandomMap::AdjacentCost(cPosition* node, std::vector< micropather::StateCost > *neighbors) {
396 const int dx[8] = { 8, 8, 0, -8, -8, -8, 0, 8 };
397 const int dy[8] = { 0, 8, 8, 8, 0, -8, -8, -8 };
398 const float cost[8] = { 1.0f, 1.41f, 1.0f, 1.41f, 1.0f, 1.41f, 1.0f, 1.41f };
399
400 for (int i = 0; i < 8; ++i) {
401 int nx = node->mX + dx[i];
402 int ny = node->mY + dy[i];
403
404 if (nx < 0 || ny < 0)
405 continue;
406
407 int pass = Passable(nx, ny);
408 if (pass > 0) {
409 if (pass == 1)
410 {
411 // Normal floor
412 micropather::StateCost nodeCost = { cPosition(nx, ny), cost[i] };
413 neighbors->push_back(nodeCost);
414 }
415 else
416 {
417 // Normal floor
418 micropather::StateCost nodeCost = { cPosition(nx, ny), cost[i] + pass };
419 neighbors->push_back(nodeCost);
420 }
421 }
422 }
423}
424
425void cRandomMap::PrintStateInfo(cPosition* node) {
426 printf("(%d,%d)", node->mX, node->mY);

Callers 1

GetNodeNeighborsMethod · 0.80

Calls 2

cPositionClass · 0.50
push_backMethod · 0.45

Tested by

no test coverage detected