src/texteff.cpp
author celestar
Thu, 19 Apr 2007 14:48:10 +0000
branchgamebalance
changeset 9907 3b068c3a1c74
parent 9906 6f41b8713b65
child 9908 0fa543611bbe
permissions -rw-r--r--
(svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     4
#include "openttd.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2153
diff changeset
     5
#include "functions.h"
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
     6
#include "macros.h"
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1174
diff changeset
     7
#include "strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "saveload.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    11
#include "hal.h"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    12
#include "console.h"
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
    13
#include "string.h"
2153
91e89aa8c299 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2062
diff changeset
    14
#include "variables.h"
2218
abd47ef7d902 (svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents: 2186
diff changeset
    15
#include "table/sprites.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    16
#include <stdarg.h> /* va_list */
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 2685
diff changeset
    17
#include "date.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    19
enum {
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5919
diff changeset
    20
	MAX_TEXTMESSAGE_LENGTH = 200,
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    21
	MAX_TEXT_MESSAGES      =  30,
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    22
	MAX_CHAT_MESSAGES      =  10,
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    23
	MAX_ANIMATED_TILES     = 256,
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    24
};
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    25
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
    26
struct TextEffect {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	StringID string_id;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    28
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    29
	int32 y;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    30
	int32 right;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    31
	int32 bottom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	uint16 duration;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	uint32 params_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	uint32 params_2;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
    35
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    37
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
    38
struct TextMessage {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    39
	char message[MAX_TEXTMESSAGE_LENGTH];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    40
	uint16 color;
4363
3a3a2a3dda00 (svn r6078) -Fix: forgot one uint16 -> Date conversion. Tnx to #openttdcoop team for detecting and Rubidium for finding the cause.
truelight
parents: 4261
diff changeset
    41
	Date end_date;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
    42
};
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    43
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    44
static TextEffect _text_effect_list[MAX_TEXT_MESSAGES];
4956
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    45
static TextMessage _textmsg_list[MAX_CHAT_MESSAGES];
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
    46
TileIndex _animated_tile_list[MAX_ANIMATED_TILES];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
4956
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    48
static bool _textmessage_dirty = false;
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2470
diff changeset
    49
static bool _textmessage_visible = false;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    50
4956
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    51
/* The chatbox grows from the bottom so the coordinates are pixels from
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
    52
 * the left and pixels from the bottom. The height is the maximum height */
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    53
static const Oblong _textmsg_box = {10, 30, 500, 150};
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    54
static Pixel _textmessage_backup[150 * 500]; // (height * width)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    55
4958
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4957
diff changeset
    56
extern void memcpy_pitch(void *dst, void *src, int w, int h, int srcpitch, int dstpitch);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    57
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
    58
static inline uint GetTextMessageCount()
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    59
{
4959
828f9223446d (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
    60
	uint i;
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    61
4959
828f9223446d (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
    62
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    63
		if (_textmsg_list[i].message[0] == '\0') break;
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    64
	}
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    65
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    66
	return i;
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    67
}
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    68
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    69
/* Add a text message to the 'chat window' to be shown
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    70
 * @param color The colour this message is to be shown in
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    71
 * @param duration The duration of the chat message in game-days
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    72
 * @param message message itself in printf() style */
1022
9ea8ee93d6a9 (svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents: 849
diff changeset
    73
void CDECL AddTextMessage(uint16 color, uint8 duration, const char *message, ...)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    74
{
2455
8d6d990d55f8 (svn r2981) Remove a no-op
tron
parents: 2424
diff changeset
    75
	char buf[MAX_TEXTMESSAGE_LENGTH];
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    76
	const char *bufp;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    77
	va_list va;
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    78
	uint msg_count;
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    79
	uint16 lines;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    80
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    81
	va_start(va, message);
2373
f06403621870 (svn r2899) -Fix: Several format string vulnerabilities and buffer overflows in the network code
tron
parents: 2295
diff changeset
    82
	vsnprintf(buf, lengthof(buf), message, va);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    83
	va_end(va);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    84
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5919
diff changeset
    85
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5919
diff changeset
    86
	Utf8TrimString(buf, MAX_TEXTMESSAGE_LENGTH);
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 5919
diff changeset
    87
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    88
	/* Force linebreaks for strings that are too long */
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    89
	lines = GB(FormatStringLinebreaks(buf, _textmsg_box.width - 8), 0, 16) + 1;
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    90
	if (lines >= MAX_CHAT_MESSAGES) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    91
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    92
	msg_count = GetTextMessageCount();
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    93
	/* We want to add more chat messages than there is free space for, remove 'old' */
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    94
	if (lines > MAX_CHAT_MESSAGES - msg_count) {
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    95
		int i = lines - (MAX_CHAT_MESSAGES - msg_count);
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    96
		memmove(&_textmsg_list[0], &_textmsg_list[i], sizeof(_textmsg_list[0]) * (msg_count - i));
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
    97
		msg_count = MAX_CHAT_MESSAGES - lines;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    98
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    99
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   100
	for (bufp = buf; lines != 0; lines--) {
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   101
		TextMessage *tmsg = &_textmsg_list[msg_count++];
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   102
		ttd_strlcpy(tmsg->message, bufp, sizeof(tmsg->message));
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   103
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   104
		/* The default colour for a message is player colour. Replace this with
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   105
		 * white for any additional lines */
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   106
		tmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   107
		tmsg->end_date = _date + duration;
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   108
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   109
		bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   110
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   111
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   112
	_textmessage_dirty = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   113
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   114
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   115
void InitTextMessage()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   116
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   117
	uint i;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   118
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   119
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
4956
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   120
		_textmsg_list[i].message[0] = '\0';
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   121
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   122
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   123
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   124
/* Hide the textbox */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   125
void UndrawTextMessage()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   126
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   127
	if (_textmessage_visible) {
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   128
		/* Sometimes we also need to hide the cursor
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   129
		 *   This is because both textmessage and the cursor take a shot of the
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   130
		 *   screen before drawing.
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   131
		 *   Now the textmessage takes his shot and paints his data before the cursor
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   132
		 *   does, so in the shot of the cursor is the screen-data of the textmessage
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   133
		 *   included when the cursor hangs somewhere over the textmessage. To
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   134
		 *   avoid wrong repaints, we undraw the cursor in that case, and everything
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   135
		 *   looks nicely ;)
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   136
		 * (and now hope this story above makes sense to you ;))
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   137
		 */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   138
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   139
		if (_cursor.visible) {
4956
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   140
			if (_cursor.draw_pos.x + _cursor.draw_size.x >= _textmsg_box.x &&
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   141
				_cursor.draw_pos.x <= _textmsg_box.x + _textmsg_box.width &&
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   142
				_cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _textmsg_box.y - _textmsg_box.height &&
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   143
				_cursor.draw_pos.y <= _screen.height - _textmsg_box.y) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   144
				UndrawMouseCursor();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   145
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   146
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   147
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   148
		int x      = _textmsg_box.x;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   149
		int y      = _screen.height - _textmsg_box.y - _textmsg_box.height;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   150
		int width  = _textmsg_box.width;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   151
		int height = _textmsg_box.height;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   152
		if (y < 0) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   153
			height = max(height + y, min(_textmsg_box.height, _screen.height));
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   154
			y = 0;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   155
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   156
		if (x + width >= _screen.width) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   157
			width = _screen.width - x;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   158
		}
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   159
		if (width <= 0 || height <= 0) return;
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   160
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   161
		_textmessage_visible = false;
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   162
		/* Put our 'shot' back to the screen */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   163
		memcpy_pitch(
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   164
			_screen.dst_ptr + x + y * _screen.pitch,
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   165
			_textmessage_backup,
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   166
			width, height, _textmsg_box.width, _screen.pitch);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   167
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   168
		/* And make sure it is updated next time */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   169
		_video_driver->make_dirty(x, y, width, height);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   170
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   171
		_textmessage_dirty = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   172
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   173
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   174
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   175
/* Check if a message is expired every day */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   176
void TextMessageDailyLoop()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   177
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   178
	uint i;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   179
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   180
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   181
		TextMessage *tmsg = &_textmsg_list[i];
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   182
		if (tmsg->message[0] == '\0') continue;
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   183
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   184
		/* Message has expired, remove from the list */
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   185
		if (tmsg->end_date < _date) {
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   186
			/* Move the remaining messages over the current message */
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4956
diff changeset
   187
			if (i != MAX_CHAT_MESSAGES - 1) memmove(tmsg, tmsg + 1, sizeof(*tmsg) * (MAX_CHAT_MESSAGES - i - 1));
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   188
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   189
			/* Mark the last item as empty */
4956
76db5a2689fc (svn r6955) -Codechange: Change some variable names for _textmessage_box, and replace 5 different
Darkvater
parents: 4912
diff changeset
   190
			_textmsg_list[MAX_CHAT_MESSAGES - 1].message[0] = '\0';
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   191
			_textmessage_dirty = true;
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   192
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   193
			/* Go one item back, because we moved the array 1 to the left */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   194
			i--;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   195
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   196
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   197
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   198
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   199
/* Draw the textmessage-box */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   200
void DrawTextMessage()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   201
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   202
	if (!_textmessage_dirty) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   203
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   204
	/* First undraw if needed */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   205
	UndrawTextMessage();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   206
4959
828f9223446d (svn r6958) -Fix (r6956): GCC warning (thx Tron) and a coding style forgotten in r6957
Darkvater
parents: 4958
diff changeset
   207
	if (_iconsole_mode == ICONSOLE_FULL) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   208
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   209
	/* Check if we have anything to draw at all */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   210
	uint count = GetTextMessageCount();
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   211
	if (count == 0) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   212
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   213
	int x      = _textmsg_box.x;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   214
	int y      = _screen.height - _textmsg_box.y - _textmsg_box.height;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   215
	int width  = _textmsg_box.width;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   216
	int height = _textmsg_box.height;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   217
	if (y < 0) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   218
		height = max(height + y, min(_textmsg_box.height, _screen.height));
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   219
		y = 0;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   220
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   221
	if (x + width >= _screen.width) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   222
		width = _screen.width - x;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   223
	}
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   224
	if (width <= 0 || height <= 0) return;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   225
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   226
	/* Make a copy of the screen as it is before painting (for undraw) */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   227
	memcpy_pitch(
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   228
		_textmessage_backup,
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   229
		_screen.dst_ptr + x + y * _screen.pitch,
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   230
		width, height, _screen.pitch, _textmsg_box.width);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   231
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   232
	_cur_dpi = &_screen; // switch to _screen painting
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   233
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   234
	/* Paint a half-transparent box behind the text messages */
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   235
	GfxFillRect(
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   236
			_textmsg_box.x,
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   237
			_screen.height - _textmsg_box.y - count * 13 - 2,
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   238
			_textmsg_box.x + _textmsg_box.width - 1,
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   239
			_screen.height - _textmsg_box.y - 2,
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   240
			PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE) // black, but with some alpha for background
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   241
		);
1595
b1a8323c1024 (svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents: 1569
diff changeset
   242
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   243
	/* Paint the messages starting with the lowest at the bottom */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   244
	for (uint y = 13; count-- != 0; y += 13) {
4960
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   245
		DoDrawString(_textmsg_list[count].message, _textmsg_box.x + 3, _screen.height - _textmsg_box.y - y + 1, _textmsg_list[count].color);
cb06aa866acb (svn r6959) -Codechange: Move GfxFillRect() out of the chat-message drawing loop since we already
Darkvater
parents: 4959
diff changeset
   246
 	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   247
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   248
	/* Make sure the data is updated next flush */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   249
	_video_driver->make_dirty(x, y, width, height);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   250
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   251
	_textmessage_visible = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   252
	_textmessage_dirty = false;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   253
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   254
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
static void MarkTextEffectAreaDirty(TextEffect *te)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
		te->x,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		te->y - 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		(te->right - te->x)*2 + te->x + 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		(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
   262
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
void AddTextEffect(StringID msg, int x, int y, uint16 duration)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	TextEffect *te;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	int w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
	char buffer[100];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
4958
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4957
diff changeset
   271
	if (_game_mode == GM_MENU) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   272
2470
a3b2f1f8ab3d (svn r2996) 0xFFFF -> INVALID_STRING_ID
tron
parents: 2458
diff changeset
   273
	for (te = _text_effect_list; te->string_id != INVALID_STRING_ID; ) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   274
		if (++te == endof(_text_effect_list)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	te->string_id = msg;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	te->duration = duration;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
	te->y = y - 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	te->bottom = y + 5;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 425
diff changeset
   281
	te->params_1 = GetDParam(0);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 425
diff changeset
   282
	te->params_2 = GetDParam(4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4609
diff changeset
   284
	GetString(buffer, msg, lastof(buffer));
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4469
diff changeset
   285
	w = GetStringBoundingBox(buffer).width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	te->x = x - (w >> 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	te->right = x + (w >> 1) - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	MarkTextEffectAreaDirty(te);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
static void MoveTextEffect(TextEffect *te)
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
	if (te->duration < 8) {
2470
a3b2f1f8ab3d (svn r2996) 0xFFFF -> INVALID_STRING_ID
tron
parents: 2458
diff changeset
   295
		te->string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	} else {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   297
		te->duration -= 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
		te->y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
		te->bottom--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	MarkTextEffectAreaDirty(te);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   304
void MoveAllTextEffects()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	TextEffect *te;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   308
	for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   309
		if (te->string_id != INVALID_STRING_ID) MoveTextEffect(te);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   313
void InitTextEffects()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	TextEffect *te;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   317
	for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
2470
a3b2f1f8ab3d (svn r2996) 0xFFFF -> INVALID_STRING_ID
tron
parents: 2458
diff changeset
   318
		te->string_id = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
void DrawTextEffects(DrawPixelInfo *dpi)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
{
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   324
	const TextEffect* te;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   326
	switch (dpi->zoom) {
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   327
		case 0:
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   328
			for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   329
				if (te->string_id != INVALID_STRING_ID &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   330
						dpi->left <= te->right &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   331
						dpi->top  <= te->bottom &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   332
						dpi->left + dpi->width  > te->x &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   333
						dpi->top  + dpi->height > te->y) {
5026
c8b7148798ac (svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents: 4960
diff changeset
   334
					AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2);
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   335
				}
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   336
			}
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   337
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   339
		case 1:
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   340
			for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   341
				if (te->string_id != INVALID_STRING_ID &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   342
						dpi->left <= te->right  * 2 - te->x &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   343
						dpi->top  <= te->bottom * 2 - te->y &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   344
						dpi->left + dpi->width  > te->x &&
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   345
						dpi->top  + dpi->height > te->y) {
5026
c8b7148798ac (svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents: 4960
diff changeset
   346
					AddStringToDraw(te->x, te->y, (StringID)(te->string_id-1), te->params_1, te->params_2);
4469
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   347
				}
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   348
			}
224ea00d73af (svn r6254) if () cascade -> switch ()
tron
parents: 4363
diff changeset
   349
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   353
void DeleteAnimatedTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
{
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   355
	TileIndex *ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   357
	for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   358
		if (tile == *ti) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
			/* remove the hole */
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   360
			memmove(ti, ti + 1, (lastof(_animated_tile_list) - ti) * sizeof(*ti));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
			/* and clear last item */
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   362
			*lastof(_animated_tile_list) = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
			return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   365
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	}
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   369
bool AddAnimatedTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
{
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   371
	TileIndex *ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   373
	for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   374
		if (tile == *ti || *ti == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			*ti = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   379
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   384
void AnimateAnimatedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   386
	const TileIndex* ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   388
	for (ti = _animated_tile_list; ti != endof(_animated_tile_list) && *ti != 0; ti++) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   389
		AnimateTile(*ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   393
void InitializeAnimatedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
	memset(_animated_tile_list, 0, sizeof(_animated_tile_list));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   398
static void SaveLoad_ANIT()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
{
5679
a478b04c1fd0 (svn r7632) -Codechange: several small code cleanups of texteff, like moving magic values and defines to an enum and fix coding/documentation style.
rubidium
parents: 5678
diff changeset
   400
	/* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2639
diff changeset
   401
	if (CheckSavegameVersion(6)) {
1881
023a134a4b12 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1595
diff changeset
   402
		SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_FILE_U16 | SLE_VAR_U32);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   403
	} else {
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1093
diff changeset
   404
		SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   405
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   409
extern const ChunkHandler _animated_tile_chunk_handlers[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	{ 'ANIT', SaveLoad_ANIT, SaveLoad_ANIT, CH_RIFF | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
};