2014-04-09 04:09:30 +02:00
|
|
|
/*****************************************************************************
|
2014-05-03 11:34:11 +02:00
|
|
|
* Copyright (c) 2014 Ted John, Peter Hill
|
2014-04-09 04:09:30 +02:00
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* This file is part of OpenRCT2.
|
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "addresses.h"
|
2014-04-09 12:16:35 +02:00
|
|
|
#include "climate.h"
|
|
|
|
#include "date.h"
|
2014-04-09 04:09:30 +02:00
|
|
|
#include "map.h"
|
|
|
|
|
|
|
|
#define GET_MAP_ELEMENT(x) (&(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element)[x]))
|
2014-04-09 18:06:47 +02:00
|
|
|
#define TILE_MAP_ELEMENT_POINTER(x) (RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*)[x])
|
|
|
|
|
|
|
|
static void tiles_init();
|
2014-04-09 04:09:30 +02:00
|
|
|
|
2014-04-13 23:23:56 +02:00
|
|
|
void map_element_set_terrain(rct_map_element *element, int terrain)
|
|
|
|
{
|
|
|
|
// Bit 3 for terrain is stored in element.type bit 0
|
|
|
|
if (terrain & 8)
|
|
|
|
element->type |= 1;
|
|
|
|
else
|
|
|
|
element->type &= ~1;
|
|
|
|
|
|
|
|
// Bits 0, 1, 2 for terrain are stored in element.terrain bit 5, 6, 7
|
|
|
|
element->properties.surface.terrain &= ~0xE0;
|
|
|
|
element->properties.surface.terrain = (terrain & 7) << 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
void map_element_set_terrain_edge(rct_map_element *element, int terrain)
|
|
|
|
{
|
|
|
|
// Bit 3 for terrain is stored in element.type bit 0
|
|
|
|
if (terrain & 8)
|
|
|
|
element->type |= 128;
|
|
|
|
else
|
|
|
|
element->type &= ~128;
|
|
|
|
|
|
|
|
// Bits 0, 1, 2 for terrain are stored in element.slope bit 5, 6, 7
|
|
|
|
element->properties.surface.slope &= ~0xE0;
|
|
|
|
element->properties.surface.slope = (terrain & 7) << 5;
|
|
|
|
}
|
|
|
|
|
2014-05-03 22:34:22 +02:00
|
|
|
rct_map_element *map_get_surface_element_at(int x, int y)
|
|
|
|
{
|
|
|
|
// Get first element of the tile
|
|
|
|
rct_map_element *mapElement = TILE_MAP_ELEMENT_POINTER(y * 256 + x);
|
|
|
|
|
|
|
|
// Find the first surface element
|
|
|
|
while ((mapElement->type & MAP_ELEMENT_TYPE_MASK) != MAP_ELEMENT_TYPE_SURFACE) {
|
|
|
|
// Check if last element on tile
|
|
|
|
if (mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
mapElement++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mapElement;
|
|
|
|
}
|
|
|
|
|
2014-04-09 04:09:30 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068AB4C
|
|
|
|
*/
|
|
|
|
void map_init()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
rct_map_element *map_element;
|
|
|
|
|
2014-04-09 12:16:35 +02:00
|
|
|
date_reset();
|
2014-04-09 04:09:30 +02:00
|
|
|
RCT2_GLOBAL(0x0138B580, sint16) = 0;
|
|
|
|
RCT2_GLOBAL(0x010E63B8, sint32) = 0;
|
|
|
|
|
2014-04-09 18:06:47 +02:00
|
|
|
for (i = 0; i < MAX_TILE_MAP_ELEMENT_POINTERS; i++) {
|
2014-04-09 04:09:30 +02:00
|
|
|
map_element = GET_MAP_ELEMENT(i);
|
2014-04-24 19:53:42 +02:00
|
|
|
map_element->type = (MAP_ELEMENT_TYPE_SURFACE << 2);
|
2014-04-10 05:02:06 +02:00
|
|
|
map_element->flags = MAP_ELEMENT_FLAG_LAST_TILE;
|
|
|
|
map_element->base_height = 14;
|
|
|
|
map_element->clearance_height = 14;
|
2014-04-24 19:53:42 +02:00
|
|
|
map_element->properties.surface.slope = 0;
|
2014-04-10 05:02:06 +02:00
|
|
|
map_element->properties.surface.grass_length = 1;
|
|
|
|
map_element->properties.surface.ownership = 0;
|
2014-04-13 23:23:56 +02:00
|
|
|
|
|
|
|
map_element_set_terrain(map_element, TERRAIN_GRASS);
|
2014-04-24 19:53:42 +02:00
|
|
|
map_element_set_terrain_edge(map_element, TERRAIN_EDGE_ROCK);
|
2014-04-09 04:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT2_GLOBAL(0x013B0E70, sint16) = 0;
|
|
|
|
RCT2_GLOBAL(0x013CE774, sint16) = 0;
|
|
|
|
RCT2_GLOBAL(0x013CE776, sint16) = 0;
|
|
|
|
RCT2_GLOBAL(0x01358830, sint16) = 4768;
|
|
|
|
RCT2_GLOBAL(0x01358832, sint16) = 5054;
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16) = 150;
|
|
|
|
RCT2_GLOBAL(0x01358836, sint16) = 4767;
|
|
|
|
RCT2_GLOBAL(0x01359208, sint16) = 7;
|
2014-04-10 16:14:47 +02:00
|
|
|
map_update_tile_pointers();
|
2014-04-09 04:09:30 +02:00
|
|
|
RCT2_CALLPROC_EBPSAFE(0x0068ADBC);
|
2014-04-09 12:16:35 +02:00
|
|
|
|
|
|
|
climate_reset(CLIMATE_WARM);
|
2014-04-09 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068AFFD
|
|
|
|
*/
|
2014-04-10 16:14:47 +02:00
|
|
|
void map_update_tile_pointers()
|
2014-04-09 18:06:47 +02:00
|
|
|
{
|
|
|
|
int i, x, y, lastTile;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_TILE_MAP_ELEMENT_POINTERS; i++)
|
|
|
|
TILE_MAP_ELEMENT_POINTER(i) = TILE_UNDEFINED_MAP_ELEMENT;
|
|
|
|
|
|
|
|
rct_map_element *mapElement = RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element);
|
|
|
|
rct_map_element **tile = RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*);
|
|
|
|
for (y = 0; y < 256; y++) {
|
|
|
|
for (x = 0; x < 256; x++) {
|
|
|
|
*tile++ = mapElement;
|
|
|
|
do {
|
2014-04-10 05:02:06 +02:00
|
|
|
lastTile = (mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE);
|
2014-04-09 18:06:47 +02:00
|
|
|
mapElement++;
|
|
|
|
} while (!lastTile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Possible next free map element
|
|
|
|
RCT2_GLOBAL(0x0140E9A4, rct_map_element*) = mapElement;
|
2014-04-10 16:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-02 21:25:42 +02:00
|
|
|
* Return the absolute height of an element, given its (x,y) coordinates
|
|
|
|
*
|
2014-04-10 16:14:47 +02:00
|
|
|
* rct2: 0x00662783
|
|
|
|
*/
|
2014-05-02 21:25:42 +02:00
|
|
|
int map_element_height(int x, int y)
|
2014-04-10 16:14:47 +02:00
|
|
|
{
|
|
|
|
rct_map_element *mapElement;
|
|
|
|
|
2014-05-02 21:25:42 +02:00
|
|
|
// Off the map
|
2014-04-10 16:14:47 +02:00
|
|
|
if (x >= 8192 || y >= 8192)
|
|
|
|
return 16;
|
|
|
|
|
2014-05-03 22:34:22 +02:00
|
|
|
// Truncate subtile coordinates
|
2014-05-02 21:25:42 +02:00
|
|
|
int x_tile = x & 0xFFFFFFE0;
|
|
|
|
int y_tile = y & 0xFFFFFFE0;
|
2014-04-10 16:14:47 +02:00
|
|
|
|
2014-05-03 22:34:22 +02:00
|
|
|
// Get the surface element for the tile
|
|
|
|
mapElement = map_get_surface_element_at(x_tile / 32, y_tile / 32);
|
2014-04-10 16:14:47 +02:00
|
|
|
|
2014-05-02 21:25:42 +02:00
|
|
|
uint32 height =
|
2014-04-10 16:14:47 +02:00
|
|
|
((mapElement->properties.surface.terrain & MAP_ELEMENT_WATER_HEIGHT_MASK) << 20) |
|
|
|
|
(mapElement->base_height << 3);
|
|
|
|
|
2014-05-02 21:25:42 +02:00
|
|
|
uint32 slope = (mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK);
|
|
|
|
uint8 extra_height = (slope & 0x10) >> 4; // 0x10 is the 5th bit - sets slope to double height
|
2014-05-03 10:24:25 +02:00
|
|
|
// Remove the extra height bit
|
2014-05-02 21:25:42 +02:00
|
|
|
slope &= 0xF;
|
|
|
|
|
2014-05-03 10:22:20 +02:00
|
|
|
uint8 quad, quad_extra; // which quadrant the element is in?
|
|
|
|
// quad_extra is for extra height tiles
|
2014-05-02 21:25:42 +02:00
|
|
|
|
2014-05-03 10:24:25 +02:00
|
|
|
uint8 xl, yl; // coordinates across this tile
|
2014-05-02 21:25:42 +02:00
|
|
|
|
|
|
|
uint8 TILE_SIZE = 31;
|
|
|
|
|
|
|
|
xl = x & 0x1f;
|
|
|
|
yl = y & 0x1f;
|
|
|
|
|
2014-05-03 10:24:25 +02:00
|
|
|
// Slope logic:
|
|
|
|
// Each of the four bits in slope represents that corner being raised
|
|
|
|
// slope == 15 (all four bits) is not used and slope == 0 is flat
|
|
|
|
// If the extra_height bit is set, then the slope goes up two z-levels
|
|
|
|
|
|
|
|
// We arbitrarily take the SW corner to be closest to the viewer
|
2014-05-02 21:25:42 +02:00
|
|
|
|
|
|
|
// One corner up
|
|
|
|
if ((slope == 1) || (slope == 2) || (slope == 4) || (slope == 8)) {
|
2014-05-03 10:24:25 +02:00
|
|
|
switch (slope) {
|
|
|
|
case 1: // NE corner up
|
|
|
|
quad = xl + yl - TILE_SIZE;
|
|
|
|
break;
|
|
|
|
case 2: // SE corner up
|
|
|
|
quad = xl - yl;
|
|
|
|
break;
|
|
|
|
case 4: // SW corner up
|
|
|
|
quad = TILE_SIZE - yl - xl;
|
|
|
|
break;
|
|
|
|
case 8: // NW corner up
|
|
|
|
quad = xl - yl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// If the element is in the quadrant with the slope, raise its height
|
|
|
|
if (quad > 0) {
|
|
|
|
height += quad / 2;
|
|
|
|
}
|
2014-05-02 21:25:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// One side up
|
2014-05-03 10:24:25 +02:00
|
|
|
switch (slope) {
|
2014-05-02 21:25:42 +02:00
|
|
|
case 3: // E side up
|
2014-05-03 10:24:25 +02:00
|
|
|
height += xl / 2;
|
|
|
|
break;
|
2014-05-02 21:25:42 +02:00
|
|
|
case 6: // S side up
|
2014-05-03 10:24:25 +02:00
|
|
|
height += (TILE_SIZE - yl) / 2;
|
|
|
|
break;
|
2014-05-02 21:25:42 +02:00
|
|
|
case 9: // N side up
|
2014-05-03 10:24:25 +02:00
|
|
|
height += yl / 2;
|
|
|
|
height++;
|
|
|
|
break;
|
2014-05-02 21:25:42 +02:00
|
|
|
case 12: // W side up
|
2014-05-03 10:24:25 +02:00
|
|
|
height += (TILE_SIZE - xl) / 2;
|
|
|
|
break;
|
2014-05-02 21:25:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// One corner down
|
|
|
|
if ((slope == 7) || (slope == 11) || (slope == 13) || (slope == 14)) {
|
2014-05-03 10:24:25 +02:00
|
|
|
switch (slope) {
|
|
|
|
case 7: // NW corner down
|
|
|
|
quad_extra = xl + TILE_SIZE - yl;
|
|
|
|
quad = xl - yl;
|
|
|
|
break;
|
|
|
|
case 11: // SW corner down
|
|
|
|
quad_extra = xl + yl;
|
|
|
|
quad = xl + yl - TILE_SIZE;
|
|
|
|
break;
|
|
|
|
case 13: // SE corner down
|
|
|
|
quad_extra = TILE_SIZE - xl + yl;
|
|
|
|
quad = xl - yl;
|
|
|
|
break;
|
|
|
|
case 14: // NE corner down
|
|
|
|
quad_extra = (TILE_SIZE - xl) + (TILE_SIZE - yl);
|
|
|
|
quad = TILE_SIZE - yl - xl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extra_height) {
|
|
|
|
height += quad_extra / 2;
|
|
|
|
height++;
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
// This tile is essentially at the next height level
|
|
|
|
height += 0x10;
|
|
|
|
// so we move *down* the slope
|
|
|
|
if (quad < 0) {
|
|
|
|
height += quad / 2;
|
|
|
|
height += 0xFF00;
|
|
|
|
}
|
2014-05-02 21:25:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Valleys
|
2014-05-03 10:22:20 +02:00
|
|
|
if ((slope == 5) || (slope == 10)) {
|
2014-05-03 10:24:25 +02:00
|
|
|
switch (slope) {
|
|
|
|
case 5: // NW-SE valley
|
|
|
|
if (xl + yl <= TILE_SIZE + 1) {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
quad = TILE_SIZE - xl - yl;
|
|
|
|
break;
|
|
|
|
case 10: // NE-SW valley
|
|
|
|
quad = xl - yl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (quad > 0) {
|
|
|
|
height += quad / 2;
|
|
|
|
}
|
2014-05-02 21:25:42 +02:00
|
|
|
}
|
2014-04-10 16:14:47 +02:00
|
|
|
|
2014-05-02 21:25:42 +02:00
|
|
|
return height;
|
2014-04-21 11:27:48 +02:00
|
|
|
}
|
2014-05-04 19:51:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0068B089
|
|
|
|
*/
|
|
|
|
void sub_68B089()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
rct_map_element *mapElementFirst, *mapElement;
|
|
|
|
|
|
|
|
if (RCT2_GLOBAL(0x009DEA6F, uint8) & 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
i = RCT2_GLOBAL(0x0010E63B8, uint32);
|
|
|
|
do {
|
|
|
|
i++;
|
|
|
|
if (i >= MAX_TILE_MAP_ELEMENT_POINTERS)
|
|
|
|
i = 0;
|
2014-05-12 02:45:45 +02:00
|
|
|
} while (TILE_MAP_ELEMENT_POINTER(i) == TILE_UNDEFINED_MAP_ELEMENT);
|
2014-05-04 19:51:36 +02:00
|
|
|
RCT2_GLOBAL(0x0010E63B8, uint32) = i;
|
|
|
|
|
|
|
|
mapElementFirst = mapElement = TILE_MAP_ELEMENT_POINTER(i);
|
|
|
|
do {
|
|
|
|
mapElement--;
|
2014-05-12 02:45:45 +02:00
|
|
|
if (mapElement < (rct_map_element*)RCT2_ADDRESS_MAP_ELEMENTS)
|
2014-05-04 19:51:36 +02:00
|
|
|
break;
|
|
|
|
} while (mapElement->base_height == 255);
|
|
|
|
mapElement++;
|
|
|
|
|
|
|
|
if (mapElement == mapElementFirst)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//
|
|
|
|
TILE_MAP_ELEMENT_POINTER(i) = mapElement;
|
|
|
|
do {
|
|
|
|
*mapElement = *mapElementFirst;
|
|
|
|
mapElementFirst->base_height = 255;
|
|
|
|
|
|
|
|
mapElement++;
|
|
|
|
mapElementFirst++;
|
|
|
|
} while (!((mapElement - 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE));
|
|
|
|
|
|
|
|
// Update next free element?
|
|
|
|
mapElement = RCT2_GLOBAL(0x0140E9A4, rct_map_element*);
|
|
|
|
do {
|
|
|
|
mapElement--;
|
|
|
|
} while (mapElement->base_height == 255);
|
|
|
|
mapElement++;
|
|
|
|
RCT2_GLOBAL(0x0140E9A4, rct_map_element*) = mapElement;
|
2014-05-26 15:22:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the tile at coordinate at height counts as connected.
|
|
|
|
* @return 1 if connected, 0 otherwisei
|
|
|
|
*/
|
2014-05-26 17:39:18 +02:00
|
|
|
int map_coord_is_connected(uint16 tile_idx, uint8 height, uint8 face_direction)
|
2014-05-26 15:22:52 +02:00
|
|
|
{
|
2014-05-26 17:39:18 +02:00
|
|
|
rct_map_element* tile = RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*)[tile_idx];
|
2014-05-26 15:22:52 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
rct_map_element_path_properties props = tile->properties.path;
|
|
|
|
uint8 path_type = props.type >> 2, path_dir = props.type & 3;
|
|
|
|
uint8 element_type = tile->type & MAP_ELEMENT_TYPE_MASK;
|
|
|
|
|
2014-05-26 17:39:18 +02:00
|
|
|
if (element_type != PATH_ROAD)
|
2014-05-26 15:22:52 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (path_type & 1) {
|
|
|
|
if (path_dir == face_direction) {
|
|
|
|
if (height == tile->base_height + 2)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (path_dir ^ 2 == face_direction && height == tile->base_height) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (height == tile->base_height)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (!(tile->flags & MAP_ELEMENT_FLAG_LAST_TILE) && tile++);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|