MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Map_CreateLandscape

Function Map_CreateLandscape

src/map.c:1439–1673  ·  view source on GitHub ↗

* Creates the landscape using the given seed. * @param seed The seed. */

Source from the content-addressed store, hash-verified

1437 * @param seed The seed.
1438 */
1439void Map_CreateLandscape(uint32 seed)
1440{
1441 static const int8 around[] = {0, -1, 1, -16, 16, -17, 17, -15, 15, -2, 2, -32, 32, -4, 4, -64, 64, -30, 30, -34, 34};
1442
1443 uint16 i;
1444 uint16 j;
1445 uint16 k;
1446 uint8 memory[273];
1447 uint16 currentRow[64];
1448 uint16 previousRow[64];
1449 uint16 spriteID1;
1450 uint16 spriteID2;
1451 uint16 *iconMap;
1452
1453 Tools_Random_Seed(seed);
1454
1455 /* Place random data on a 4x4 grid. */
1456 for (i = 0; i < 272; i++) {
1457 memory[i] = Tools_Random_256() & 0xF;
1458 if (memory[i] > 0xA) memory[i] = 0xA;
1459 }
1460
1461 i = (Tools_Random_256() & 0xF) + 1;
1462 while (i-- != 0) {
1463 int16 base = Tools_Random_256();
1464
1465 for (j = 0; j < lengthof(around); j++) {
1466 int16 index = min(max(0, base + around[j]), 272);
1467
1468 memory[index] = (memory[index] + (Tools_Random_256() & 0xF)) & 0xF;
1469 }
1470 }
1471
1472 i = (Tools_Random_256() & 0x3) + 1;
1473 while (i-- != 0) {
1474 int16 base = Tools_Random_256();
1475
1476 for (j = 0; j < lengthof(around); j++) {
1477 int16 index = min(max(0, base + around[j]), 272);
1478
1479 memory[index] = Tools_Random_256() & 0x3;
1480 }
1481 }
1482
1483 for (j = 0; j < 16; j++) {
1484 for (i = 0; i < 16; i++) {
1485 g_map[Tile_PackXY(i * 4, j * 4)].groundTileID = memory[j * 16 + i];
1486 }
1487 }
1488
1489 /* Average around the 4x4 grid. */
1490 for (j = 0; j < 16; j++) {
1491 for (i = 0; i < 16; i++) {
1492 for (k = 0; k < 21; k++) {
1493 const uint16 *offsets = _offsetTable[(i + 1) % 2][k];
1494 uint16 packed1;
1495 uint16 packed2;
1496 uint16 packed;

Callers 2

Scenario_LoadFunction · 0.85
Info_LoadFunction · 0.85

Calls 5

Tools_Random_SeedFunction · 0.85
Tools_Random_256Function · 0.85
Tile_UnpackTileFunction · 0.85
Tile_MoveByRandomFunction · 0.85
Map_AddSpiceOnTileFunction · 0.85

Tested by

no test coverage detected