File: Sign_gump.cc

package info (click to toggle)
exult 1.2-4
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 9,040 kB
  • ctags: 10,543
  • sloc: cpp: 99,373; sh: 8,333; ansic: 4,659; makefile: 988; yacc: 769; lex: 313; xml: 19
file content (183 lines) | stat: -rwxr-xr-x 3,794 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Copyright (C) 2000 The Exult Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include "Sign_gump.h"
#include "gamewin.h"
#include "game.h"
#include "actors.h"


/*
 *	Create a sign gump.
 */

Sign_gump::Sign_gump
	(
	int shapenum,
	int nlines			// # of text lines.
	) : Gump(0, shapenum), num_lines(nlines), serpentine(false)
{
	// THIS IS A HACK, but don't ask me why this is like this,
	if (Game::get_game_type() == SERPENT_ISLE && shapenum==49)
	{
		// check for avatar read here
		Main_actor *avatar = gwin->get_main_actor();
		if (!avatar->get_flag(Obj_flags::read))
			serpentine = true;

		shapenum = game->get_shape("gumps/goldsign");
		set_shape(shapenum);
		set_pos();	// Recenter
	}

	if(shapenum==game->get_shape("gumps/woodsign"))
	{
		set_object_area(Rectangle(0, 4, 196, 92));
	}
	else if(shapenum==game->get_shape("gumps/tombstone"))
	{
		set_object_area(Rectangle(0, 8, 200, 112));
	}
	else if(shapenum==game->get_shape("gumps/goldsign"))
	{
		if (Game::get_game_type() == BLACK_GATE)
			set_object_area(Rectangle(0, 4, 232, 96));
		else			// SI
			set_object_area(Rectangle(4, 4, 312, 96));
	}
	else if (shapenum==game->get_shape("gumps/scroll"))
		set_object_area(Rectangle(48, 30, 146, 118));
	lines = new std::string[num_lines];
}

/*
 *	Delete sign.
 */

Sign_gump::~Sign_gump
	(
	)
{
	delete [] lines;
}

/*
 *	Add a line of text.
 */

void Sign_gump::add_text
	(
	int line,
	const std::string &txt
	)
{
	if (line < 0 || line >= num_lines)
		return;

	// check for avatar read here
	Main_actor *avatar = gwin->get_main_actor();

	if (!serpentine && avatar->get_flag(Obj_flags::read))
	{
		for (int i = 0; i < txt.size(); i++)
		{
			if (txt[i] == 40) 
			{
				lines[line] += 'T';
				lines[line] += 'H';
			}
			else if (txt[i] == 41) 
			{
				lines[line] += 'E';
				lines[line] += 'E';
			}
			else if (txt[i] == 42) 
			{
				lines[line] += 'N';
				lines[line] += 'G';
			}
			else if (txt[i] == 43) 
			{
				lines[line] += 'E';
				lines[line] += 'A';
			}
			else if (txt[i] == 44) 
			{
				lines[line] += 'S';
				lines[line] += 'T';
			}
			else if (txt[i] == '|')
			{
				lines[line] += ' ';
			}
			else if (txt[i] >= 'a')
				lines[line] += txt[i] - 32;
			else
				lines[line] += txt[i];
		}
	}
	else
	{
		lines[line] = txt;

	}
}

/*
 *	Paint sign.
 */

void Sign_gump::paint
	(
	)
{
	int font = 1;			// Normal runes.
	if (get_shapenum() == game->get_shape("gumps/goldsign"))
	{
		if (serpentine)
			font = 10;
		else
			font = 6;		// Embossed.
	}
	else if (serpentine)
		font = 8;
					// Get height of 1 line.
	int lheight = sman->get_text_height(font);
					// Get space between lines.
	int lspace = (object_area.h - num_lines*lheight)/(num_lines + 1);
					// Paint the gump itself.
	paint_shape(x, y);
	int ypos = y + object_area.y;	// Where to paint next line.
	for (int i = 0; i < num_lines; i++)
	{
		ypos += lspace;
		if (lines[i].empty())
			continue;
		sman->paint_text(font, lines[i].c_str(),
			x + object_area.x + 
				(object_area.w - 
			sman->get_text_width(font, lines[i].c_str()))/2,
			ypos);
		ypos += lheight;
	}
	gwin->set_painted();
}