2011-06-10 05:45:18 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on original Soltys source code
|
|
|
|
* Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
|
|
|
|
*/
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#include "cge/general.h"
|
|
|
|
#include "cge/text.h"
|
|
|
|
#include "cge/talk.h"
|
|
|
|
#include "cge/vol.h"
|
|
|
|
#include "cge/game.h"
|
|
|
|
#include "cge/snail.h"
|
2011-06-19 22:13:41 +00:00
|
|
|
#include "cge/cge_main.h"
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
namespace CGE {
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
Text *_text;
|
|
|
|
Talk *_talk = NULL;
|
|
|
|
|
|
|
|
Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) {
|
|
|
|
_cache = new Han[size];
|
|
|
|
mergeExt(_fileName, fname, SAY_EXT);
|
|
|
|
if (!INI_FILE::exist(_fileName))
|
|
|
|
error("No talk (%s)\n", _fileName);
|
|
|
|
|
|
|
|
for (_size = 0; _size < size; _size++) {
|
|
|
|
_cache[_size]._ref = 0;
|
|
|
|
_cache[_size]._txt = NULL;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
Text::~Text() {
|
|
|
|
clear();
|
|
|
|
delete[] _cache;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
void Text::clear(int from, int upto) {
|
|
|
|
Han *p, * q;
|
|
|
|
for (p = _cache, q = p + _size; p < q; p++) {
|
|
|
|
if (p->_ref && p->_ref >= from && p->_ref < upto) {
|
|
|
|
p->_ref = 0;
|
|
|
|
delete[] p->_txt;
|
|
|
|
p->_txt = NULL;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
int Text::find(int ref) {
|
|
|
|
Han *p, * q;
|
2011-06-13 09:57:24 +00:00
|
|
|
int i = 0;
|
2011-07-03 09:28:22 +00:00
|
|
|
for (p = _cache, q = p + _size; p < q; p++) {
|
|
|
|
if (p->_ref == ref)
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
2011-06-13 11:07:45 +00:00
|
|
|
else
|
2011-07-03 09:28:22 +00:00
|
|
|
i++;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
return i;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
void Text::preload(int from, int upto) {
|
|
|
|
INI_FILE tf = _fileName;
|
2011-07-01 06:37:40 +00:00
|
|
|
if (!tf._error) {
|
2011-07-03 09:28:22 +00:00
|
|
|
Han *CacheLim = _cache + _size;
|
2011-07-20 23:56:40 +00:00
|
|
|
char line[kLineMax + 1];
|
2011-06-13 09:57:24 +00:00
|
|
|
int n;
|
|
|
|
|
2011-06-30 06:30:23 +00:00
|
|
|
while ((n = tf.read((uint8 *)line)) != 0) {
|
2011-06-13 09:57:24 +00:00
|
|
|
char *s;
|
|
|
|
int ref;
|
|
|
|
|
|
|
|
if (line[n - 1] == '\n')
|
|
|
|
line[-- n] = '\0';
|
|
|
|
if ((s = strtok(line, " =,;/\t\n")) == NULL)
|
|
|
|
continue;
|
|
|
|
if (! IsDigit(*s))
|
|
|
|
continue;
|
|
|
|
ref = atoi(s);
|
|
|
|
if (ref && ref >= from && ref < upto) {
|
2011-07-03 09:28:22 +00:00
|
|
|
Han *p;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
p = &_cache[find(ref)];
|
2011-06-13 09:57:24 +00:00
|
|
|
if (p < CacheLim) {
|
2011-07-03 09:28:22 +00:00
|
|
|
delete[] p->_txt;
|
|
|
|
p->_txt = NULL;
|
2011-06-13 11:07:45 +00:00
|
|
|
} else
|
2011-07-03 09:28:22 +00:00
|
|
|
p = &_cache[find(0)];
|
2011-06-13 11:07:45 +00:00
|
|
|
if (p >= CacheLim)
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
s += strlen(s);
|
2011-06-13 11:07:45 +00:00
|
|
|
if (s < line + n)
|
2011-06-13 09:57:24 +00:00
|
|
|
++s;
|
2011-07-03 09:28:22 +00:00
|
|
|
if ((p->_txt = new char[strlen(s) + 1]) == NULL)
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
2011-07-03 09:28:22 +00:00
|
|
|
p->_ref = ref;
|
|
|
|
strcpy(p->_txt, s);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
char *Text::load(int idx, int ref) {
|
|
|
|
INI_FILE tf = _fileName;
|
2011-07-01 06:37:40 +00:00
|
|
|
if (!tf._error) {
|
2011-07-03 09:28:22 +00:00
|
|
|
Han *p = &_cache[idx];
|
2011-07-20 23:56:40 +00:00
|
|
|
char line[kLineMax + 1];
|
2011-06-13 09:57:24 +00:00
|
|
|
int n;
|
|
|
|
|
2011-06-30 06:30:23 +00:00
|
|
|
while ((n = tf.read((uint8 *)line)) != 0) {
|
2011-06-13 09:57:24 +00:00
|
|
|
char *s;
|
|
|
|
|
2011-06-13 11:07:45 +00:00
|
|
|
if (line[n - 1] == '\n')
|
2011-06-13 09:57:24 +00:00
|
|
|
line[-- n] = '\0';
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((s = strtok(line, " =,;/\t\n")) == NULL)
|
2011-06-13 09:57:24 +00:00
|
|
|
continue;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (! IsDigit(*s))
|
2011-06-13 09:57:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
int r = atoi(s);
|
2011-06-13 11:07:45 +00:00
|
|
|
if (r < ref)
|
2011-06-13 09:57:24 +00:00
|
|
|
continue;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (r > ref)
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
// (r == ref)
|
|
|
|
s += strlen(s);
|
2011-06-13 11:07:45 +00:00
|
|
|
if (s < line + n)
|
2011-06-13 09:57:24 +00:00
|
|
|
++s;
|
2011-07-03 09:28:22 +00:00
|
|
|
p->_ref = ref;
|
|
|
|
if ((p->_txt = new char[strlen(s) + 1]) == NULL)
|
2011-06-13 09:57:24 +00:00
|
|
|
return NULL;
|
2011-07-03 09:28:22 +00:00
|
|
|
return strcpy(p->_txt, s);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
return NULL;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
char *Text::getText(int ref) {
|
2011-06-13 09:57:24 +00:00
|
|
|
int i;
|
2011-07-03 09:28:22 +00:00
|
|
|
if ((i = find(ref)) < _size)
|
|
|
|
return _cache[i]._txt;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
if ((i = find(0)) >= _size) {
|
|
|
|
clear(SYSTXT_MAX); // clear non-system
|
|
|
|
if ((i = find(0)) >= _size) {
|
|
|
|
clear(); // clear all
|
2011-06-13 09:57:24 +00:00
|
|
|
i = 0;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-07-03 09:28:22 +00:00
|
|
|
return load(i, ref);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
void Text::say(const char *txt, Sprite *spr) {
|
|
|
|
killText();
|
2011-07-24 21:42:03 +00:00
|
|
|
_talk = new Talk(_vm, txt, kTBRound);
|
2011-07-03 09:28:22 +00:00
|
|
|
if (_talk) {
|
2011-06-29 14:13:17 +00:00
|
|
|
bool east = spr->_flags._east;
|
|
|
|
int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2);
|
|
|
|
int y = spr->_y + 2;
|
2011-07-10 00:07:35 +00:00
|
|
|
Sprite *spike = new Spike(_vm);
|
2011-06-29 14:13:17 +00:00
|
|
|
uint16 sw = spike->_w;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
if (east) {
|
2011-07-20 23:56:40 +00:00
|
|
|
if (x + sw + kTextRoundCorner + 5 >= kScrWidth)
|
2011-06-13 09:57:24 +00:00
|
|
|
east = false;
|
|
|
|
} else {
|
2011-07-19 05:50:07 +00:00
|
|
|
if (x <= 5 + kTextRoundCorner + sw)
|
2011-06-13 09:57:24 +00:00
|
|
|
east = true;
|
|
|
|
}
|
2011-06-29 14:13:17 +00:00
|
|
|
x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2 - sw);
|
2011-06-28 22:35:21 +00:00
|
|
|
if (spr->_ref == 1)
|
2011-06-13 11:44:52 +00:00
|
|
|
x += ((east) ? -10 : 10); // Hero
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
_talk->_flags._kill = true;
|
|
|
|
_talk->_flags._bDel = true;
|
|
|
|
_talk->setName(_text->getText(SAY_NAME));
|
|
|
|
_talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1);
|
|
|
|
_talk->_z = 125;
|
|
|
|
_talk->_ref = SAY_REF;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
spike->gotoxy(x, _talk->_y + _talk->_h - 1);
|
2011-06-29 14:13:17 +00:00
|
|
|
spike->_z = 126;
|
|
|
|
spike->_flags._slav = true;
|
|
|
|
spike->_flags._kill = true;
|
2011-07-03 09:28:22 +00:00
|
|
|
spike->setName(_text->getText(SAY_NAME));
|
2011-07-01 23:02:14 +00:00
|
|
|
spike->step(east);
|
2011-06-28 22:35:21 +00:00
|
|
|
spike->_ref = SAY_REF;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(_talk, _vga->_showQ->last());
|
|
|
|
_vga->_showQ->insert(spike, _vga->_showQ->last());
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::inf(const char *txt) {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::inf(%s)", txt);
|
2011-07-19 05:13:41 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
killText();
|
2011-07-24 21:42:03 +00:00
|
|
|
_talk = new Talk(this, txt, kTBRect);
|
2011-07-03 09:28:22 +00:00
|
|
|
if (_talk) {
|
|
|
|
_talk->_flags._kill = true;
|
|
|
|
_talk->_flags._bDel = true;
|
|
|
|
_talk->setName(_text->getText(INF_NAME));
|
|
|
|
_talk->center();
|
|
|
|
_talk->gotoxy(_talk->_x, _talk->_y - 20);
|
|
|
|
_talk->_z = 126;
|
|
|
|
_talk->_ref = INF_REF;
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(_talk, _vga->_showQ->last());
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
void sayTime(Sprite *spr) {
|
2011-06-13 09:57:24 +00:00
|
|
|
/*
|
|
|
|
static char t[] = "00:00";
|
|
|
|
struct time ti;
|
|
|
|
gettime(&ti);
|
|
|
|
wtom(ti.ti_hour, t+0, 10, 2);
|
|
|
|
wtom(ti.ti_min, t+3, 10, 2);
|
|
|
|
Say((*t == '0') ? (t+1) : t, spr);
|
|
|
|
*/
|
2011-07-03 09:28:22 +00:00
|
|
|
warning("STUB: sayTime");
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
void killText() {
|
|
|
|
if (_talk) {
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnKill, -1, 0, _talk);
|
2011-07-03 09:28:22 +00:00
|
|
|
_talk = NULL;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
} // End of namespace CGE
|