add some park functions

This commit is contained in:
IntelOrca 2014-04-08 00:41:35 +01:00
parent 880e741341
commit 1b92d895a2
7 changed files with 341 additions and 0 deletions

View File

@ -23,8 +23,10 @@
<ClInclude Include="..\src\intro.h" />
<ClInclude Include="..\src\news_item.h" />
<ClInclude Include="..\src\osinterface.h" />
<ClInclude Include="..\src\park.h" />
<ClInclude Include="..\src\peep.h" />
<ClInclude Include="..\src\rct2.h" />
<ClInclude Include="..\src\ride.h" />
<ClInclude Include="..\src\scenario.h" />
<ClInclude Include="..\src\sprite.h" />
<ClInclude Include="..\src\sprites.h" />
@ -43,6 +45,7 @@
<ClCompile Include="..\src\intro.c" />
<ClCompile Include="..\src\news_item.c" />
<ClCompile Include="..\src\osinterface.c" />
<ClCompile Include="..\src\park.c" />
<ClCompile Include="..\src\peep.c" />
<ClCompile Include="..\src\rct2.c" />
<ClCompile Include="..\src\scenario.c" />

View File

@ -75,6 +75,12 @@
<ClInclude Include="..\src\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\ride.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\park.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\game.c">
@ -137,6 +143,9 @@
<ClCompile Include="..\src\config.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\park.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\openrct2.exe">

View File

@ -84,6 +84,13 @@
#define RCT2_ADDRESS_SPRITES_START_TEXTFX 0x013573C2
#define RCT2_ADDRESS_SPRITES_START_LITTER 0x013573C4
#define RCT2_ADDRESS_CURRENT_LOAN 0x013573E0
#define RCT2_ADDRESS_GUESTS_IN_PARK 0x01357844
#define RCT2_ADDRESS_CURRENT_PARK_VALUE 0x0135853C
#define RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED 0x013587F8
#define RCT2_ADDRESS_RIDE_LIST 0x013628F8
#define RCT2_ADDRESS_NEWS_ITEM_LIST 0x013CA754
#define RCT2_ADDRESS_SCENARIO_NAME 0x0141F5B8

222
src/park.c Normal file
View File

@ -0,0 +1,222 @@
/*****************************************************************************
* Copyright (c) 2014 Ted John
* 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"
#include "park.h"
#include "peep.h"
#include "ride.h"
#include "sprite.h"
/**
*
* rct2: 0x00669EAA
*/
int calculate_park_rating()
{
int result;
result = 1150;
if (RCT2_GLOBAL(0x013573E4, uint32) & 0x4000)
result = 1050;
// Guests
{
rct_peep* peep;
uint16 sprite_idx;
int num_happy_peeps;
short _bp;
// -150 to +3 based on a range of guests from 0 to 2000
result -= 150 - (min(2000, RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16)) / 13);
// Guests, happiness, ?
num_happy_peeps = 0;
_bp = 0;
for (sprite_idx = RCT2_GLOBAL(RCT2_ADDRESS_SPRITES_START_PEEP, uint16); sprite_idx != SPRITE_INDEX_NULL; sprite_idx = peep->next) {
peep = &(RCT2_ADDRESS(RCT2_ADDRESS_SPRITE_LIST, rct_sprite)[sprite_idx].peep);
if (peep->type != PEEP_TYPE_GUEST)
continue;
if (peep->var_2A != 0)
continue;
if (peep->happiness > 128)
num_happy_peeps++;
if (!(peep->var_C8 & 0x01))
continue;
if (peep->var_C6 <= 89)
_bp++;
}
// Peep happiness -500 to +0
result -= 500;
if (num_happy_peeps > 0)
result += 2 * min(250, (RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16) * 300) / num_happy_peeps);
// ?
_bp -= 25;
if (_bp >= 0)
result -= _bp * 7;
}
// Rides
{
int i;
short _ax, _bx;
int num_rides;
rct_ride* ride;
//
_ax = 0;
num_rides = 0;
for (i = 0; i < 255; i++) {
ride = &(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_LIST, rct_ride)[i]);
if (ride->type == RIDE_TYPE_NULL)
continue;
_ax += 100 - ride->var_199;
num_rides++;
}
result -= 200;
if (num_rides > 0)
result += (_ax / num_rides) * 2;
//
_ax = 0;
_bx = 0;
for (i = 0; i < 255; i++) {
ride = &(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_LIST, rct_ride)[i]);
if (ride->type == RIDE_TYPE_NULL)
continue;
if (ride->var_140 == -1)
continue;
_ax += ride->var_140 / 8;
_bx += ride->var_142 / 8;
}
_ax = min(1000, _ax);
_bx = min(1000, _bx);
result -= 200 - ((_ax + _bx) / 10);
}
// Litter
{
rct_litter* litter;
uint16 sprite_idx;
short num_litter;
num_litter = 0;
for (sprite_idx = RCT2_GLOBAL(RCT2_ADDRESS_SPRITES_START_LITTER, uint16); sprite_idx != SPRITE_INDEX_NULL; sprite_idx = litter->next) {
litter = &(RCT2_ADDRESS(RCT2_ADDRESS_SPRITE_LIST, rct_sprite)[sprite_idx].litter);
// Guessing this eliminates recently dropped litter
if (litter->var_24 - RCT2_GLOBAL(0x00F663AC, sint32) >= 7680)
num_litter++;
}
result -= 600 - (4 * (150 - min(150, num_litter)));
}
// Rides
{
int i, num_rides;
short _ax, _bx;
rct_ride* ride;
num_rides = 0;
_ax = 0;
_bx = 0;
for (i = 0; i < 255; i++) {
ride = &(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_LIST, rct_ride)[i]);
if (ride->type == RIDE_TYPE_NULL)
continue;
if (ride->var_140 == -1)
continue;
_ax += ride->var_140 / 8;
_bx += ride->var_142 / 8;
num_rides++;
}
result -= 100;
if (num_rides > 0) {
_bx = _ax / num_rides;
_ax = _bx / num_rides;
_bx -= 46;
if (_bx >= 0)
_bx = -_bx;
_ax -= 65;
if (_ax >= 0)
_ax = -_ax;
_bx /= 2;
_ax /= 2;
_bx = min(50, _bx);
_ax = min(50, _ax);
result += 100 - _ax - _bx;
}
}
result -= RCT2_GLOBAL(0x0135882E, sint16);
result = clamp(0, result, 999);
return result;
}
/**
*
* rct2: 0x0066A3F6
*/
int calculate_park_value()
{
int result, value, i;
rct_ride* ride;
result = 0;
for (i = 0; i < 255; i++) {
ride = &(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_LIST, rct_ride)[i]);
if (ride->type == RIDE_TYPE_NULL)
continue;
if (ride->reliability == 0xFFFF)
continue;
value = 0;
value += ride->var_124 + ride->var_126 + ride->var_128 + ride->var_12A;
value += ride->var_12C + ride->var_12E + ride->age + ride->running_cost;
value += ride->var_134 + ride->var_136;
value += *((uint8*)(0x0097D21E + (ride->type * 8))) * 4;
value *= ride->reliability * 10;
result += value;
}
result += RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16) * 70;
return result;
}
/**
*
* rct2: 0x0066A498
*/
int calculate_company_value()
{
int result;
result = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32));
result += RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PARK_VALUE, sint32);
result -= RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, sint32);
return result;
}

33
src/park.h Normal file
View File

@ -0,0 +1,33 @@
/*****************************************************************************
* Copyright (c) 2014 Ted John
* 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/>.
*****************************************************************************/
#ifndef _PARK_H_
#define _PARK_H_
#include "rct2.h"
#define DECRYPT_MONEY(money) rol32((money) ^ 0xF4EC9621, 13)
#define ENCRYPT_MONEY(money) (ror32((money), 13) ^ 0xF4EC9621)
int calculate_park_rating();
int calculate_park_value();
int calculate_company_value();
#endif

View File

@ -22,6 +22,7 @@
#define _SDL_RCT2_H_
#include <stddef.h>
#include <stdlib.h>
typedef signed char sint8;
typedef signed short sint16;
@ -32,6 +33,11 @@ typedef unsigned short uint16;
typedef unsigned long uint32;
typedef unsigned long long uint64;
#define rol32(x, shift) (((x) << (shift)) | ((x) >> (32 - (shift))))
#define ror32(x, shift) (((x) >> (shift)) | ((x) << (32 - (shift))))
#define sgn(x) ((x > 0) ? 1 : ((x < 0) ? -1 : 0))
#define clamp(l, x, h) (min(h, max(l, x)))
void rct2_finish();
enum {

61
src/ride.h Normal file
View File

@ -0,0 +1,61 @@
/*****************************************************************************
* Copyright (c) 2014 Ted John
* 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/>.
*****************************************************************************/
#ifndef _RIDE_H_
#define _RIDE_H_
#include "rct2.h"
/**
* Ride structure.
* size: 0x0260
*/
typedef struct {
uint8 type; // 0x000
uint8 pad_001[0xEF];
sint16 excitement; // 0x0F0
sint16 intensity; // 0x0F2
sint16 nausea; // 0x0F4
uint8 pad_0F6[0x2E];
sint16 var_124;
sint16 var_126;
sint16 var_128;
sint16 var_12A;
sint16 var_12C;
sint16 var_12E;
uint16 age; // 0x130
sint16 running_cost; // 0x132
sint16 var_134;
sint16 var_136;
uint8 pad_138[0x08];
sint16 var_140;
sint16 var_142;
uint16 pad_144;
uint16 reliability; // 0x146
uint8 pad_148[0x51];
uint8 var_199;
uint8 pad_19A[0xC6];
} rct_ride;
enum {
RIDE_TYPE_NULL = (uint8)-1
};
#endif