src/texteff.cpp
author rubidium
Wed, 09 Jan 2008 09:45:45 +0000
changeset 8720 4e60c30e2006
parent 8710 52015340050c
child 8721 b7971ad9bdd9
permissions -rw-r--r--
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6700
diff changeset
     3
/** @file texteff.cpp */
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6700
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8610
diff changeset
     7
#include "tile_cmd.h"
6949
72d11a1e1e60 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6918
diff changeset
     8
#include "landscape.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "saveload.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    11
#include "console.h"
2153
91e89aa8c299 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2062
diff changeset
    12
#include "variables.h"
2218
abd47ef7d902 (svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents: 2186
diff changeset
    13
#include "table/sprites.h"
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7374
diff changeset
    14
#include "blitter/factory.hpp"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    15
#include <stdarg.h> /* va_list */
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
    16
#include "texteff.hpp"
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7502
diff changeset
    17
#include "video/video_driver.hpp"
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8245
diff changeset
    18
#include "transparency.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8609
diff changeset
    19
#include "strings_func.h"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8617
diff changeset
    20
#include "core/alloc_func.hpp"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8627
diff changeset
    21
#include "date_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8626
diff changeset
    22
#include "functions.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    24
enum {
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5919
diff changeset
    25
	MAX_TEXTMESSAGE_LENGTH = 200,
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
    26
	INIT_NUM_TEXT_MESSAGES =  20,
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    27
	MAX_CHAT_MESSAGES      =  10,
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    28
};
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    29
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    30
struct TextEffect {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	StringID string_id;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    32
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    33
	int32 y;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    34
	int32 right;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    35
	int32 bottom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	uint16 duration;
7502
71f5d2c6a605 (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 7494
diff changeset
    37
	uint64 params_1;
71f5d2c6a605 (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 7494
diff changeset
    38
	uint64 params_2;
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
    39
	TextEffectMode mode;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    40
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    42
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    43
struct ChatMessage {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    44
	char message[MAX_TEXTMESSAGE_LENGTH];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    45
	uint16 color;
4363
3a3a2a3dda00 (svn r6078) -Fix: forgot one uint16 -> Date conversion. Tnx to #openttdcoop team for detecting and Rubidium for finding the cause.
truelight
parents: 4261
diff changeset
    46
	Date end_date;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    47
};
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    48
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    49
/* used for text effects */
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
    50
static TextEffect *_text_effect_list = NULL;
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    51
static uint16 _num_text_effects = INIT_NUM_TEXT_MESSAGES;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    53
/* used for chat window */
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    54
static ChatMessage _chatmsg_list[MAX_CHAT_MESSAGES];
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    55
static bool _chatmessage_dirty = false;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    56
static bool _chatmessage_visible = false;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    57
4956
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    58
/* The chatbox grows from the bottom so the coordinates are pixels from
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    59
 * the left and pixels from the bottom. The height is the maximum height */
8617
931e0970d509 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8615
diff changeset
    60
static const PointDimension _chatmsg_box = {10, 30, 500, 150};
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    61
static uint8 _chatmessage_backup[150 * 500 * 6]; // (height * width)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    62
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    63
static inline uint GetChatMessageCount()
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    64
{
4959
828f9223446d (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
    65
	uint i;
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    66
4959
828f9223446d (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
    67
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    68
		if (_chatmsg_list[i].message[0] == '\0') break;
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    69
	}
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    70
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    71
	return i;
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    72
}
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    73
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    74
/* Add a text message to the 'chat window' to be shown
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    75
 * @param color The colour this message is to be shown in
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    76
 * @param duration The duration of the chat message in game-days
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    77
 * @param message message itself in printf() style */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    78
void CDECL AddChatMessage(uint16 color, uint8 duration, const char *message, ...)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    79
{
2455
8d6d990d55f8 (svn r2981) Remove a no-op
tron
parents: 2424
diff changeset
    80
	char buf[MAX_TEXTMESSAGE_LENGTH];
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    81
	const char *bufp;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    82
	va_list va;
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    83
	uint msg_count;
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    84
	uint16 lines;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    85
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    86
	va_start(va, message);
2373
f06403621870 (svn r2899) -Fix: Several format string vulnerabilities and buffer overflows in the network code
tron
parents: 2295
diff changeset
    87
	vsnprintf(buf, lengthof(buf), message, va);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    88
	va_end(va);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    89
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5919
diff changeset
    90
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5919
diff changeset
    91
	Utf8TrimString(buf, MAX_TEXTMESSAGE_LENGTH);
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5919
diff changeset
    92
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    93
	/* Force linebreaks for strings that are too long */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    94
	lines = GB(FormatStringLinebreaks(buf, _chatmsg_box.width - 8), 0, 16) + 1;
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    95
	if (lines >= MAX_CHAT_MESSAGES) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    96
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
    97
	msg_count = GetChatMessageCount();
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    98
	/* We want to add more chat messages than there is free space for, remove 'old' */
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    99
	if (lines > MAX_CHAT_MESSAGES - msg_count) {
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   100
		int i = lines - (MAX_CHAT_MESSAGES - msg_count);
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   101
		memmove(&_chatmsg_list[0], &_chatmsg_list[i], sizeof(_chatmsg_list[0]) * (msg_count - i));
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   102
		msg_count = MAX_CHAT_MESSAGES - lines;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   103
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   104
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   105
	for (bufp = buf; lines != 0; lines--) {
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   106
		ChatMessage *cmsg = &_chatmsg_list[msg_count++];
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   107
		ttd_strlcpy(cmsg->message, bufp, sizeof(cmsg->message));
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   108
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   109
		/* The default colour for a message is player colour. Replace this with
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   110
		 * white for any additional lines */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   111
		cmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   112
		cmsg->end_date = _date + duration;
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   113
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   114
		bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   115
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   116
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   117
	_chatmessage_dirty = true;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   118
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   119
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   120
void InitChatMessage()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   121
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   122
	uint i;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   123
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   124
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   125
		_chatmsg_list[i].message[0] = '\0';
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   126
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   127
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   128
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   129
/** Hide the chatbox */
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   130
void UndrawChatMessage()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   131
{
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   132
	if (_chatmessage_visible) {
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7374
diff changeset
   133
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   134
		/* Sometimes we also need to hide the cursor
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   135
		 *   This is because both textmessage and the cursor take a shot of the
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   136
		 *   screen before drawing.
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   137
		 *   Now the textmessage takes his shot and paints his data before the cursor
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   138
		 *   does, so in the shot of the cursor is the screen-data of the textmessage
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   139
		 *   included when the cursor hangs somewhere over the textmessage. To
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   140
		 *   avoid wrong repaints, we undraw the cursor in that case, and everything
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   141
		 *   looks nicely ;)
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   142
		 * (and now hope this story above makes sense to you ;))
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   143
		 */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   144
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   145
		if (_cursor.visible) {
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   146
			if (_cursor.draw_pos.x + _cursor.draw_size.x >= _chatmsg_box.x &&
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   147
				_cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width &&
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   148
				_cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height &&
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   149
				_cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   150
				UndrawMouseCursor();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   151
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   152
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   153
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   154
		int x      = _chatmsg_box.x;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   155
		int y      = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   156
		int width  = _chatmsg_box.width;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   157
		int height = _chatmsg_box.height;
6692
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   158
		if (y < 0) {
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   159
			height = max(height + y, min(_chatmsg_box.height, _screen.height));
6692
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   160
			y = 0;
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   161
		}
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   162
		if (x + width >= _screen.width) {
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   163
			width = _screen.width - x;
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   164
		}
6700
0cee66ecb04a (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6692
diff changeset
   165
		if (width <= 0 || height <= 0) return;
6692
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   166
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   167
		_chatmessage_visible = false;
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   168
		/* Put our 'shot' back to the screen */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   169
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   170
		/* And make sure it is updated next time */
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7502
diff changeset
   171
		_video_driver->MakeDirty(x, y, width, height);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   172
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   173
		_chatmessage_dirty = true;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   174
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   175
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   176
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6700
diff changeset
   177
/** Check if a message is expired every day */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   178
void ChatMessageDailyLoop()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   179
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   180
	uint i;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   181
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   182
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   183
		ChatMessage *cmsg = &_chatmsg_list[i];
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   184
		if (cmsg->message[0] == '\0') continue;
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   185
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   186
		/* Message has expired, remove from the list */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   187
		if (cmsg->end_date < _date) {
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   188
			/* Move the remaining messages over the current message */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   189
			if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   190
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   191
			/* Mark the last item as empty */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   192
			_chatmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0';
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   193
			_chatmessage_dirty = true;
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   194
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   195
			/* Go one item back, because we moved the array 1 to the left */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   196
			i--;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   197
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   198
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   199
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   200
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   201
/** Draw the chat message-box */
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   202
void DrawChatMessage()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   203
{
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7374
diff changeset
   204
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   205
	if (!_chatmessage_dirty) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   206
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   207
	/* First undraw if needed */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   208
	UndrawChatMessage();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   209
4959
828f9223446d (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
   210
	if (_iconsole_mode == ICONSOLE_FULL) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   211
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   212
	/* Check if we have anything to draw at all */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   213
	uint count = GetChatMessageCount();
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   214
	if (count == 0) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   215
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   216
	int x      = _chatmsg_box.x;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   217
	int y      = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   218
	int width  = _chatmsg_box.width;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   219
	int height = _chatmsg_box.height;
6692
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   220
	if (y < 0) {
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   221
		height = max(height + y, min(_chatmsg_box.height, _screen.height));
6692
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   222
		y = 0;
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   223
	}
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   224
	if (x + width >= _screen.width) {
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   225
		width = _screen.width - x;
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   226
	}
6700
0cee66ecb04a (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6692
diff changeset
   227
	if (width <= 0 || height <= 0) return;
0cee66ecb04a (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6692
diff changeset
   228
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   229
	assert(blitter->BufferSize(width, height) < (int)sizeof(_chatmessage_backup));
7481
699607d457a0 (svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents: 7433
diff changeset
   230
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   231
	/* Make a copy of the screen as it is before painting (for undraw) */
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   232
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   233
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   234
	_cur_dpi = &_screen; // switch to _screen painting
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   235
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   236
	/* Paint a half-transparent box behind the chat messages */
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   237
	GfxFillRect(
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   238
			_chatmsg_box.x,
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   239
			_screen.height - _chatmsg_box.y - count * 13 - 2,
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   240
			_chatmsg_box.x + _chatmsg_box.width - 1,
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   241
			_screen.height - _chatmsg_box.y - 2,
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   242
			PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE) // black, but with some alpha for background
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   243
		);
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   244
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   245
	/* Paint the chat messages starting with the lowest at the bottom */
6692
983dbcb48cac (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6574
diff changeset
   246
	for (uint y = 13; count-- != 0; y += 13) {
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   247
		DoDrawString(_chatmsg_list[count].message, _chatmsg_box.x + 3, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].color);
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6949
diff changeset
   248
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   249
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   250
	/* Make sure the data is updated next flush */
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7502
diff changeset
   251
	_video_driver->MakeDirty(x, y, width, height);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   252
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   253
	_chatmessage_visible = true;
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7666
diff changeset
   254
	_chatmessage_dirty = false;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   255
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   256
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   257
/* Text Effects */
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   258
/**
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   259
 * Mark the area of the text effect as dirty.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   260
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   261
 * This function marks the area of a text effect as dirty for repaint.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   262
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   263
 * @param te The TextEffect to mark the area dirty
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   264
 * @ingroup dirty
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8031
diff changeset
   265
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
static void MarkTextEffectAreaDirty(TextEffect *te)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
{
8031
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   268
	/* Width and height of the text effect are doubled, so they are correct in both zoom out levels 1x and 2x. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
		te->x,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
		te->y - 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
		(te->right - te->x)*2 + te->x + 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
		(te->bottom - (te->y - 1)) * 2 + (te->y - 1) + 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   277
TextEffectID AddTextEffect(StringID msg, int x, int y, uint16 duration, TextEffectMode mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
	TextEffect *te;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	int w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	char buffer[100];
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   282
	TextEffectID i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   284
	if (_game_mode == GM_MENU) return INVALID_TE_ID;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   285
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   286
	/* Look for a free spot in the text effect array */
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   287
	for (i = 0; i < _num_text_effects; i++) {
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   288
		if (_text_effect_list[i].string_id == INVALID_STRING_ID) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   291
	/* If there is none found, we grow the array */
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   292
	if (i == _num_text_effects) {
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   293
		_num_text_effects += 25;
8533
a9b708fe4a00 (svn r11597) -Change: replace all remaining instances of (re|m|c)alloc with (Re|M|C)allocT and add a check for out-of-memory situations to the *allocT functions.
rubidium
parents: 8345
diff changeset
   294
		_text_effect_list = ReallocT<TextEffect>(_text_effect_list, _num_text_effects);
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   295
		for (; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   296
		i = _num_text_effects - 1;
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   297
	}
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   298
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   299
	te = &_text_effect_list[i];
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   300
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   301
	/* Start defining this object */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	te->string_id = msg;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	te->duration = duration;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	te->y = y - 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	te->bottom = y + 5;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 425
diff changeset
   306
	te->params_1 = GetDParam(0);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 425
diff changeset
   307
	te->params_2 = GetDParam(4);
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   308
	te->mode = mode;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4609
diff changeset
   310
	GetString(buffer, msg, lastof(buffer));
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4469
diff changeset
   311
	w = GetStringBoundingBox(buffer).width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	te->x = x - (w >> 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	te->right = x + (w >> 1) - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	MarkTextEffectAreaDirty(te);
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   316
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   317
	return i;
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   318
}
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   319
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   320
void UpdateTextEffect(TextEffectID te_id, StringID msg)
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   321
{
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   322
	assert(te_id < _num_text_effects);
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   323
	TextEffect *te;
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   324
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   325
	/* Update details */
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   326
	te = &_text_effect_list[te_id];
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   327
	te->string_id = msg;
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   328
	te->params_1 = GetDParam(0);
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   329
	te->params_2 = GetDParam(4);
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   330
8031
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   331
	/* Update width of text effect */
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   332
	char buffer[100];
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   333
	GetString(buffer, msg, lastof(buffer));
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   334
	int w = GetStringBoundingBox(buffer).width;
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   335
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   336
	/* Only allow to make it broader, so it completely covers the old text. That avoids remnants of the old text. */
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   337
	int right_new = te->x + w;
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   338
	if (te->right < right_new) te->right = right_new;
65a6e355c493 (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7950
diff changeset
   339
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   340
	MarkTextEffectAreaDirty(te);
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   341
}
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   342
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   343
void RemoveTextEffect(TextEffectID te_id)
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   344
{
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   345
	assert(te_id < _num_text_effects);
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   346
	TextEffect *te;
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   347
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   348
	te = &_text_effect_list[te_id];
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   349
	MarkTextEffectAreaDirty(te);
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   350
	te->string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
static void MoveTextEffect(TextEffect *te)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
{
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   355
	/* Never expire for duration of 0xFFFF */
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   356
	if (te->duration == 0xFFFF) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	if (te->duration < 8) {
2470
a3b2f1f8ab3d (svn r2996) 0xFFFF -> INVALID_STRING_ID
tron
parents: 2458
diff changeset
   358
		te->string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
	} else {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   360
		te->duration -= 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		te->y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		te->bottom--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	MarkTextEffectAreaDirty(te);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6541
diff changeset
   367
void MoveAllTextEffects()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
{
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   369
	for (TextEffectID i = 0; i < _num_text_effects; i++) {
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   370
		TextEffect *te = &_text_effect_list[i];
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   371
		if (te->string_id != INVALID_STRING_ID && te->mode == TE_RISING) MoveTextEffect(te);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6541
diff changeset
   375
void InitTextEffects()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
{
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   377
	if (_text_effect_list == NULL) _text_effect_list = MallocT<TextEffect>(_num_text_effects);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   379
	for (TextEffectID i = 0; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
void DrawTextEffects(DrawPixelInfo *dpi)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
{
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   384
	switch (dpi->zoom) {
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6988
diff changeset
   385
		case ZOOM_LVL_NORMAL:
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   386
			for (TextEffectID i = 0; i < _num_text_effects; i++) {
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   387
				TextEffect *te = &_text_effect_list[i];
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   388
				if (te->string_id != INVALID_STRING_ID &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   389
						dpi->left <= te->right &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   390
						dpi->top  <= te->bottom &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   391
						dpi->left + dpi->width  > te->x &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   392
						dpi->top  + dpi->height > te->y) {
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8245
diff changeset
   393
					if (te->mode == TE_RISING || (_patches.loading_indicators && !IsTransparencySet(TO_LOADING))) {
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   394
						AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2);
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   395
					}
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   396
				}
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   397
			}
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   398
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6988
diff changeset
   400
		case ZOOM_LVL_OUT_2X:
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   401
			for (TextEffectID i = 0; i < _num_text_effects; i++) {
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   402
				TextEffect *te = &_text_effect_list[i];
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   403
				if (te->string_id != INVALID_STRING_ID &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   404
						dpi->left <= te->right  * 2 - te->x &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   405
						dpi->top  <= te->bottom * 2 - te->y &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   406
						dpi->left + dpi->width  > te->x &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   407
						dpi->top  + dpi->height > te->y) {
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8245
diff changeset
   408
					if (te->mode == TE_RISING || (_patches.loading_indicators && !IsTransparencySet(TO_LOADING))) {
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   409
						AddStringToDraw(te->x, te->y, (StringID)(te->string_id - 1), te->params_1, te->params_2);
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7484
diff changeset
   410
					}
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   411
				}
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   412
			}
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   413
			break;
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6988
diff changeset
   414
7122
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
   415
		case ZOOM_LVL_OUT_4X:
7149
ba2798e551a3 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 7122
diff changeset
   416
		case ZOOM_LVL_OUT_8X:
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6988
diff changeset
   417
			break;
7122
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
   418
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
   419
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   423
/** The table/list with animated tiles. */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   424
TileIndex *_animated_tile_list = NULL;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   425
/** The number of animated tiles in the current state. */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   426
uint _animated_tile_count = 0;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   427
/** The number of slots for animated tiles allocated currently. */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   428
static uint _animated_tile_allocated = 0;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   429
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   430
/**
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   431
 * Removes the given tile from the animated tile table.
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   432
 * @param tile the tile to remove
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   433
 */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   434
void DeleteAnimatedTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
{
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   436
	for (TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   437
		if (tile == *ti) {
8245
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   438
			/* Remove the hole
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   439
			 * The order of the remaining elements must stay the same, otherwise the animation loop
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   440
			 * may miss a tile; that's why we must use memmove instead of just moving the last element.
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   441
			 */
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   442
			memmove(ti, ti + 1, (_animated_tile_list + _animated_tile_count - (ti + 1)) * sizeof(*ti));
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   443
			_animated_tile_count--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
			return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   446
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   450
/**
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   451
 * Add the given tile to the animated tile table (if it does not exist
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   452
 * on that table yet). Also increases the size of the table if necessary.
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   453
 * @param tile the tile to make animated
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   454
 */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   455
void AddAnimatedTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
{
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   457
	MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   459
	for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   460
		if (tile == *ti) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   461
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   463
	/* Table not large enough, so make it larger */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   464
	if (_animated_tile_count == _animated_tile_allocated) {
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   465
		_animated_tile_allocated *= 2;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   466
		_animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, _animated_tile_allocated);
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   467
	}
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   468
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   469
	_animated_tile_list[_animated_tile_count] = tile;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   470
	_animated_tile_count++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   473
/**
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   474
 * Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them.
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   475
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6541
diff changeset
   476
void AnimateAnimatedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
{
8245
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   478
	const TileIndex *ti = _animated_tile_list;
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   479
	while (ti < _animated_tile_list + _animated_tile_count) {
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   480
		const TileIndex curr = *ti;
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   481
		AnimateTile(curr);
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   482
		/* During the AnimateTile call, DeleteAnimatedTile could have been called,
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   483
		 * deleting an element we've already processed and pushing the rest one
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   484
		 * slot to the left. We can detect this by checking whether the index
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   485
		 * in the current slot has changed - if it has, an element has been deleted,
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   486
		 * and we should process the current slot again instead of going forward.
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   487
		 * NOTE: this will still break if more than one animated tile is being
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   488
		 *       deleted during the same AnimateTile call, but no code seems to
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   489
		 *       be doing this anyway.
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   490
		 */
dc1637bc2c56 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 8190
diff changeset
   491
		if (*ti == curr) ++ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   495
/**
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   496
 * Initialize all animated tile variables to some known begin point
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   497
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6541
diff changeset
   498
void InitializeAnimatedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
{
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   500
	_animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, 256);
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   501
	_animated_tile_count = 0;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   502
	_animated_tile_allocated = 256;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   505
/**
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   506
 * Save the ANIT chunk.
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   507
 */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   508
static void Save_ANIT()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
{
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   510
	SlSetLength(_animated_tile_count * sizeof(*_animated_tile_list));
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   511
	SlArray(_animated_tile_list, _animated_tile_count, SLE_UINT32);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   514
/**
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   515
 * Load the ANIT chunk; the chunk containing the animated tiles.
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   516
 */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   517
static void Load_ANIT()
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   518
{
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   519
	/* Before version 80 we did NOT have a variable length animated tile table */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   520
	if (CheckSavegameVersion(80)) {
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   521
		/* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   522
		SlArray(_animated_tile_list, 256, CheckSavegameVersion(6) ? (SLE_FILE_U16 | SLE_VAR_U32) : SLE_UINT32);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   524
		for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   525
			if (_animated_tile_list[_animated_tile_count] == 0) break;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   526
		}
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   527
		return;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   528
	}
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   529
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   530
	_animated_tile_count = SlGetFieldLength() / sizeof(*_animated_tile_list);
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   531
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   532
	/* Determine a nice rounded size for the amount of allocated tiles */
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   533
	_animated_tile_allocated = 256;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   534
	while (_animated_tile_allocated < _animated_tile_count) _animated_tile_allocated *= 2;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   535
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   536
	_animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, _animated_tile_allocated);
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   537
	SlArray(_animated_tile_list, _animated_tile_count, SLE_UINT32);
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   538
}
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   539
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   540
/**
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   541
 * "Definition" imported by the saveload code to be able to load and save
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   542
 * the animated tile table.
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   543
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   544
extern const ChunkHandler _animated_tile_chunk_handlers[] = {
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8041
diff changeset
   545
	{ 'ANIT', Save_ANIT, Load_ANIT, CH_RIFF | CH_LAST},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
};