summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2004-12-19 09:39:19 +0000
committerdominik <dominik@openttd.org>2004-12-19 09:39:19 +0000
commitbb5dca016ddbd7d21373c052cefa96f894e1e2fc (patch)
tree67065372ddab844b0eca1fb7b664f60f5c1d957a
parentcf89cb12cd49333fba3b72001f52f1032c036f62 (diff)
downloadopenttd-bb5dca016ddbd7d21373c052cefa96f894e1e2fc.tar.xz
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
-rw-r--r--news.h12
-rw-r--r--news_gui.c13
-rw-r--r--train_cmd.c15
3 files changed, 34 insertions, 6 deletions
diff --git a/news.h b/news.h
index 076f1b569..858d3923a 100644
--- a/news.h
+++ b/news.h
@@ -14,20 +14,26 @@ struct NewsItem {
TileIndex data_b;
uint32 params[10];
+
+ /* The validation functions for news items get called immediately
+ * before the news are supposed to be shown. If this funcion returns
+ * false, the news item won't be displayed. */
+ bool (*isValid) ( uint data_a, uint data_b );
};
+typedef bool ValidationProc ( uint data_a, uint data_b );
+typedef void DrawNewsCallbackProc(Window *w);
+typedef StringID GetNewsStringCallbackProc(NewsItem *ni);
#define NEWS_FLAGS(mode,flag,type,cb) ((cb)<<24 | (type)<<16 | (flag)<<8 | (mode))
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b);
+void AddValidatedNewsItem(StringID string, uint32 flags, uint data_a, uint data_b, ValidationProc *validation);
void NewsLoop(void);
void DrawNewsBorder(const Window *w);
void InitNewsItemStructs(void);
VARDEF NewsItem _statusbar_news_item;
-typedef void DrawNewsCallbackProc(Window *w);
-typedef StringID GetNewsStringCallbackProc(NewsItem *ni);
-
enum {
NT_ARRIVAL_PLAYER = 0,
NT_ARRIVAL_OTHER = 1,
diff --git a/news_gui.c b/news_gui.c
index af804f226..b9f7e8286 100644
--- a/news_gui.c
+++ b/news_gui.c
@@ -210,7 +210,6 @@ byte increaseIndex(byte i)
return i;
}
-
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
{
NewsItem *ni;
@@ -257,6 +256,14 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
w->vscroll.count = _total_news;
}
+/* To add a news item with an attached validation function. This validation function
+ * makes sure that the news item is not outdated when the newspaper pops up. */
+void AddValidatedNewsItem(StringID string, uint32 flags, uint data_a, uint data_b, ValidationProc validation)
+{
+ AddNewsItem(string, flags, data_a, data_b);
+ _news_items[_latest_news].isValid = validation;
+}
+
// don't show item if it's older than x days
static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
@@ -421,6 +428,10 @@ static void MoveToNexItem(void)
if (_date - _news_items_age[ni->type] > ni->date)
return;
+ // execute the validation function to see if this item is still valid
+ if ( ni->isValid != NULL && !ni->isValid(ni->data_a, ni->data_b) )
+ return;
+
// show newspaper or send to ticker?
if (!HASBIT(_news_display_opt, ni->type) && !(ni->flags & NF_FORCE_BIG))
ShowTicker(ni);
diff --git a/train_cmd.c b/train_cmd.c
index d2bab6abf..389141d46 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -2546,6 +2546,16 @@ void Train_Tick(Vehicle *v)
static const byte _depot_track_ind[4] = {0,1,0,1};
+// Validation for the news item "Train is waiting in depot"
+bool ValidateTrainInDepot( uint data_a, uint data_b )
+{
+ Vehicle *v = &_vehicles[data_a];
+ if (v->u.rail.track == 0x80 && (v->vehstatus | VS_STOPPED))
+ return true;
+ else
+ return false;
+}
+
void TrainEnterDepot(Vehicle *v, uint tile)
{
SetSignalsOnBothDir(tile, _depot_track_ind[_map5[tile]&3]);
@@ -2580,11 +2590,12 @@ void TrainEnterDepot(Vehicle *v, uint tile)
v->vehstatus |= VS_STOPPED;
if (v->owner == _local_player) {
SetDParam(0, v->unitnumber);
- AddNewsItem(
+ AddValidatedNewsItem(
STR_8814_TRAIN_IS_WAITING_IN_DEPOT,
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0),
v->index,
- 0);
+ 0,
+ ValidateTrainInDepot);
}
}
}