MCPcopy Create free account
hub / github.com/SimHacker/micropolis / buildHouse

Method buildHouse

MicropolisCore/src/MicropolisEngine/src/zone.cpp:445–493  ·  view source on GitHub ↗

* Try to build a house at the zone at \a pos. * @param pos Center tile of the zone. * @param value Value to build (land value?) * @todo Have some form of looking around the center tile (like getFromMap()) */

Source from the content-addressed store, hash-verified

443 * @todo Have some form of looking around the center tile (like getFromMap())
444 */
445void Micropolis::buildHouse(const Position &pos, int value)
446{
447 short z, score, hscore, BestLoc;
448 static short ZeX[9] = { 0,-1, 0, 1,-1, 1,-1, 0, 1};
449 static short ZeY[9] = { 0,-1,-1,-1, 0, 0, 1, 1, 1};
450
451 BestLoc = 0;
452 hscore = 0;
453
454 for (z = 1; z < 9; z++) {
455 int xx = pos.posX + ZeX[z];
456 int yy = pos.posY + ZeY[z];
457
458 if (testBounds(xx, yy)) {
459
460 score = evalLot(xx, yy);
461
462 /// @bug score is never 0 !!
463 if (score != 0) {
464
465 if (score > hscore) {
466 hscore = score;
467 BestLoc = z;
468 }
469
470 /// @todo Move the code below to a better place.
471 /// If we just updated hscore above, we could
472 // trigger this code too.
473 if (score == hscore && !(getRandom16() & 7)) {
474 BestLoc = z;
475 }
476
477 }
478
479 }
480
481 }
482
483 if (BestLoc) {
484 int xx = pos.posX + ZeX[BestLoc];
485 int yy = pos.posY + ZeY[BestLoc];
486
487 if (testBounds(xx, yy)) {
488 /// @todo Is HOUSE the proper constant here?
489 map[xx][yy] = HOUSE + BLBNCNBIT + getRandom(2) + value * 3;
490 }
491
492 }
493}
494
495
496/**

Callers

nothing calls this directly

Calls 1

testBoundsFunction · 0.85

Tested by

no test coverage detected