mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
-Feature: possibility to disable exclusive rights and giving money. Both by skidd13.
This commit is contained in:
parent
c952f3d5ef
commit
ff14665f6e
@ -1047,6 +1047,8 @@ STR_CONFIG_PATCHES_NEW_NONSTOP :{LTBLUE}TTDPatc
|
||||
STR_CONFIG_PATCHES_ROADVEH_QUEUE :{LTBLUE}Road vehicle queueing (with quantum effects): {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_AUTOSCROLL :{LTBLUE}Pan window when mouse is at the edge: {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_BRIBE :{LTBLUE}Allow bribing of the local authority: {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_ALLOW_EXCLUSIVE :{LTBLUE}Allow buying exclusive transport rights: {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_ALLOW_GIVE_MONEY :{LTBLUE}Allow sending money to other companies: {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_NONUNIFORM_STATIONS :{LTBLUE}Nonuniform stations: {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_NEW_PATHFINDING_ALL :{LTBLUE}New global pathfinding (NPF, overrides NTP): {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_FREIGHT_TRAINS :{LTBLUE}Weight multiplier for freight to simulate heavy trains: {ORANGE}{STRING}
|
||||
|
@ -65,7 +65,7 @@ bool _draw_bounding_boxes = false;
|
||||
void CcGiveMoney(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (!success) return;
|
||||
if (!success || !_patches.give_money) return;
|
||||
|
||||
char msg[20];
|
||||
/* Inform the player of this action */
|
||||
|
@ -341,6 +341,8 @@ CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
*/
|
||||
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
if (!_patches.give_money) return CMD_ERROR;
|
||||
|
||||
const Player *p = GetPlayer(_current_player);
|
||||
CommandCost amount(min((Money)p1, (Money)20000000LL));
|
||||
|
||||
|
@ -1264,8 +1264,8 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y)
|
||||
_clientlist_proc[i++] = &ClientList_SpeakToAll;
|
||||
|
||||
if (_network_own_client_index != ci->client_index) {
|
||||
/* We are no spectator and the player we want to give money to is no spectator */
|
||||
if (IsValidPlayer(_network_playas) && IsValidPlayer(ci->client_playas)) {
|
||||
/* We are no spectator and the player we want to give money to is no spectator and money gifts are allowed */
|
||||
if (IsValidPlayer(_network_playas) && IsValidPlayer(ci->client_playas) && _patches.give_money) {
|
||||
GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(_clientlist_action[i]));
|
||||
_clientlist_proc[i++] = &ClientList_GiveMoney;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "strings.h"
|
||||
#include <list>
|
||||
|
||||
extern const uint16 SAVEGAME_VERSION = 78;
|
||||
extern const uint16 SAVEGAME_VERSION = 79;
|
||||
uint16 _sl_version; ///< the major savegame version identifier
|
||||
byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
|
||||
|
||||
|
@ -1429,6 +1429,8 @@ const SettingDesc _patch_settings[] = {
|
||||
SDT_BOOL(Patches, multiple_industry_per_town, 0, 0, false, STR_CONFIG_PATCHES_MULTIPINDTOWN, NULL),
|
||||
SDT_BOOL(Patches, same_industry_close, 0, 0, false, STR_CONFIG_PATCHES_SAMEINDCLOSE, NULL),
|
||||
SDT_BOOL(Patches, bribe, 0, 0, true, STR_CONFIG_PATCHES_BRIBE, NULL),
|
||||
SDT_CONDBOOL(Patches, exclusive_rights, 79, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_ALLOW_EXCLUSIVE, NULL),
|
||||
SDT_CONDBOOL(Patches, give_money, 79, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_ALLOW_GIVE_MONEY, NULL),
|
||||
SDT_VAR(Patches, snow_line_height,SLE_UINT8, 0, 0, 7, 2, 13, 0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT, NULL),
|
||||
SDT_VAR(Patches, colored_news_year,SLE_INT32, 0,NC, 2000, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_COLORED_NEWS_YEAR,NULL),
|
||||
SDT_VAR(Patches, starting_year, SLE_INT32, 0,NC, 1950, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_STARTING_YEAR,NULL),
|
||||
|
@ -695,6 +695,8 @@ static const char *_patches_economy[] = {
|
||||
"multiple_industry_per_town",
|
||||
"same_industry_close",
|
||||
"bribe",
|
||||
"exclusive_rights",
|
||||
"give_money",
|
||||
"colored_news_year",
|
||||
"ending_year",
|
||||
"smooth_economy",
|
||||
|
@ -2014,6 +2014,9 @@ static void TownActionFundBuildings(Town* t)
|
||||
|
||||
static void TownActionBuyRights(Town* t)
|
||||
{
|
||||
/* Check if it's allowed to by the rights */
|
||||
if (!_patches.exclusive_rights) return;
|
||||
|
||||
t->exclusive_counter = 12;
|
||||
t->exclusivity = _current_player;
|
||||
|
||||
|
103
src/town_gui.cpp
103
src/town_gui.cpp
@ -20,19 +20,49 @@
|
||||
#include "variables.h"
|
||||
#include "helpers.hpp"
|
||||
|
||||
enum TownAuthorityWidget {
|
||||
TWA_CLOSEBOX = 0,
|
||||
TWA_CAPTION,
|
||||
TWA_RATING_INFO,
|
||||
TWA_COMMAND_LIST,
|
||||
TWA_SCROLLBAR,
|
||||
TWA_ACTION_INFO,
|
||||
TWA_EXECUTE,
|
||||
};
|
||||
|
||||
static const Widget _town_authority_widgets[] = {
|
||||
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
||||
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 316, 0, 13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
||||
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 14, 105, 0x0, STR_NULL},
|
||||
{ WWT_PANEL, RESIZE_NONE, 13, 0, 304, 106, 157, 0x0, STR_2043_LIST_OF_THINGS_TO_DO_AT},
|
||||
{ WWT_SCROLLBAR, RESIZE_NONE, 13, 305, 316, 106, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
||||
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 158, 209, 0x0, STR_NULL},
|
||||
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 316, 210, 221, STR_2042_DO_IT, STR_2044_CARRY_OUT_THE_HIGHLIGHTED},
|
||||
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // TWA_CLOSEBOX
|
||||
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 316, 0, 13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS}, // TWA_CAPTION
|
||||
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 14, 105, 0x0, STR_NULL}, // TWA_RATING_INFO
|
||||
{ WWT_PANEL, RESIZE_NONE, 13, 0, 304, 106, 157, 0x0, STR_2043_LIST_OF_THINGS_TO_DO_AT}, // TWA_COMMAND_LIST
|
||||
{ WWT_SCROLLBAR, RESIZE_NONE, 13, 305, 316, 106, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // TWA_SCROLLBAR
|
||||
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 158, 209, 0x0, STR_NULL}, // TWA_ACTION_INFO
|
||||
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 316, 210, 221, STR_2042_DO_IT, STR_2044_CARRY_OUT_THE_HIGHLIGHTED}, // TWA_EXECUTE
|
||||
{ WIDGETS_END},
|
||||
};
|
||||
|
||||
extern const byte _town_action_costs[8];
|
||||
|
||||
enum TownActions {
|
||||
TACT_NONE = 0x00,
|
||||
|
||||
TACT_ADVERTISE_SMALL = 0x01,
|
||||
TACT_ADVERTISE_MEDIUM = 0x02,
|
||||
TACT_ADVERTISE_LARGE = 0x04,
|
||||
TACT_ROAD_REBUILD = 0x08,
|
||||
TACT_BUILD_STATUE = 0x10,
|
||||
TACT_FOUND_BUILDINGS = 0x20,
|
||||
TACT_BUY_RIGHTS = 0x40,
|
||||
TACT_BRIBE = 0x80,
|
||||
|
||||
TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE,
|
||||
TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS,
|
||||
TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE,
|
||||
TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS,
|
||||
};
|
||||
|
||||
DECLARE_ENUM_AS_BIT_SET(TownActions);
|
||||
|
||||
/** Get a list of available actions to do at a town.
|
||||
* @param nump if not NULL add put the number of available actions in it
|
||||
* @param pid the player that is querying the town
|
||||
@ -41,41 +71,38 @@ extern const byte _town_action_costs[8];
|
||||
*/
|
||||
uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t)
|
||||
{
|
||||
Money avail, ref;
|
||||
int num = 0;
|
||||
uint avail_buttons = 0x7F; // by default all buttons except bribe are enabled.
|
||||
uint buttons = 0;
|
||||
TownActions buttons = TACT_NONE;
|
||||
|
||||
if (pid != PLAYER_SPECTATOR) {
|
||||
uint i;
|
||||
|
||||
/* bribe option enabled? */
|
||||
if (_patches.bribe) {
|
||||
/* if unwanted, disable everything. */
|
||||
if (t->unwanted[pid]) {
|
||||
avail_buttons = 0;
|
||||
} else if (t->ratings[pid] < RATING_BRIBE_MAXIMUM) {
|
||||
SETBIT(avail_buttons, 7); // Allow bribing
|
||||
}
|
||||
}
|
||||
/* Spectators and unwanted have no options */
|
||||
if (pid != PLAYER_SPECTATOR && !(_patches.bribe && t->unwanted[pid])) {
|
||||
|
||||
/* Things worth more than this are not shown */
|
||||
avail = GetPlayer(pid)->player_money + _price.station_value * 200;
|
||||
ref = _price.build_industry >> 8;
|
||||
Money avail = GetPlayer(pid)->player_money + _price.station_value * 200;
|
||||
Money ref = _price.build_industry >> 8;
|
||||
|
||||
for (i = 0; i != lengthof(_town_action_costs); i++, avail_buttons >>= 1) {
|
||||
if (HASBIT(avail_buttons, 0) && avail >= _town_action_costs[i] * ref) {
|
||||
SETBIT(buttons, i);
|
||||
/* Check the action bits for validity and
|
||||
* if they are valid add them */
|
||||
for (uint i = 0; i != lengthof(_town_action_costs); i++) {
|
||||
const TownActions cur = (TownActions)(1 << i);
|
||||
|
||||
/* Is the player not able to bribe ? */
|
||||
if (cur == TACT_BRIBE && (!_patches.bribe || t->ratings[pid] >= RATING_BRIBE_MAXIMUM))
|
||||
continue;
|
||||
|
||||
/* Is the player not able to buy exclusive rights ? */
|
||||
if (cur == TACT_BUY_RIGHTS && !_patches.exclusive_rights)
|
||||
continue;
|
||||
|
||||
/* Is the player not able to build a statue ? */
|
||||
if (cur == TACT_BUILD_STATUE && HASBIT(t->statues, pid))
|
||||
continue;
|
||||
|
||||
if (avail >= _town_action_costs[i] * ref) {
|
||||
buttons |= cur;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable build statue if already built */
|
||||
if (HASBIT(t->statues, pid)) {
|
||||
CLRBIT(buttons, 4);
|
||||
num--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (nump != NULL) *nump = num;
|
||||
@ -161,9 +188,9 @@ static void TownAuthorityWndProc(Window *w, WindowEvent *e)
|
||||
y += 10;
|
||||
}
|
||||
for (i = 0; buttons; i++, buttons >>= 1) {
|
||||
if (pos <= -5) break;
|
||||
if (pos <= -5) break; ///< Draw only the 5 fitting lines
|
||||
|
||||
if (buttons&1 && --pos < 0) {
|
||||
if ((buttons & 1) && --pos < 0) {
|
||||
DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, 6);
|
||||
y += 10;
|
||||
}
|
||||
@ -185,7 +212,7 @@ static void TownAuthorityWndProc(Window *w, WindowEvent *e)
|
||||
case WE_DOUBLE_CLICK:
|
||||
case WE_CLICK:
|
||||
switch (e->we.click.widget) {
|
||||
case 3: { /* listbox */
|
||||
case TWA_COMMAND_LIST: {
|
||||
const Town *t = GetTown(w->window_number);
|
||||
int y = (e->we.click.pt.y - 0x6B) / 10;
|
||||
|
||||
@ -200,7 +227,7 @@ static void TownAuthorityWndProc(Window *w, WindowEvent *e)
|
||||
if (e->event != WE_DOUBLE_CLICK || y < 0) break;
|
||||
}
|
||||
|
||||
case 6: { /* carry out the action */
|
||||
case TWA_EXECUTE: {
|
||||
DoCommandP(GetTown(w->window_number)->xy, w->window_number, WP(w,def_d).data_1, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
|
||||
break;
|
||||
}
|
||||
|
@ -244,6 +244,9 @@ struct Patches {
|
||||
bool autoslope; ///< Allow terraforming under things.
|
||||
|
||||
bool mod_road_rebuild; ///< Roadworks remove unneccesary RoadBits
|
||||
|
||||
bool exclusive_rights; ///< allow buying exclusive rights
|
||||
bool give_money; ///< allow giving other players money
|
||||
};
|
||||
|
||||
VARDEF Patches _patches;
|
||||
|
Loading…
Reference in New Issue
Block a user