Skip to content

Commit

Permalink
refactor Monsters.c functions to take 'pos' as argument (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-Fenner authored Aug 15, 2023
1 parent 92ccf24 commit 49e60aa
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 137 deletions.
17 changes: 8 additions & 9 deletions src/brogue/Architect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1566,8 +1566,7 @@ boolean buildAMachine(enum machineTypes bp,

if (feature->flags & MF_GENERATE_HORDE) {
monst = spawnHorde(0,
featX,
featY,
(pos){ featX, featY },
((HORDE_IS_SUMMONED | HORDE_LEADER_CAPTIVE) & ~(feature->hordeFlags)),
feature->hordeFlags);
if (monst) {
Expand Down Expand Up @@ -3308,7 +3307,7 @@ void evacuateCreatures(char blockingMap[DCOLS][DROWS]) {
monst = monsterAtLoc((pos) { i, j });
pos newLoc;
getQualifyingLocNear(&newLoc,
i, j,
(pos){ i, j },
true,
blockingMap,
forbiddenFlagsForMonster(&(monst->info)),
Expand All @@ -3331,7 +3330,7 @@ boolean spawnDungeonFeature(short x, short y, dungeonFeature *feat, boolean refr
boolean succeeded;

if ((feat->flags & DFF_RESURRECT_ALLY)
&& !resurrectAlly(x, y)) {
&& !resurrectAlly((pos){ x, y })) {
return false;
}

Expand Down Expand Up @@ -3536,7 +3535,7 @@ void restoreItem(item *theItem) {

pos loc;
// Items can fall into deep water, enclaved lakes, another chasm, even lava!
getQualifyingLocNear(&loc, theItem->loc.x, theItem->loc.y, true, 0,
getQualifyingLocNear(&loc, theItem->loc, true, 0,
(T_OBSTRUCTS_ITEMS),
(HAS_MONSTER | HAS_ITEM | HAS_STAIRS), false, false);

Expand Down Expand Up @@ -3659,10 +3658,10 @@ void initializeLevel() {
}

pos downLoc;
if (getQualifyingGridLocNear(&downLoc, levels[n].downStairsLoc.x, levels[n].downStairsLoc.y, grid, false)) {
if (getQualifyingGridLocNear(&downLoc, levels[n].downStairsLoc, grid, false)) {
prepareForStairs(downLoc.x, downLoc.y, grid);
} else {
getQualifyingLocNear(&downLoc, levels[n].downStairsLoc.x, levels[n].downStairsLoc.y, false, 0,
getQualifyingLocNear(&downLoc, levels[n].downStairsLoc, false, 0,
(T_OBSTRUCTS_PASSABILITY | T_OBSTRUCTS_ITEMS | T_AUTO_DESCENT | T_IS_DEEP_WATER | T_LAVA_INSTA_DEATH | T_IS_DF_TRAP),
(HAS_MONSTER | HAS_ITEM | HAS_STAIRS | IS_IN_MACHINE), true, false);
}
Expand All @@ -3681,10 +3680,10 @@ void initializeLevel() {
levels[n].downStairsLoc = downLoc;

pos upLoc;
if (getQualifyingGridLocNear(&upLoc, levels[n].upStairsLoc.x, levels[n].upStairsLoc.y, grid, false)) {
if (getQualifyingGridLocNear(&upLoc, levels[n].upStairsLoc, grid, false)) {
prepareForStairs(upLoc.x, upLoc.y, grid);
} else { // Hopefully this never happens.
getQualifyingLocNear(&upLoc, levels[n].upStairsLoc.x, levels[n].upStairsLoc.y, false, 0,
getQualifyingLocNear(&upLoc, levels[n].upStairsLoc, false, 0,
(T_OBSTRUCTS_PASSABILITY | T_OBSTRUCTS_ITEMS | T_AUTO_DESCENT | T_IS_DEEP_WATER | T_LAVA_INSTA_DEATH | T_IS_DF_TRAP),
(HAS_MONSTER | HAS_ITEM | HAS_STAIRS | IS_IN_MACHINE), true, false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/brogue/Combat.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ void processStaggerHit(creature *attacker, creature *defender) {
&& !cellHasTerrainFlag(newX, newY, T_OBSTRUCTS_PASSABILITY)
&& !(pmap[newX][newY].flags & (HAS_MONSTER | HAS_PLAYER))) {

setMonsterLocation(defender, newX, newY);
setMonsterLocation(defender, (pos){ newX, newY });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/brogue/Dijkstra.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void calculateDistances(short **distanceMap,
} else if (canUseSecretDoors
&& cellHasTMFlag(i, j, TM_IS_SECRET)
&& cellHasTerrainFlag(i, j, T_OBSTRUCTS_PASSABILITY)
&& !(discoveredTerrainFlagsAtLoc(i, j) & T_OBSTRUCTS_PASSABILITY)) {
&& !(discoveredTerrainFlagsAtLoc((pos){ i, j }) & T_OBSTRUCTS_PASSABILITY)) {

cost = 1;
} else if (cellHasTerrainFlag(i, j, T_OBSTRUCTS_PASSABILITY)
Expand Down
2 changes: 1 addition & 1 deletion src/brogue/Grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ boolean getQualifyingPathLocNear(short *retValX, short *retValY,
// Fall back to a pathing-agnostic alternative if there are no solutions.
if (*retValX == -1 && *retValY == -1) {
pos loc;
if (getQualifyingLocNear(&loc, x, y, hallwaysAllowed, NULL,
if (getQualifyingLocNear(&loc, (pos){ x, y }, hallwaysAllowed, NULL,
(blockingTerrainFlags | forbiddenTerrainFlags),
(blockingMapFlags | forbiddenMapFlags),
false, deterministic)) {
Expand Down
14 changes: 7 additions & 7 deletions src/brogue/Items.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void fillItemSpawnHeatMap(unsigned short heatMap[DCOLS][DROWS], unsigned short h
pos neighbor = posNeighborInDirection(loc, dir);
if (isPosInMap(neighbor)
&& !cellHasTerrainFlag(neighbor.x, neighbor.y, T_IS_DEEP_WATER | T_LAVA_INSTA_DEATH | T_AUTO_DESCENT)
&& isPassableOrSecretDoor(neighbor.x, neighbor.y)
&& isPassableOrSecretDoor(neighbor)
&& heatLevel < heatMap[neighbor.x][neighbor.y]) {

fillItemSpawnHeatMap(heatMap, heatLevel, neighbor);
Expand Down Expand Up @@ -1182,7 +1182,7 @@ void updateFloorItems() {
}
if (cellHasTerrainFlag(x, y, T_MOVES_ITEMS)) {
pos loc;
getQualifyingLocNear(&loc, x, y, true, 0, (T_OBSTRUCTS_ITEMS | T_OBSTRUCTS_PASSABILITY), (HAS_ITEM), false, false);
getQualifyingLocNear(&loc, (pos){ x, y }, true, 0, (T_OBSTRUCTS_ITEMS | T_OBSTRUCTS_PASSABILITY), (HAS_ITEM), false, false);
removeItemAt((pos){ x, y });
pmapAt(loc)->flags |= HAS_ITEM;
if (pmap[x][y].flags & ITEM_DETECTED) {
Expand Down Expand Up @@ -4408,7 +4408,7 @@ boolean updateBolt(bolt *theBolt, creature *caster, short x, short y,
if (monst->bookkeepingFlags & MB_CAPTIVE) {
freeCaptive(monst);
}
teleport(monst, -1, -1, false);
teleport(monst, INVALID_POS, false);
}
break;
case BE_BECKONING:
Expand Down Expand Up @@ -6110,7 +6110,7 @@ void throwItem(item *theItem, creature *thrower, pos targetLoc, short maxDistanc
return;
}
pos dropLoc;
getQualifyingLocNear(&dropLoc, x, y, true, 0, (T_OBSTRUCTS_ITEMS | T_OBSTRUCTS_PASSABILITY), (HAS_ITEM), false, false);
getQualifyingLocNear(&dropLoc, (pos){ x, y }, true, 0, (T_OBSTRUCTS_ITEMS | T_OBSTRUCTS_PASSABILITY), (HAS_ITEM), false, false);
placeItemAt(theItem, dropLoc);
refreshDungeonCell(dropLoc.x, dropLoc.y);
}
Expand Down Expand Up @@ -6570,7 +6570,7 @@ void useCharm(item *theItem) {
summonGuardian(theItem);
break;
case CHARM_TELEPORTATION:
teleport(&player, -1, -1, true);
teleport(&player, INVALID_POS, true);
break;
case CHARM_RECHARGING:
rechargeItems(STAFF);
Expand Down Expand Up @@ -6872,7 +6872,7 @@ void readScroll(item *theItem) {
messageWithColor(buf2, &itemMessageColor, 0);
break;
case SCROLL_TELEPORT:
teleport(&player, -1, -1, true);
teleport(&player, INVALID_POS, true);
break;
case SCROLL_REMOVE_CURSE:
for (tempItem = packItems->nextItem; tempItem != NULL; tempItem = tempItem->nextItem) {
Expand Down Expand Up @@ -7050,7 +7050,7 @@ void readScroll(item *theItem) {
y = player.loc.y + nbDirs[i][1];
if (!cellHasTerrainFlag(x, y, T_OBSTRUCTS_PASSABILITY) && !(pmap[x][y].flags & HAS_MONSTER)
&& rand_percent(10) && (numberOfMonsters < 3)) {
monst = spawnHorde(0, x, y, (HORDE_LEADER_CAPTIVE | HORDE_NO_PERIODIC_SPAWN | HORDE_IS_SUMMONED | HORDE_MACHINE_ONLY), 0);
monst = spawnHorde(0, (pos){ x, y }, (HORDE_LEADER_CAPTIVE | HORDE_NO_PERIODIC_SPAWN | HORDE_IS_SUMMONED | HORDE_MACHINE_ONLY), 0);
if (monst) {
// refreshDungeonCell(x, y);
// monst->creatureState = MONSTER_TRACKING_SCENT;
Expand Down
Loading

0 comments on commit 49e60aa

Please sign in to comment.