2019-12-03 23:28:28 +00:00
|
|
|
/*
|
|
|
|
**
|
|
|
|
** quotes.cpp
|
|
|
|
** Duke-Nukem-style quote buffer
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2019 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
** This is actually a VERY inefficient way to manage strings
|
|
|
|
** but needs to be preserved because the CON VM depends on it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quotemgr.h"
|
|
|
|
#include "savegamehelp.h"
|
2020-02-23 13:03:03 +00:00
|
|
|
#include "serializer.h"
|
|
|
|
#include "printf.h"
|
2019-12-03 23:28:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Quotes::MakeStringLabel(FString "e)
|
|
|
|
{
|
2019-12-09 23:01:45 +00:00
|
|
|
// Only prepend a quote if the string is localizable.
|
2023-10-08 07:15:32 +00:00
|
|
|
if (quote.Len() > 0 && quote[0] != '$' && GStrings[quote.GetChars()]) quote.Insert(0, "$");
|
2019-12-03 23:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Quotes::InitializeQuote(int num, const char *text, bool fromscript)
|
|
|
|
{
|
2019-12-03 23:38:43 +00:00
|
|
|
quotes[num] = text;
|
2019-12-03 23:28:28 +00:00
|
|
|
if (fromscript) // means this is the initial setup from the source data.
|
|
|
|
{
|
|
|
|
MakeStringLabel(quotes[num]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quotes::AppendQuote(int dst, int src, int len)
|
|
|
|
{
|
|
|
|
// This needs to apply the localization because the combined string is not localizable anymore.
|
2023-10-08 07:15:32 +00:00
|
|
|
if (quotes[dst][0] == '$') quotes[dst] = GStrings.localize(quotes[dst].GetChars());
|
|
|
|
if (len < 0) quotes[dst] << GStrings.localize(quotes[src].GetChars());
|
|
|
|
else quotes[dst] += FString(GStrings.localize(quotes[src].GetChars()), len);
|
2019-12-03 23:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Quotes::FormatQuote(int dst, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
quotes[dst].VFormat(fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quotes::Substitute(int dst, const char* text, const char* replc)
|
|
|
|
{
|
2023-10-08 07:15:32 +00:00
|
|
|
if (quotes[dst][0] == '$') quotes[dst] = GStrings.localize(quotes[dst].GetChars());
|
2019-12-03 23:28:28 +00:00
|
|
|
quotes[dst].Substitute(text, replc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-23 13:03:03 +00:00
|
|
|
void Quotes::Serialize(FSerializer &arc)
|
2019-12-03 23:28:28 +00:00
|
|
|
{
|
2020-07-21 19:32:38 +00:00
|
|
|
#if 0 // not needed without EDuke's extensions.
|
2020-02-23 13:03:03 +00:00
|
|
|
// This only saves the regular quotes. The ExQuotes array is immutable once initialized.
|
|
|
|
if (arc.BeginObject("quotes"))
|
2019-12-03 23:28:28 +00:00
|
|
|
{
|
2020-02-23 13:03:03 +00:00
|
|
|
for (int i = 0; i < MAXQUOTES; i++)
|
2019-12-03 23:28:28 +00:00
|
|
|
{
|
2020-02-23 13:03:03 +00:00
|
|
|
char buf[10];
|
|
|
|
mysnprintf(buf, 10, "%d", i);
|
|
|
|
FString nulstr;
|
|
|
|
arc(buf, quotes[i], nulstr);
|
2019-12-03 23:28:28 +00:00
|
|
|
}
|
2020-02-23 13:03:03 +00:00
|
|
|
arc.EndObject();
|
2019-12-03 23:28:28 +00:00
|
|
|
}
|
2020-07-21 19:32:38 +00:00
|
|
|
#endif
|
2019-12-03 23:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Quotes quoteMgr;
|