diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj
index 6ff3a72044..3c13ff3f2b 100644
--- a/projects/openrct2.vcxproj
+++ b/projects/openrct2.vcxproj
@@ -21,6 +21,7 @@
+
@@ -58,6 +59,7 @@
+
diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters
index 44896fdf76..00a17f947b 100644
--- a/projects/openrct2.vcxproj.filters
+++ b/projects/openrct2.vcxproj.filters
@@ -123,6 +123,9 @@
Header Files
+
+ Header Files
+
@@ -275,6 +278,9 @@
Windows
+
+ Source Files
+
diff --git a/src/addresses.h b/src/addresses.h
index 601d8aa95e..a453f9c7bd 100644
--- a/src/addresses.h
+++ b/src/addresses.h
@@ -141,6 +141,7 @@
#define RCT2_ADDRESS_SPRITES_START_LITTER 0x013573C4
#define RCT2_ADDRESS_CURRENT_LOAN 0x013573E0
+#define RCT2_ADDRESS_MAXIMUM_LOAN 0x013580F0
#define RCT2_ADDRESS_PARK_FLAGS 0x013573E4
#define RCT2_ADDRESS_PARK_ENTRANCE_FEE 0x013573E8
#define RCT2_ADDRESS_GUESTS_IN_PARK 0x01357844
@@ -160,8 +161,13 @@
#define RCT2_ADDRESS_CURRENT_COMPANY_VALUE 0x0135874C
#define RCT2_ADDRESS_AWARD_LIST 0x01358760
#define RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED 0x013587F8
+#define RCT2_ADDRESS_CURRENT_INTEREST_RATE 0x0135934A
+#define RCT2_ADDRESS_EXPENDITURE_TABLE 0x01357848
+#define RCT2_ADDRESS_CURRENT_RESEARCH_LEVEL 0x013573FF
+#define RCT2_ADDRESS_CURRENT_INTEREST_RATE 0x0135934A
#define RCT2_ADDRESS_MAP_SIZE 0x01358834
+#define RCT2_ADDRESS_PARK_SIZE 0x013580EA
#define RCT2_ADDRESS_SCENARIO_NAME 0x0135920A
#define RCT2_ADDRESS_SCENARIO_DETAILS 0x0135924A
diff --git a/src/editor.c b/src/editor.c
index 0c53218ee2..31e77b4229 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -40,19 +40,19 @@ void editor_load()
{
rct_window *mainWindow;
- RCT2_CALLPROC_EBPSAFE(0x006BABB4); // pause_sounds
- RCT2_CALLPROC_EBPSAFE(0x006BABD8); // unpause_sounds
+ pause_sounds();
+ unpause_sounds();
RCT2_CALLPROC_EBPSAFE(0x006A9CE8);
map_init();
RCT2_CALLPROC_EBPSAFE(0x006B9CB0);
- RCT2_CALLPROC_EBPSAFE(0x00667104); // reset_park_entrances
- RCT2_CALLPROC_EBPSAFE(0x006C4209); // reset_saved_strings
+ reset_park_entrances();
+ reset_saved_strings();
RCT2_CALLPROC_EBPSAFE(0x0069EB13); // sprites_init
ride_init_all();
RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a
RCT2_CALLPROC_EBPSAFE(0x006BD3A4);
park_init();
- RCT2_CALLPROC_EBPSAFE(0x0069DEFB); // finance_init
+ finance_init();
date_reset();
RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b
RCT2_CALLPROC_EBPSAFE(0x006BD39C);
@@ -94,14 +94,14 @@ void trackdesigner_load()
map_init();
set_all_land_owned();
RCT2_CALLPROC_EBPSAFE(0x006B9CB0);
- RCT2_CALLPROC_EBPSAFE(0x00667104); // reset_park_entrances
- RCT2_CALLPROC_EBPSAFE(0x006C4209); // reset_saved_strings
+ reset_park_entrances();
+ reset_saved_strings();
RCT2_CALLPROC_EBPSAFE(0x0069EB13); // reset_sprites
ride_init_all();
RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a
RCT2_CALLPROC_EBPSAFE(0x006BD3A4);
park_init();
- RCT2_CALLPROC_EBPSAFE(0x0069DEFB); // finance_init
+ finance_init();
date_reset();
RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b
RCT2_CALLPROC_EBPSAFE(0x006BD39C);
@@ -132,14 +132,14 @@ void trackmanager_load()
map_init();
set_all_land_owned();
RCT2_CALLPROC_EBPSAFE(0x006B9CB0);
- RCT2_CALLPROC_EBPSAFE(0x00667104); // reset_park_entrances
- RCT2_CALLPROC_EBPSAFE(0x006C4209); // reset_saved_strings
+ reset_park_entrances();
+ reset_saved_strings();
RCT2_CALLPROC_EBPSAFE(0x0069EB13); // reset_sprites
ride_init_all();
RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a
RCT2_CALLPROC_EBPSAFE(0x006BD3A4);
park_init();
- RCT2_CALLPROC_EBPSAFE(0x0069DEFB); // finance_init
+ finance_init();
date_reset();
RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b
RCT2_CALLPROC_EBPSAFE(0x006BD39C);
@@ -168,3 +168,86 @@ static void set_all_land_owned()
game_do_command(64, 1, 64, 2, 56, (mapSize - 2) * 32, (mapSize - 2) * 32);
}
+
+/**
+*
+* rct2: 0x00667104
+*/
+void reset_park_entrances() {
+ RCT2_GLOBAL(0x013573D4, uint16) = 0;
+
+ for (short i = 0; i < 4; i++) {
+ RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i] = 0x8000;
+ }
+
+ RCT2_GLOBAL(0x013573F2, uint16) = 0xFFFF;
+ RCT2_GLOBAL(0x013573F8, uint16) = 0xFFFF;
+}
+
+/**
+*
+* rct2: 0x006C4209
+*/
+void reset_saved_strings() {
+ for (int i = 0; i < 1024; i++) {
+ RCT2_ADDRESS(0x135A8F4, uint8)[i * 32] = 0;
+ }
+}
+
+/**
+*
+* rct2: 0x006BABB4
+*/
+void pause_sounds() {
+ if (++RCT2_GLOBAL(0x009AF59C, uint8) == 1) {
+ RCT2_CALLPROC_EBPSAFE(0x006BCAE5);
+ RCT2_CALLPROC_EBPSAFE(0x006BABDF);
+ RCT2_CALLPROC_EBPSAFE(0x006BCA9F);
+ RCT2_CALLPROC_EBPSAFE(0x006BD07F);
+ }
+}
+
+/**
+*
+* rct2: 0x006BABD8
+*/
+void unpause_sounds() {
+ RCT2_GLOBAL(0x009AF59C, uint8)--;
+}
+
+/**
+*
+* rct2: 0x0069DEFB
+*/
+void finance_init() {
+
+ for (short i = 0; i < 56; i++) {
+ RCT2_ADDRESS(0x01357848, uint32)[i] = 0;
+ }
+
+ RCT2_GLOBAL(0x0135832C, uint32) = 0;
+
+ RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, uint32) = 0;
+
+ RCT2_GLOBAL(0x01358334, uint32) = 0;
+ RCT2_GLOBAL(0x01358338, uint16) = 0;
+
+ RCT2_GLOBAL(0x013573DC, uint32) = 100000;
+
+ RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(100000);
+ RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, sint32) = 100000;
+ RCT2_GLOBAL(RCT2_ADDRESS_MAXIMUM_LOAN, uint32) = 200000;
+
+ RCT2_GLOBAL(0x013587D0, uint32) = 0;
+
+ RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, uint8) = 10;
+ RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PARK_VALUE, sint32) = 0;
+ RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_COMPANY_VALUE, sint32) = 0;
+ RCT2_GLOBAL(RCT2_ADDRESS_COMPLETED_COMPANY_VALUE, sint32) = 0x80000000;
+ RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_ADMISSIONS, uint32) = 0;
+ RCT2_GLOBAL(RCT2_ADDRESS_INCOME_FROM_ADMISSIONS, uint32) = 0;
+
+ RCT2_GLOBAL(0x013587D8, uint16) = 0x3F;
+
+ RCT2_CALLPROC_EBPSAFE(0x0069E869);
+}
\ No newline at end of file
diff --git a/src/editor.h b/src/editor.h
index 34a7ef5ab3..d350e8a24f 100644
--- a/src/editor.h
+++ b/src/editor.h
@@ -25,5 +25,10 @@ void editor_load();
void editor_convert_save_to_scenario();
void trackdesigner_load();
void trackmanager_load();
+void reset_park_entrances();
+void reset_saved_strings();
+void pause_sounds();
+void unpause_sounds();
+void finance_init();
#endif
diff --git a/src/finance.c b/src/finance.c
new file mode 100644
index 0000000000..37c4a14d60
--- /dev/null
+++ b/src/finance.c
@@ -0,0 +1,103 @@
+/*****************************************************************************
+* Copyright (c) 2014 Matthias Lanzinger
+* 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 .
+*****************************************************************************/
+
+#include "addresses.h"
+#include "finance.h"
+#include "sprite.h"
+#include "park.h"
+#include "peep.h"
+#include "window.h"
+
+
+const int wage_table[4] = { 500, 800, 600, 550 };
+const int research_cost_table[4] = { 0, 1000, 2000, 4000 }; // monthly cost
+
+/**
+ *
+ * rct2: 0x069C674
+ * @param amount (eax)
+ * @param type passed via global var 0x0141F56C, our type is that var/4.
+ **/
+void finance_payment(int amount, rct_expenditure_type type)
+{
+ int test = RCT2_GLOBAL(0x13CA740, uint32);
+ sint32 cur_money = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32));
+ sint32 new_money = cur_money - amount;
+
+ //overflow check
+ RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(new_money);
+ RCT2_ADDRESS(RCT2_ADDRESS_EXPENDITURE_TABLE, sint32)[type] -= amount;
+ if (RCT2_ADDRESS(0x00988E60, uint32)[type] & 1)
+ RCT2_GLOBAL(0x0135832C, sint32) -= amount;
+
+
+ RCT2_GLOBAL(0x009A9804, uint32) |= 1; // money diry flag
+ window_invalidate_by_id(WC_FINANCES, 0);
+}
+
+/**
+ * Pays the wages of all active staff members in the park.
+ * rct2: 0x006C18A9
+ **/
+void finance_pay_wages()
+{
+ rct_peep* peep;
+ uint16 sprite_idx;
+
+ if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800)
+ return;
+
+ 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_STAFF)
+ finance_payment(wage_table[peep->staff_type], RCT_EXPENDITURE_TYPE_WAGES);
+ }
+}
+
+/**
+* Pays the current research level's cost.
+* rct2: 0x00684DA5
+**/
+void finance_pay_research()
+{
+ uint8 level;
+
+ if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800)
+ return;
+
+ level = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RESEARCH_LEVEL, uint8);
+ finance_payment(research_cost_table[level] / 4, RCT_EXPENDITURE_TYPE_RESEARCH);
+}
+
+/**
+ * Pay interest on current loans.
+ * rct2: 0x0069E092
+ **/
+void finance_pay_interest()
+{
+ sint32 current_loan = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, sint32);
+ sint16 current_interest = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, sint16);
+ sint64 tempcost = (current_loan * 5 * current_interest) >> 14; // (5*interest)/2^14 is pretty close to
+
+ if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800)
+ return;
+
+ finance_payment((sint32)tempcost, RCT_EXPENDITURE_TYPE_INTEREST);
+}
diff --git a/src/finance.h b/src/finance.h
new file mode 100644
index 0000000000..6c8d75fdfa
--- /dev/null
+++ b/src/finance.h
@@ -0,0 +1,40 @@
+/*****************************************************************************
+* Copyright (c) 2014 Matthias Lanzinger
+* 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 .
+*****************************************************************************/
+
+#ifndef _FINANCE_H_
+#define _FINANCE_H_
+
+#include "rct2.h"
+
+typedef int rct_expenditure_type;
+
+enum {
+ RCT_EXPENDITURE_TYPE_WAGES = 10,
+ RCT_EXPENDITURE_TYPE_RESEARCH = 12,
+ RCT_EXPENDITURE_TYPE_INTEREST = 13
+};
+
+
+void finance_payment(int amount, rct_expenditure_type type);
+void finance_pay_wages();
+void finance_pay_research();
+void finance_pay_interest();
+
+#endif
\ No newline at end of file
diff --git a/src/park.c b/src/park.c
index 6beb551b6c..a8f5a90f37 100644
--- a/src/park.c
+++ b/src/park.c
@@ -62,8 +62,8 @@ int park_calculate_size()
}
}
- if (tiles != RCT2_GLOBAL(0x013580EA, sint16)) {
- RCT2_GLOBAL(0x013580EA, sint16) = tiles;
+ if (tiles != RCT2_GLOBAL(RCT2_ADDRESS_PARK_SIZE, sint16)) {
+ RCT2_GLOBAL(RCT2_ADDRESS_PARK_SIZE, sint16) = tiles;
window_invalidate_by_id(WC_PARK_INFORMATION, 0);
}
diff --git a/src/scenario.c b/src/scenario.c
index cd0fb9b931..b283c9e767 100644
--- a/src/scenario.c
+++ b/src/scenario.c
@@ -23,6 +23,7 @@
#include
#include "addresses.h"
#include "date.h"
+#include "finance.h"
#include "game.h"
#include "map.h"
#include "news_item.h"
@@ -854,9 +855,9 @@ void scenario_update()
if ((current_days_in_month * next_month_tick) >> 16 != (current_days_in_month * month_tick) >> 16) {
// daily checks
- RCT2_CALLPROC_EBPSAFE(0x0069E79A); // finance update
+ RCT2_CALLPROC_EBPSAFE(0x0069E79A); // daily profit update
RCT2_CALLPROC_EBPSAFE(0x0069C35E); // some kind of peeps days_visited update loop
- RCT2_CALLPROC_EBPSAFE(0x006C45E7); // get local time
+ get_local_time();
RCT2_CALLPROC_EBPSAFE(0x0066A13C); // objective 6 dragging
if (objective_type == 10 || objective_type == 9 || objective_type == 8 ||
objective_type == 6 || objective_type == 5) {
@@ -868,13 +869,13 @@ void scenario_update()
//if ( (unsigned int)((4 * current_day) & 0xFFFF) >= 0xFFEFu) {
if ( next_month_tick % 0x4000 == 0) {
// weekly checks
- RCT2_CALLPROC_EBPSAFE(0x006C18A9);
- RCT2_CALLPROC_EBPSAFE(0x00684DA5);
- RCT2_CALLPROC_EBPSAFE(0x0069E092);
+ finance_pay_wages();
+ finance_pay_research();
+ finance_pay_interest();
scenario_marketing_update();
- RCT2_CALLPROC_EBPSAFE(0x0069BF41);
- RCT2_CALLPROC_EBPSAFE(0x006B7A5E);
- RCT2_CALLPROC_EBPSAFE(0x006AC916);
+ RCT2_CALLPROC_EBPSAFE(0x0069BF41); // peep needs update and warnings
+ RCT2_CALLPROC_EBPSAFE(0x006B7A5E); // check ride reachability
+ RCT2_CALLPROC_EBPSAFE(0x006AC916); // ride update favourited
if (month <= 1 && RCT2_GLOBAL(0x009ADAE0, sint32) != -1 && RCT2_GLOBAL(0x009ADAE0 + 14, uint16) & 1) {
for (int i = 0; i < 100; ++i) {
@@ -886,8 +887,8 @@ void scenario_update()
break;
}
}
- RCT2_CALLPROC_EBPSAFE(0x0066A231);
- RCT2_CALLPROC_EBPSAFE(0x0066A348);
+ RCT2_CALLPROC_EBPSAFE(0x0066A231); // update histories (finance, ratings, etc)
+ park_calculate_size();
}
//if ( (unsigned int)((2 * current_day) & 0xFFFF) >= 0xFFF8) {
@@ -904,7 +905,7 @@ void scenario_update()
RCT2_CALLPROC_EBPSAFE(0x0069DEAD);
scenario_objectives_check();
scenario_entrance_fee_too_high_check();
- RCT2_CALLPROC_EBPSAFE(0x0066A86C);
+ RCT2_CALLPROC_EBPSAFE(0x0066A86C); // award checks
}
}