summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-10-17 17:59:41 +0000
committerDarkvater <darkvater@openttd.org>2006-10-17 17:59:41 +0000
commitfba7d2f7f32aaef9497abbe8f1d7423b1a9d9220 (patch)
tree78e9f63f8221b7a2f6a4824b9b0d23036795510d
parentec9e59b4fc1e04823f1637e26e04c8d5e8047fec (diff)
downloadopenttd-fba7d2f7f32aaef9497abbe8f1d7423b1a9d9220.tar.xz
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
-rw-r--r--economy.c32
-rw-r--r--news.h41
-rw-r--r--news_gui.c21
-rw-r--r--players.c4
-rw-r--r--station_cmd.c2
5 files changed, 64 insertions, 36 deletions
diff --git a/economy.c b/economy.c
index 36bab82ab..e03c9c17e 100644
--- a/economy.c
+++ b/economy.c
@@ -382,14 +382,14 @@ static void PlayersCheckBankrupt(Player *p)
switch (p->quarters_of_bankrupcy) {
case 2:
- AddNewsItem( (StringID)(owner + 16),
+ AddNewsItem( (StringID)(owner | NB_BTROUBLE),
NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
break;
case 3: {
/* XXX - In multiplayer, should we ask other players if it wants to take
over when it is a human company? -- TrueLight */
if (IsHumanPlayer(owner)) {
- AddNewsItem( (StringID)(owner + 16),
+ AddNewsItem( (StringID)(owner | NB_BTROUBLE),
NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
break;
}
@@ -412,7 +412,7 @@ static void PlayersCheckBankrupt(Player *p)
// Show bankrupt news
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
- AddNewsItem( (StringID)(owner + 16*3), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
+ AddNewsItem( (StringID)(owner | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
// If the player is human, and it is no network play, leave the player playing
if (IsHumanPlayer(owner) && !_networking) {
@@ -460,7 +460,7 @@ void DrawNewsBankrupcy(Window *w)
DrawNewsBorder(w);
- p = GetPlayer(WP(w,news_d).ni->string_id & 15);
+ p = GetPlayer(GB(WP(w,news_d).ni->string_id, 0, 4));
DrawPlayerFace(p->face, p->player_color, 2, 23);
GfxFillRect(3, 23, 3+91, 23+118, 0x323 | USE_COLORTABLE);
@@ -469,8 +469,8 @@ void DrawNewsBankrupcy(Window *w)
DrawStringMultiCenter(49, 148, STR_7058_PRESIDENT, 94);
- switch (WP(w,news_d).ni->string_id >> 4) {
- case 1:
+ switch (WP(w,news_d).ni->string_id & 0xF0) {
+ case NB_BTROUBLE:
DrawStringCentered(w->width>>1, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, 0);
SetDParam(0, p->name_1);
@@ -483,7 +483,7 @@ void DrawNewsBankrupcy(Window *w)
w->width - 101);
break;
- case 2: {
+ case NB_BMERGER: {
int32 price;
DrawStringCentered(w->width>>1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, 0);
@@ -500,7 +500,7 @@ void DrawNewsBankrupcy(Window *w)
break;
}
- case 3:
+ case NB_BBANKRUPT:
DrawStringCentered(w->width>>1, 1, STR_705C_BANKRUPT, 0);
COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2);
DrawStringMultiCenter(
@@ -510,7 +510,7 @@ void DrawNewsBankrupcy(Window *w)
w->width - 101);
break;
- case 4:
+ case NB_BNEWCOMPANY:
DrawStringCentered(w->width>>1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
@@ -529,16 +529,16 @@ void DrawNewsBankrupcy(Window *w)
StringID GetNewsStringBankrupcy(const NewsItem *ni)
{
- const Player *p = GetPlayer(ni->string_id & 0xF);
+ const Player *p = GetPlayer(GB(ni->string_id, 0, 4));
- switch (ni->string_id >> 4) {
- case 1:
+ switch (ni->string_id & 0xF0) {
+ case NB_BTROUBLE:
SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE);
SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED);
SetDParam(2, p->name_1);
SetDParam(3, p->name_2);
return STR_02B6;
- case 2:
+ case NB_BMERGER:
SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER);
SetDParam(1, STR_705A_HAS_BEEN_SOLD_TO_FOR);
COPY_IN_DPARAM(2,ni->params, 2);
@@ -546,12 +546,12 @@ StringID GetNewsStringBankrupcy(const NewsItem *ni)
SetDParam(5, p->name_2);
COPY_IN_DPARAM(6,ni->params + 2, 1);
return STR_02B6;
- case 3:
+ case NB_BBANKRUPT:
SetDParam(0, STR_705C_BANKRUPT);
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY);
COPY_IN_DPARAM(2,ni->params, 2);
return STR_02B6;
- case 4:
+ case NB_BNEWCOMPANY:
SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED);
SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR);
SetDParam(2, p->name_1);
@@ -1501,7 +1501,7 @@ static void DoAcquireCompany(Player *p)
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
SetDParam(2, p->bankrupt_value);
- AddNewsItem( (StringID)(_current_player + 16*2), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
+ AddNewsItem( (StringID)(_current_player | NB_BMERGER), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
// original code does this a little bit differently
pi = p->index;
diff --git a/news.h b/news.h
index b820fde27..d2024b844 100644
--- a/news.h
+++ b/news.h
@@ -30,7 +30,7 @@ void InitNewsItemStructs(void);
VARDEF NewsItem _statusbar_news_item;
-enum {
+enum NewsType {
NT_ARRIVAL_PLAYER = 0,
NT_ARRIVAL_OTHER = 1,
NT_ACCIDENT = 2,
@@ -44,27 +44,34 @@ enum {
};
enum NewsMode {
- NM_SMALL = 0,
- NM_NORMAL = 1,
- NM_THIN = 2,
- NM_CALLBACK = 3,
+ NM_SMALL = 0, ///< Show only a small popup informing us about vehicle age for example
+ NM_NORMAL = 1, ///< Show a simple news message (height 170 pixels)
+ NM_THIN = 2, ///< Show a simple news message (height 130 pixels)
+ NM_CALLBACK = 3, ///< Do some special processing before displaying news message. Which callback to call is in NewsCallback
};
enum NewsFlags {
- NF_VIEWPORT = 0x01,
- NF_TILE = 0x04,
- NF_VEHICLE = 0x08,
- NF_FORCE_BIG = 0x10,
- NF_NOEXPIRE = 0x20,
- NF_INCOLOR = 0x40,
+ NF_VIEWPORT = (1 << 1), ///< Does the news message have a viewport? (ingame picture of happening)
+ NF_TILE = (1 << 2), ///< When clicked on the news message scroll to a given tile? Tile is in data_a/data_b
+ NF_VEHICLE = (1 << 3), ///< When clicked on the message scroll to the vehicle? VehicleID is in data_a
+ NF_FORCE_BIG = (1 << 4), ///< Force the appearance of a news message if it has already been shown (internal)
+ NF_NOEXPIRE = (1 << 5), ///< Some flag that I think is already deprecated
+ NF_INCOLOR = (1 << 6), ///< Show the newsmessage in colour, otherwise it defaults to black & white
};
-enum {
- DNC_TRAINAVAIL = 0,
- DNC_ROADAVAIL = 1,
- DNC_SHIPAVAIL = 2,
- DNC_AIRCRAFTAVAIL = 3,
- DNC_BANKRUPCY = 4,
+enum NewsCallback {
+ DNC_TRAINAVAIL = 0, ///< Show new train available message. StringID is EngineID
+ DNC_ROADAVAIL = 1, ///< Show new road vehicle available message. StringID is EngineID
+ DNC_SHIPAVAIL = 2, ///< Show new ship available message. StringID is EngineID
+ DNC_AIRCRAFTAVAIL = 3, ///< Show new aircraft available message. StringID is EngineID
+ DNC_BANKRUPCY = 4, ///< Show bankrupcy message. StringID is PlayerID (0-3) and NewsBankrupcy (4-7)
+};
+
+enum NewsBankrupcy {
+ NB_BTROUBLE = (1 << 4), ///< Company is in trouble (warning)
+ NB_BMERGER = (2 << 4), ///< Company has been bought by another company
+ NB_BBANKRUPT = (3 << 4), ///< Company has gone bankrupt
+ NB_BNEWCOMPANY = (4 << 4), ///< A new company has been started
};
/**
diff --git a/news_gui.c b/news_gui.c
index 79f697927..c3a777a5d 100644
--- a/news_gui.c
+++ b/news_gui.c
@@ -228,6 +228,27 @@ static byte increaseIndex(byte i)
return i;
}
+/** Add a new newsitem to be shown.
+ * @param string String to display, can have special values based on parameter 'flags'
+ * @param flags various control bits that will show various news-types. See macro NEWS_FLAGS()
+ * @param data_a news-specific value based on news type
+ * @param data_b news-specific value based on news type
+ * @note flags exists of 4 byte-sized extra parameters.<br/>
+ * 1. 0 - 7 display_mode, any of the NewsMode enums (NM_)<br/>
+ * 2. 8 - 15 news flags, any of the NewsFlags enums (NF_) NF_NOEXPIRE and
+ * NF_INCOLOR are set automatically if needed<br/>
+ * 3. 16 - 23 news category, any of the NewsType enums (NT_)<br/>
+ * 4. 24 - 31 news callback function, any of the NewsCallback enums (DNC_)<br/>
+ * If the display mode is NM_CALLBACK special news is shown and parameter
+ * stringid has a special meaning.<br/>
+ * DNC_TRAINAVAIL, DNC_ROADAVAIL, DNC_SHIPAVAIL, DNC_AIRCRAFTAVAIL: StringID is
+ * the index of the engine that is shown<br/>
+ * DNC_BANKRUPCY: bytes 0-3 of StringID contains the player that is in trouble,
+ * and 4-7 contains what kind of bankrupcy message is shown, NewsBankrupcy enum (NB_)<br/>
+ * @see NewsMode
+ * @see NewsFlags
+ * @see NewsType
+ * @see NewsCallback */
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
{
NewsItem *ni;
diff --git a/players.c b/players.c
index d5c2d7f78..720b5cd70 100644
--- a/players.c
+++ b/players.c
@@ -343,7 +343,7 @@ set_name:;
if (!IsHumanPlayer(p->index)) {
SetDParam(0, t->index);
- AddNewsItem(p->index + (4 << 4), NEWS_FLAGS(NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY), p->last_build_coordinate, 0);
+ AddNewsItem((StringID)(p->index | NB_BNEWCOMPANY), NEWS_FLAGS(NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY), p->last_build_coordinate, 0);
}
return;
}
@@ -913,7 +913,7 @@ int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Show the bankrupt news */
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
- AddNewsItem( (StringID)(p->index + 16*3), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
+ AddNewsItem( (StringID)(p->index | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
/* Remove the company */
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
diff --git a/station_cmd.c b/station_cmd.c
index abf54a413..373f30a90 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -539,7 +539,7 @@ static void ShowRejectOrAcceptNews(const Station *st, uint32 items, StringID msg
SetDParam(2, GB(items, 16, 16));
SetDParam(1, GB(items, 0, 16));
SetDParam(0, st->index);
- AddNewsItem(msg + ((items >> 16)?1:0), NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0);
+ AddNewsItem(msg + (GB(items, 16, 16) ? 1 : 0), NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0);
}
}