src/texteff.cpp
author smatz
Sat, 05 Apr 2008 12:30:48 +0000
changeset 8831 d598d3d0380a
parent 8270 e7c342f6b14c
child 9005 d6b0e0a54ef2
permissions -rw-r--r--
(svn r12579) -Change: reset cursor when the Plant trees GUI is opened
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6374
diff changeset
     3
/** @file texteff.cpp */
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6374
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8114
diff changeset
     7
#include "tile_cmd.h"
6453
226bcddeba32 (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: 6422
diff changeset
     8
#include "landscape.h"
8225
cd84a95b6630 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8214
diff changeset
     9
#include "gfx_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "saveload.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    11
#include "console.h"
2153
ecfc674410b4 (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"
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
    13
#include "blitter/factory.hpp"
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
    14
#include "texteff.hpp"
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7006
diff changeset
    15
#include "video/video_driver.hpp"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7749
diff changeset
    16
#include "transparency.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8113
diff changeset
    17
#include "strings_func.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8121
diff changeset
    18
#include "core/alloc_func.hpp"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8131
diff changeset
    19
#include "date_func.h"
8131
160939e24ed3 (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: 8130
diff changeset
    20
#include "functions.h"
8225
cd84a95b6630 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8214
diff changeset
    21
#include "viewport_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    22
#include "settings_type.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8225
diff changeset
    24
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8225
diff changeset
    25
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8225
diff changeset
    26
#include <stdarg.h> /* va_list */
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8225
diff changeset
    27
5428
00fab4aeff78 (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: 5427
diff changeset
    28
enum {
6215
bbd141b026b5 (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: 5668
diff changeset
    29
	MAX_TEXTMESSAGE_LENGTH = 200,
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
    30
	INIT_NUM_TEXT_MESSAGES =  20,
5428
00fab4aeff78 (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: 5427
diff changeset
    31
	MAX_CHAT_MESSAGES      =  10,
00fab4aeff78 (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: 5427
diff changeset
    32
};
00fab4aeff78 (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: 5427
diff changeset
    33
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    34
struct TextEffect {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	StringID string_id;
849
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    36
	int32 x;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    37
	int32 y;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    38
	int32 right;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    39
	int32 bottom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	uint16 duration;
7006
bfa3974da32b (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: 6998
diff changeset
    41
	uint64 params_1;
bfa3974da32b (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: 6998
diff changeset
    42
	uint64 params_2;
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
    43
	TextEffectMode mode;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    44
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    46
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    47
struct ChatMessage {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    48
	char message[MAX_TEXTMESSAGE_LENGTH];
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    49
	uint16 color;
4363
8a38cd70dab9 (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
    50
	Date end_date;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    51
};
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    52
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    53
/* used for text effects */
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
    54
static TextEffect *_text_effect_list = NULL;
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    55
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
    56
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    57
/* used for chat window */
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    58
static ChatMessage _chatmsg_list[MAX_CHAT_MESSAGES];
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    59
static bool _chatmessage_dirty = false;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    60
static bool _chatmessage_visible = false;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    61
4956
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    62
/* The chatbox grows from the bottom so the coordinates are pixels from
49ecd2a36222 (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    63
 * the left and pixels from the bottom. The height is the maximum height */
8121
3bc6351e7369 (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: 8119
diff changeset
    64
static const PointDimension _chatmsg_box = {10, 30, 500, 150};
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    65
static uint8 _chatmessage_backup[150 * 500 * 6]; // (height * width)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    66
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    67
static inline uint GetChatMessageCount()
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    68
{
4959
9a25901ce3e6 (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
    69
	uint i;
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    70
4959
9a25901ce3e6 (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
    71
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    72
		if (_chatmsg_list[i].message[0] == '\0') break;
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    73
	}
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    74
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    75
	return i;
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    76
}
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    77
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    78
/* Add a text message to the 'chat window' to be shown
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    79
 * @param color The colour this message is to be shown in
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    80
 * @param duration The duration of the chat message in game-days
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    81
 * @param message message itself in printf() style */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    82
void CDECL AddChatMessage(uint16 color, uint8 duration, const char *message, ...)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    83
{
2455
43283b066cc4 (svn r2981) Remove a no-op
tron
parents: 2424
diff changeset
    84
	char buf[MAX_TEXTMESSAGE_LENGTH];
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    85
	const char *bufp;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    86
	va_list va;
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    87
	uint msg_count;
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    88
	uint16 lines;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    89
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    90
	va_start(va, message);
2373
e073ec69bf56 (svn r2899) -Fix: Several format string vulnerabilities and buffer overflows in the network code
tron
parents: 2295
diff changeset
    91
	vsnprintf(buf, lengthof(buf), message, va);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    92
	va_end(va);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    93
6215
bbd141b026b5 (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: 5668
diff changeset
    94
bbd141b026b5 (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: 5668
diff changeset
    95
	Utf8TrimString(buf, MAX_TEXTMESSAGE_LENGTH);
bbd141b026b5 (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: 5668
diff changeset
    96
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    97
	/* Force linebreaks for strings that are too long */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
    98
	lines = GB(FormatStringLinebreaks(buf, _chatmsg_box.width - 8), 0, 16) + 1;
4957
44b747809879 (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) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   100
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   101
	msg_count = GetChatMessageCount();
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   102
	/* We want to add more chat messages than there is free space for, remove 'old' */
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   103
	if (lines > MAX_CHAT_MESSAGES - msg_count) {
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   104
		int i = lines - (MAX_CHAT_MESSAGES - msg_count);
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   105
		memmove(&_chatmsg_list[0], &_chatmsg_list[i], sizeof(_chatmsg_list[0]) * (msg_count - i));
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   106
		msg_count = MAX_CHAT_MESSAGES - lines;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   107
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   108
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   109
	for (bufp = buf; lines != 0; lines--) {
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   110
		ChatMessage *cmsg = &_chatmsg_list[msg_count++];
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   111
		ttd_strlcpy(cmsg->message, bufp, sizeof(cmsg->message));
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   112
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   113
		/* The default colour for a message is player colour. Replace this with
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   114
		 * white for any additional lines */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   115
		cmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   116
		cmsg->end_date = _date + duration;
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   117
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   118
		bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   119
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   120
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   121
	_chatmessage_dirty = true;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   122
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   123
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   124
void InitChatMessage()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   125
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   126
	uint i;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   127
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   128
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   129
		_chatmsg_list[i].message[0] = '\0';
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   130
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   131
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   132
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   133
/** Hide the chatbox */
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   134
void UndrawChatMessage()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   135
{
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   136
	if (_chatmessage_visible) {
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
   137
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
5428
00fab4aeff78 (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: 5427
diff changeset
   138
		/* Sometimes we also need to hide the cursor
00fab4aeff78 (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: 5427
diff changeset
   139
		 *   This is because both textmessage and the cursor take a shot of the
00fab4aeff78 (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: 5427
diff changeset
   140
		 *   screen before drawing.
00fab4aeff78 (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: 5427
diff changeset
   141
		 *   Now the textmessage takes his shot and paints his data before the cursor
00fab4aeff78 (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: 5427
diff changeset
   142
		 *   does, so in the shot of the cursor is the screen-data of the textmessage
00fab4aeff78 (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: 5427
diff changeset
   143
		 *   included when the cursor hangs somewhere over the textmessage. To
00fab4aeff78 (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: 5427
diff changeset
   144
		 *   avoid wrong repaints, we undraw the cursor in that case, and everything
00fab4aeff78 (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: 5427
diff changeset
   145
		 *   looks nicely ;)
00fab4aeff78 (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: 5427
diff changeset
   146
		 * (and now hope this story above makes sense to you ;))
00fab4aeff78 (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: 5427
diff changeset
   147
		 */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   148
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   149
		if (_cursor.visible) {
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   150
			if (_cursor.draw_pos.x + _cursor.draw_size.x >= _chatmsg_box.x &&
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   151
				_cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width &&
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   152
				_cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height &&
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   153
				_cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   154
				UndrawMouseCursor();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   155
			}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   156
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   157
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   158
		int x      = _chatmsg_box.x;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   159
		int y      = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   160
		int width  = _chatmsg_box.width;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   161
		int height = _chatmsg_box.height;
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   162
		if (y < 0) {
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   163
			height = max(height + y, min(_chatmsg_box.height, _screen.height));
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   164
			y = 0;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   165
		}
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   166
		if (x + width >= _screen.width) {
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   167
			width = _screen.width - x;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   168
		}
6374
0de6e30b49db (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6366
diff changeset
   169
		if (width <= 0 || height <= 0) return;
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   170
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   171
		_chatmessage_visible = false;
5428
00fab4aeff78 (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: 5427
diff changeset
   172
		/* Put our 'shot' back to the screen */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   173
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
5428
00fab4aeff78 (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: 5427
diff changeset
   174
		/* And make sure it is updated next time */
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7006
diff changeset
   175
		_video_driver->MakeDirty(x, y, width, height);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   176
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   177
		_chatmessage_dirty = true;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   178
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   179
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   180
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6374
diff changeset
   181
/** Check if a message is expired every day */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   182
void ChatMessageDailyLoop()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   183
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   184
	uint i;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   185
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   186
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   187
		ChatMessage *cmsg = &_chatmsg_list[i];
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   188
		if (cmsg->message[0] == '\0') continue;
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   189
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   190
		/* Message has expired, remove from the list */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   191
		if (cmsg->end_date < _date) {
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   192
			/* Move the remaining messages over the current message */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   193
			if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   194
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   195
			/* Mark the last item as empty */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   196
			_chatmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0';
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   197
			_chatmessage_dirty = true;
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   198
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   199
			/* Go one item back, because we moved the array 1 to the left */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   200
			i--;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   201
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   202
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   203
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   204
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   205
/** Draw the chat message-box */
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   206
void DrawChatMessage()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   207
{
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
   208
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   209
	if (!_chatmessage_dirty) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   210
5428
00fab4aeff78 (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: 5427
diff changeset
   211
	/* First undraw if needed */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   212
	UndrawChatMessage();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   213
4959
9a25901ce3e6 (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
   214
	if (_iconsole_mode == ICONSOLE_FULL) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   215
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   216
	/* Check if we have anything to draw at all */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   217
	uint count = GetChatMessageCount();
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   218
	if (count == 0) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   219
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   220
	int x      = _chatmsg_box.x;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   221
	int y      = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   222
	int width  = _chatmsg_box.width;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   223
	int height = _chatmsg_box.height;
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   224
	if (y < 0) {
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   225
		height = max(height + y, min(_chatmsg_box.height, _screen.height));
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   226
		y = 0;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   227
	}
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   228
	if (x + width >= _screen.width) {
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   229
		width = _screen.width - x;
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   230
	}
6374
0de6e30b49db (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6366
diff changeset
   231
	if (width <= 0 || height <= 0) return;
0de6e30b49db (svn r9437) -Fix (r9420): dedicated server crashed when the y part of the resolution was less than 10.
rubidium
parents: 6366
diff changeset
   232
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   233
	assert(blitter->BufferSize(width, height) < (int)sizeof(_chatmessage_backup));
6985
d50d59dca7c1 (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: 6937
diff changeset
   234
5428
00fab4aeff78 (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: 5427
diff changeset
   235
	/* Make a copy of the screen as it is before painting (for undraw) */
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   236
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   237
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   238
	_cur_dpi = &_screen; // switch to _screen painting
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   239
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   240
	/* Paint a half-transparent box behind the chat messages */
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   241
	GfxFillRect(
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   242
			_chatmsg_box.x,
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   243
			_screen.height - _chatmsg_box.y - count * 13 - 2,
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   244
			_chatmsg_box.x + _chatmsg_box.width - 1,
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   245
			_screen.height - _chatmsg_box.y - 2,
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   246
			PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE) // black, but with some alpha for background
4960
92987006dcca (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   247
		);
1595
fda318dddab5 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   248
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   249
	/* Paint the chat messages starting with the lowest at the bottom */
6366
155956db09e9 (svn r9420) -Fix [FS#701]: crashes when the chatbox would be drawn outside of the main window.
rubidium
parents: 6248
diff changeset
   250
	for (uint y = 13; count-- != 0; y += 13) {
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   251
		DoDrawString(_chatmsg_list[count].message, _chatmsg_box.x + 3, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].color);
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6453
diff changeset
   252
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   253
5428
00fab4aeff78 (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: 5427
diff changeset
   254
	/* Make sure the data is updated next flush */
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7006
diff changeset
   255
	_video_driver->MakeDirty(x, y, width, height);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   256
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   257
	_chatmessage_visible = true;
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7170
diff changeset
   258
	_chatmessage_dirty = false;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   259
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   260
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   261
/* Text Effects */
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   262
/**
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   263
 * Mark the area of the text effect as dirty.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   264
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   265
 * This function marks the area of a text effect as dirty for repaint.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   266
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   267
 * @param te The TextEffect to mark the area dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   268
 * @ingroup dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7535
diff changeset
   269
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
static void MarkTextEffectAreaDirty(TextEffect *te)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
{
7535
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   272
	/* 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
   273
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
		te->x,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
		te->y - 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
		(te->right - te->x)*2 + te->x + 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
		(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
   278
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   281
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
   282
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	TextEffect *te;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
	int w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	char buffer[100];
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   286
	TextEffectID i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   288
	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
   289
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   290
	/* Look for a free spot in the text effect array */
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   291
	for (i = 0; i < _num_text_effects; i++) {
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   292
		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
   293
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   295
	/* If there is none found, we grow the array */
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   296
	if (i == _num_text_effects) {
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   297
		_num_text_effects += 25;
8037
8aa4ace04383 (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: 7849
diff changeset
   298
		_text_effect_list = ReallocT<TextEffect>(_text_effect_list, _num_text_effects);
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   299
		for (; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   300
		i = _num_text_effects - 1;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   301
	}
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   302
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   303
	te = &_text_effect_list[i];
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   304
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   305
	/* Start defining this object */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	te->string_id = msg;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	te->duration = duration;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
	te->y = y - 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	te->bottom = y + 5;
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 425
diff changeset
   310
	te->params_1 = GetDParam(0);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 425
diff changeset
   311
	te->params_2 = GetDParam(4);
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   312
	te->mode = mode;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4609
diff changeset
   314
	GetString(buffer, msg, lastof(buffer));
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4469
diff changeset
   315
	w = GetStringBoundingBox(buffer).width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	te->x = x - (w >> 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	te->right = x + (w >> 1) - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	MarkTextEffectAreaDirty(te);
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   320
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   321
	return i;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   322
}
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   323
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   324
void UpdateTextEffect(TextEffectID te_id, StringID msg)
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   325
{
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   326
	assert(te_id < _num_text_effects);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   327
	TextEffect *te;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   328
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   329
	/* Update details */
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   330
	te = &_text_effect_list[te_id];
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   331
	te->string_id = msg;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   332
	te->params_1 = GetDParam(0);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   333
	te->params_2 = GetDParam(4);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   334
7535
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   335
	/* Update width of text effect */
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   336
	char buffer[100];
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   337
	GetString(buffer, msg, lastof(buffer));
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   338
	int w = GetStringBoundingBox(buffer).width;
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   339
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   340
	/* Only allow to make it broader, so it completely covers the old text. That avoids remnants of the old text. */
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   341
	int right_new = te->x + w;
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   342
	if (te->right < right_new) te->right = right_new;
417613ef92fa (svn r11055) -Fix [FS#1214]: loading indicators would sometimes glitch due to a bounding box that was too small. Patch by frosch.
rubidium
parents: 7454
diff changeset
   343
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   344
	MarkTextEffectAreaDirty(te);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   345
}
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   346
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   347
void RemoveTextEffect(TextEffectID te_id)
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   348
{
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   349
	assert(te_id < _num_text_effects);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   350
	TextEffect *te;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   351
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   352
	te = &_text_effect_list[te_id];
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   353
	MarkTextEffectAreaDirty(te);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   354
	te->string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
static void MoveTextEffect(TextEffect *te)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
{
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   359
	/* Never expire for duration of 0xFFFF */
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   360
	if (te->duration == 0xFFFF) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	if (te->duration < 8) {
2470
bdbac11a61ab (svn r2996) 0xFFFF -> INVALID_STRING_ID
tron
parents: 2458
diff changeset
   362
		te->string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	} else {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   364
		te->duration -= 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
		te->y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
		te->bottom--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	MarkTextEffectAreaDirty(te);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   371
void MoveAllTextEffects()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
{
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   373
	for (TextEffectID i = 0; i < _num_text_effects; i++) {
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   374
		TextEffect *te = &_text_effect_list[i];
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   375
		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
   376
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   379
void InitTextEffects()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
{
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   381
	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
   382
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   383
	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
   384
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
void DrawTextEffects(DrawPixelInfo *dpi)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
{
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   388
	switch (dpi->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6492
diff changeset
   389
		case ZOOM_LVL_NORMAL:
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   390
			for (TextEffectID i = 0; i < _num_text_effects; i++) {
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   391
				TextEffect *te = &_text_effect_list[i];
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   392
				if (te->string_id != INVALID_STRING_ID &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   393
						dpi->left <= te->right &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   394
						dpi->top  <= te->bottom &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   395
						dpi->left + dpi->width  > te->x &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   396
						dpi->top  + dpi->height > te->y) {
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7749
diff changeset
   397
					if (te->mode == TE_RISING || (_patches.loading_indicators && !IsTransparencySet(TO_LOADING))) {
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   398
						AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   399
					}
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   400
				}
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   401
			}
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   402
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6492
diff changeset
   404
		case ZOOM_LVL_OUT_2X:
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   405
			for (TextEffectID i = 0; i < _num_text_effects; i++) {
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   406
				TextEffect *te = &_text_effect_list[i];
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   407
				if (te->string_id != INVALID_STRING_ID &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   408
						dpi->left <= te->right  * 2 - te->x &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   409
						dpi->top  <= te->bottom * 2 - te->y &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   410
						dpi->left + dpi->width  > te->x &&
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   411
						dpi->top  + dpi->height > te->y) {
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7749
diff changeset
   412
					if (te->mode == TE_RISING || (_patches.loading_indicators && !IsTransparencySet(TO_LOADING))) {
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   413
						AddStringToDraw(te->x, te->y, (StringID)(te->string_id - 1), te->params_1, te->params_2);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6988
diff changeset
   414
					}
4469
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   415
				}
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   416
			}
ce4562f4ec51 (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   417
			break;
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6492
diff changeset
   418
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   419
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   420
		case ZOOM_LVL_OUT_8X:
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6492
diff changeset
   421
			break;
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   422
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   423
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   427
/** The table/list with animated tiles. */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   428
TileIndex *_animated_tile_list = NULL;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   429
/** The number of animated tiles in the current state. */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   430
uint _animated_tile_count = 0;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   431
/** The number of slots for animated tiles allocated currently. */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   432
static uint _animated_tile_allocated = 0;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   433
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   434
/**
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   435
 * Removes the given tile from the animated tile table.
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   436
 * @param tile the tile to remove
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   437
 */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   438
void DeleteAnimatedTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
{
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   440
	for (TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   441
		if (tile == *ti) {
7749
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   442
			/* Remove the hole
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   443
			 * The order of the remaining elements must stay the same, otherwise the animation loop
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   444
			 * may miss a tile; that's why we must use memmove instead of just moving the last element.
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   445
			 */
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   446
			memmove(ti, ti + 1, (_animated_tile_list + _animated_tile_count - (ti + 1)) * sizeof(*ti));
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   447
			_animated_tile_count--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
			return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   450
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   454
/**
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   455
 * Add the given tile to the animated tile table (if it does not exist
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   456
 * on that table yet). Also increases the size of the table if necessary.
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   457
 * @param tile the tile to make animated
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   458
 */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   459
void AddAnimatedTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
{
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   461
	MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   463
	for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   464
		if (tile == *ti) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   465
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   467
	/* Table not large enough, so make it larger */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   468
	if (_animated_tile_count == _animated_tile_allocated) {
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   469
		_animated_tile_allocated *= 2;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   470
		_animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, _animated_tile_allocated);
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   471
	}
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   472
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   473
	_animated_tile_list[_animated_tile_count] = tile;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   474
	_animated_tile_count++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   477
/**
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   478
 * Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them.
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   479
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   480
void AnimateAnimatedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
{
7749
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   482
	const TileIndex *ti = _animated_tile_list;
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   483
	while (ti < _animated_tile_list + _animated_tile_count) {
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   484
		const TileIndex curr = *ti;
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   485
		AnimateTile(curr);
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   486
		/* During the AnimateTile call, DeleteAnimatedTile could have been called,
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   487
		 * deleting an element we've already processed and pushing the rest one
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   488
		 * slot to the left. We can detect this by checking whether the index
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   489
		 * in the current slot has changed - if it has, an element has been deleted,
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   490
		 * and we should process the current slot again instead of going forward.
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   491
		 * NOTE: this will still break if more than one animated tile is being
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   492
		 *       deleted during the same AnimateTile call, but no code seems to
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   493
		 *       be doing this anyway.
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   494
		 */
3ed7d92bd966 (svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
rubidium
parents: 7694
diff changeset
   495
		if (*ti == curr) ++ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   499
/**
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   500
 * Initialize all animated tile variables to some known begin point
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   501
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6215
diff changeset
   502
void InitializeAnimatedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
{
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   504
	_animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, 256);
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   505
	_animated_tile_count = 0;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   506
	_animated_tile_allocated = 256;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   509
/**
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   510
 * Save the ANIT chunk.
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   511
 */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   512
static void Save_ANIT()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
{
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   514
	SlSetLength(_animated_tile_count * sizeof(*_animated_tile_list));
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   515
	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
   516
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   518
/**
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   519
 * Load the ANIT chunk; the chunk containing the animated tiles.
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   520
 */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   521
static void Load_ANIT()
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   522
{
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   523
	/* Before version 80 we did NOT have a variable length animated tile table */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   524
	if (CheckSavegameVersion(80)) {
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   525
		/* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   526
		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
   527
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   528
		for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   529
			if (_animated_tile_list[_animated_tile_count] == 0) break;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   530
		}
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   531
		return;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   532
	}
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   533
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   534
	_animated_tile_count = SlGetFieldLength() / sizeof(*_animated_tile_list);
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   535
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   536
	/* Determine a nice rounded size for the amount of allocated tiles */
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   537
	_animated_tile_allocated = 256;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   538
	while (_animated_tile_allocated < _animated_tile_count) _animated_tile_allocated *= 2;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   539
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   540
	_animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, _animated_tile_allocated);
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   541
	SlArray(_animated_tile_list, _animated_tile_count, SLE_UINT32);
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   542
}
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   543
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   544
/**
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   545
 * "Definition" imported by the saveload code to be able to load and save
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   546
 * the animated tile table.
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   547
 */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   548
extern const ChunkHandler _animated_tile_chunk_handlers[] = {
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7545
diff changeset
   549
	{ '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
   550
};