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/bitmaps.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-06-19 09:17:54 +00:00
|
|
|
TEXT *Text;
|
2011-06-13 09:57:24 +00:00
|
|
|
TALK *Talk = NULL;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-26 23:03:47 +00:00
|
|
|
TEXT::TEXT(CGEEngine *vm, const char *fname, int size) : _vm(vm) {
|
2011-06-13 09:57:24 +00:00
|
|
|
Cache = new HAN[size];
|
2011-07-01 23:02:14 +00:00
|
|
|
mergeExt(FileName, fname, SAY_EXT);
|
2011-06-30 06:30:23 +00:00
|
|
|
if (!INI_FILE::exist(FileName))
|
2011-06-22 06:11:18 +00:00
|
|
|
error("No talk (%s)\n", FileName);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-26 10:07:42 +00:00
|
|
|
for (Size = 0; Size < size; Size++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
Cache[Size].Ref = 0;
|
|
|
|
Cache[Size].Txt = NULL;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-26 23:03:47 +00:00
|
|
|
TEXT::~TEXT() {
|
2011-06-13 09:57:24 +00:00
|
|
|
Clear();
|
|
|
|
delete[] Cache;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
void TEXT::Clear(int from, int upto) {
|
|
|
|
HAN *p, * q;
|
2011-06-26 10:07:42 +00:00
|
|
|
for (p = Cache, q = p + Size; p < q; p++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
if (p->Ref && p->Ref >= from && p->Ref < upto) {
|
|
|
|
p->Ref = 0;
|
2011-07-03 05:32:27 +00:00
|
|
|
delete[] p->Txt;
|
2011-06-13 09:57:24 +00:00
|
|
|
p->Txt = NULL;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
int TEXT::Find(int ref) {
|
|
|
|
HAN *p, * q;
|
|
|
|
int i = 0;
|
2011-06-26 10:07:42 +00:00
|
|
|
for (p = Cache, q = p + Size; p < q; p++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
if (p->Ref == ref)
|
|
|
|
break;
|
2011-06-13 11:07:45 +00:00
|
|
|
else
|
2011-06-13 09:57:24 +00:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return i;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +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-06-13 09:57:24 +00:00
|
|
|
HAN *CacheLim = Cache + Size;
|
|
|
|
char line[LINE_MAX + 1];
|
|
|
|
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) {
|
|
|
|
HAN *p;
|
|
|
|
|
|
|
|
p = &Cache[Find(ref)];
|
|
|
|
if (p < CacheLim) {
|
|
|
|
delete[] p->Txt;
|
|
|
|
p->Txt = NULL;
|
2011-06-13 11:07:45 +00:00
|
|
|
} else
|
2011-06-13 09:57:24 +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-06-13 11:07:45 +00:00
|
|
|
if ((p->Txt = new char[strlen(s) + 1]) == NULL)
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
p->Ref = ref;
|
|
|
|
strcpy(p->Txt, s);
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +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-06-13 09:57:24 +00:00
|
|
|
HAN *p = &Cache[idx];
|
|
|
|
char line[LINE_MAX + 1];
|
|
|
|
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;
|
|
|
|
p->Ref = ref;
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((p->Txt = new char[strlen(s) + 1]) == NULL)
|
2011-06-13 09:57:24 +00:00
|
|
|
return NULL;
|
|
|
|
return strcpy(p->Txt, s);
|
|
|
|
}
|
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-06-19 09:17:54 +00:00
|
|
|
char *TEXT::getText(int ref) {
|
2011-06-13 09:57:24 +00:00
|
|
|
int i;
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((i = Find(ref)) < Size)
|
2011-06-13 09:57:24 +00:00
|
|
|
return Cache[i].Txt;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
if ((i = Find(0)) >= Size) {
|
|
|
|
Clear(SYSTXT_MAX); // clear non-system
|
|
|
|
if ((i = Find(0)) >= Size) {
|
|
|
|
Clear(); // clear all
|
|
|
|
i = 0;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
return Load(i, ref);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
void TEXT::Say(const char *txt, Sprite *spr) {
|
2011-06-13 09:57:24 +00:00
|
|
|
KillText();
|
2011-06-26 23:03:47 +00:00
|
|
|
Talk = new TALK(_vm, txt, ROUND);
|
2011-06-13 09:57:24 +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-06-28 22:35:21 +00:00
|
|
|
Sprite *spike = new Sprite(_vm, SP);
|
2011-06-29 14:13:17 +00:00
|
|
|
uint16 sw = spike->_w;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
if (east) {
|
2011-06-13 11:07:45 +00:00
|
|
|
if (x + sw + TEXT_RD + 5 >= SCR_WID)
|
2011-06-13 09:57:24 +00:00
|
|
|
east = false;
|
|
|
|
} else {
|
2011-06-13 11:07:45 +00:00
|
|
|
if (x <= 5 + TEXT_RD + 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-06-29 14:13:17 +00:00
|
|
|
Talk->_flags._kill = true;
|
|
|
|
Talk->_flags._bDel = true;
|
2011-07-01 23:02:14 +00:00
|
|
|
Talk->setName(Text->getText(SAY_NAME));
|
|
|
|
Talk->gotoxy(x - (Talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - Talk->_h + 1);
|
2011-06-29 14:13:17 +00:00
|
|
|
Talk->_z = 125;
|
2011-06-28 22:35:21 +00:00
|
|
|
Talk->_ref = SAY_REF;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-01 23:02:14 +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-01 23:02:14 +00:00
|
|
|
spike->setName(Text->getText(SAY_NAME));
|
|
|
|
spike->step(east);
|
2011-06-28 22:35:21 +00:00
|
|
|
spike->_ref = SAY_REF;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-06-19 22:13:41 +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-06-13 09:57:24 +00:00
|
|
|
KillText();
|
2011-06-26 23:03:47 +00:00
|
|
|
Talk = new TALK(this, txt, RECT);
|
2011-06-13 09:57:24 +00:00
|
|
|
if (Talk) {
|
2011-06-29 14:13:17 +00:00
|
|
|
Talk->_flags._kill = true;
|
|
|
|
Talk->_flags._bDel = true;
|
2011-07-01 23:02:14 +00:00
|
|
|
Talk->setName(Text->getText(INF_NAME));
|
|
|
|
Talk->center();
|
|
|
|
Talk->gotoxy(Talk->_x, Talk->_y - 20);
|
2011-06-29 14:13:17 +00:00
|
|
|
Talk->_z = 126;
|
2011-06-28 22:35:21 +00:00
|
|
|
Talk->_ref = INF_REF;
|
2011-06-19 22:13:41 +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-06-28 22:35:21 +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);
|
|
|
|
*/
|
|
|
|
warning("STUB: SayTime");
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
void KillText(void) {
|
|
|
|
if (Talk) {
|
|
|
|
SNPOST_(SNKILL, -1, 0, Talk);
|
|
|
|
Talk = NULL;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
} // End of namespace CGE
|