1:1 source port of the engine and game code; Windows build and system layer; docs. No game files or SDK headers.
This commit is contained in:
parent
c3b032a45a
commit
0ecb47e9cb
3871 changed files with 91080 additions and 1640063 deletions
503
port/game/BSGHelpers.cpp
Normal file
503
port/game/BSGHelpers.cpp
Normal file
|
|
@ -0,0 +1,503 @@
|
|||
// Port of the game's BSGHelpers.cpp (Chocolatier 3, Big Splash Games): numeric and date helpers, window helpers
|
||||
// (fill a window from a script, alpha, layered labels, translucent rectangles), the save-game string in the user's
|
||||
// prefs, user: file access, and RegisterBSGLuaHelpers, which publishes most of them to the window script.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// BSGHelpers.h (port/game/BSGHelpers.h, unchanged).
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Mod(a, b) returns the unsigned integer quotient (uint32_t)a / (uint32_t)b (b == 0 traps like the game).
|
||||
// - Date(t) counts days as 7 * t + 171 (t in weeks): year = days / 365 (shown + 1946), the day in the year walks the
|
||||
// file's daysPerMonth table; February is set to 29 or 28 days from the 0-based year (leap rule on days / 365, not
|
||||
// on the shown year). DayOfYear(t) is (7 * t) % 365 without the 171-day offset.
|
||||
// - PointToSegmentDistanceSquared: the closest point is segmentB when the projection t >= |segment|, otherwise
|
||||
// segmentA + direction * |segment| (the game multiplies by the segment length, not by t) -- kept.
|
||||
// - Dollars builds the grouped number right to left in a 32-byte stack buffer; a %.0f result longer than the buffer
|
||||
// overruns it in the game (numbers >= 1e24 or so) -- kept as is.
|
||||
// - ReadFromFile stores the terminator at buffer[n] before testing n > 0.
|
||||
//
|
||||
// Float details settled from the game disassembly: Mod, Date and DayOfYear convert to uint32_t with gcc's SSE
|
||||
// sequence (SseDoubleToUInt32, constants __const @0x00192700 / @0x00192740 / @0x001927d0); Date computes
|
||||
// 7.0 * t first, then + 171.0 (mulsd, addsd); RandRange converts both bounds with cvtsi2sd (signed), adds 1.0 and
|
||||
// truncates with cvttsd2si; SetAlpha divides by 255.0f (divss).
|
||||
//
|
||||
// HSVtoRGB (game @0x00036bd4), listed with BSGHelpers in choc3/cpp_src by name, lives in SignEditor.o (address
|
||||
// adjacency: SignEditor::GetTypeName @0x00036bc0 precedes it) and is not part of this file.
|
||||
// GetPoint(TLuaTable*, char const*) is declared in BSGHelpers.h but has no code in the game.
|
||||
//
|
||||
// Header-inline code emitted out of line in the game (bodies from BSGHelpers.h, Transitions.h, pf/*.h):
|
||||
// BSGHideWindow game @0x001654ac, BSGShowWindow game @0x00165c4c (BSGHelpers.h);
|
||||
// GetChildWindowCast<TLayeredWindow> game @0x00163754, GetChildWindowCast<TText> game @0x001637ec (BSGHelpers.h);
|
||||
// GetChildWindowCast<TSlider> game @0x0016d948, GetChildWindowCast<TTextEdit> game @0x0016dac4,
|
||||
// GetChildWindowCast<TImage> game @0x0016db5c (BSGHelpers.h; instantiated by the CurveEditor / RecipeDesigner objects);
|
||||
// TWindowFader::TWindowFader game @0x001636b0, TWindowFader::~TWindowFader game @0x00163704 (Transitions.h);
|
||||
// TWindow::GetCast<TLayeredWindow> game @0x00163720, TWindow::GetCast<TText> game @0x001637b8 (pf/window.h);
|
||||
// lua_pushdirectclosure<F> for F =
|
||||
// str (*)(double) game @0x00163850 void (*)(str, float) game @0x00163890
|
||||
// uint (*)(uint, uint) game @0x001638d0 double (*)(double) game @0x00163910
|
||||
// double (*)(double, double) game @0x00163950 void (*)(str, double, double) game @0x00163990
|
||||
// void (*)(str) game @0x001639d0 bool (*)(str) game @0x00163a10
|
||||
// void (*)(int, str, str) game @0x00163a50 void (*)(str, str) game @0x00163a90
|
||||
// str (*)(str) game @0x00163ad0 str (*)() game @0x00163b10
|
||||
// uint (*)() game @0x00163b50
|
||||
// LPCD::DirectCallFunctionDispatchHelper<F>::DirectCallFunctionDispatcher for F =
|
||||
// str (*)(double) game @0x00163c14 (its ReturnSpecialization<str>::Call<double> game @0x00163b90),
|
||||
// uint (*)() game @0x0016435c (Call game @0x00164304), str (*)() game @0x00164394 (Call game @0x00163d54),
|
||||
// str (*)(str) game @0x001643cc (Call game @0x00163f34), void (*)(str, str) game @0x00164404
|
||||
// (Call game @0x00163c4c), void (*)(int, str, str) game @0x0016443c (Call game @0x00163e84),
|
||||
// bool (*)(str) game @0x00164474 (Call game @0x00163e18), void (*)(str) game @0x001644ac
|
||||
// (Call game @0x00163dc4), void (*)(str, double, double) game @0x001644e4 (Call game @0x00164020),
|
||||
// double (*)(double, double) game @0x0016451c (Call game @0x001641fc), double (*)(double) game @0x00164554
|
||||
// (Call game @0x001640b0), uint (*)(uint, uint) game @0x0016458c (Call game @0x001640e8),
|
||||
// void (*)(str, float) game @0x001645c4 (Call game @0x00163ce0).
|
||||
// They match the pf/luapluscd.h templates. Port note: the game's Call<unsigned int, unsigned int> converts the
|
||||
// two Lua numbers to unsigned int with the SSE sequence (see sseconv.h); pf/luapluscd.h's
|
||||
// Get(TypeWrapper<unsigned int>) uses a plain cast, which differs only for arguments outside [0, 2^32).
|
||||
// Also emitted here: TMaterial::TMaterial game @0x00163fd8, TVert::TVert game @0x001636d4, TRandom::RandDouble
|
||||
// game @0x001635f8, TPlatform::IsEnabled game @0x001634f0 (engine headers).
|
||||
//
|
||||
// Strings from the game's __cstring: "month_%lu", "%lu", "date_format", "%.0f", "$0", "savegame", "local",
|
||||
// "anonymous", "firstpeek", "xsell", "xsell/xsell.lua", "dev", "user:", "", ".choco3", "label%d", and the
|
||||
// registered names "Date" .. "CurrentTime".
|
||||
//
|
||||
// Static data (__data): MONEY_SIGN '$' (@0x001d8020), NUMERIC_SEPARATOR ',' (@0x001d8021), daysPerMonth
|
||||
// {31,28,31,30,31,30,31,31,30,31,30,31} (@0x001d8040; [1] is rewritten by Date). __bss: GlobalRandomizer
|
||||
// (@0x0021e3e0), saveFileName (@0x0021e3c0, the GetNextFile iteration state of NextSaveFileName).
|
||||
// Static initializer: __static_initialization_and_destruction_0 game @0x001ab834 constructs GlobalRandomizer
|
||||
// (TRandom, no destructor registered) and saveFileName (destroyed by ___tcf_0 game @0x00004484);
|
||||
// __GLOBAL__I__Z11BSGFillRectR6TURectRK6TColor game @0x001ab87e jumps to it.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
|
||||
#include "settings.h"
|
||||
#include "Transitions.h"
|
||||
|
||||
#include "pf/layeredwindow.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/random.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/text.h"
|
||||
#include "pf/vertexset.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/screen.h"
|
||||
|
||||
#include "sseconv.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
static char MONEY_SIGN = '$';
|
||||
static char NUMERIC_SEPARATOR = ',';
|
||||
static uint32_t daysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
static TRandom GlobalRandomizer;
|
||||
static str saveFileName;
|
||||
|
||||
// game @0x00003160
|
||||
void RandSeed(uint32_t seed)
|
||||
{
|
||||
GlobalRandomizer.Seed(seed);
|
||||
}
|
||||
|
||||
// game @0x0000317c
|
||||
uint32_t RandRange(uint32_t bottom, uint32_t top)
|
||||
{
|
||||
return bottom + (int)((((double)(int32_t)top - (double)(int32_t)bottom) + 1.0) * GlobalRandomizer.RandDouble());
|
||||
}
|
||||
|
||||
// game @0x000031bc
|
||||
lua_Number Mod(lua_Number a, lua_Number b)
|
||||
{
|
||||
return SseDoubleToUInt32(a) / SseDoubleToUInt32(b);
|
||||
}
|
||||
|
||||
// game @0x00003290
|
||||
lua_Number Floor(lua_Number a)
|
||||
{
|
||||
return floor(a);
|
||||
}
|
||||
|
||||
// game @0x0000329a
|
||||
lua_Number Pow(lua_Number a, lua_Number b)
|
||||
{
|
||||
return pow(a, b);
|
||||
}
|
||||
|
||||
// game @0x000032a4
|
||||
str Date(lua_Number time)
|
||||
{
|
||||
uint32_t day = SseDoubleToUInt32(7.0 * time + 171.0);
|
||||
uint32_t year = day / 365;
|
||||
day = day % 365;
|
||||
|
||||
if ((year % 400) == 0 || ((year % 4) == 0 && (year % 100) != 0))
|
||||
{
|
||||
daysPerMonth[1] = 29;
|
||||
}
|
||||
else
|
||||
{
|
||||
daysPerMonth[1] = 28;
|
||||
}
|
||||
|
||||
int month = 0;
|
||||
while (day >= daysPerMonth[month])
|
||||
{
|
||||
day -= daysPerMonth[month];
|
||||
month++;
|
||||
}
|
||||
|
||||
str monthName = TPlatform::GetInstance()->GetStringTable()->GetString(str::getFormatted("month_%lu", month + 1));
|
||||
return TPlatform::GetInstance()->GetStringTable()->GetString(str("date_format"), monthName,
|
||||
str::getFormatted("%lu", day + 1), str::getFormatted("%lu", year + 1946));
|
||||
}
|
||||
|
||||
// game @0x00003680
|
||||
str Dollars(lua_Number number)
|
||||
{
|
||||
str result;
|
||||
if (number >= 0.5 || number <= -0.5)
|
||||
{
|
||||
if (number < 0)
|
||||
{
|
||||
result = str::getFormatted("%.0f", -number);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = str::getFormatted("%.0f", number);
|
||||
}
|
||||
|
||||
const char* src = result.c_str();
|
||||
int len = result.length();
|
||||
src += len;
|
||||
|
||||
char buffer[32];
|
||||
char* dst = &buffer[31];
|
||||
*dst = 0;
|
||||
while (len > 3)
|
||||
{
|
||||
*--dst = *--src;
|
||||
*--dst = *--src;
|
||||
*--dst = *--src;
|
||||
*--dst = NUMERIC_SEPARATOR;
|
||||
len -= 3;
|
||||
}
|
||||
while (len > 0)
|
||||
{
|
||||
*--dst = *--src;
|
||||
len--;
|
||||
}
|
||||
*--dst = MONEY_SIGN;
|
||||
if (number < 0)
|
||||
{
|
||||
*--dst = '-';
|
||||
}
|
||||
result = str(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "$0";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x0000385c
|
||||
TReal PointToSegmentDistanceSquared(TVec3 const& segmentA, TVec3 const& segmentB, TVec3 const& testPoint)
|
||||
{
|
||||
TVec3 v = testPoint - segmentA;
|
||||
TVec3 segment = segmentB - segmentA;
|
||||
TReal length = segment.Length();
|
||||
segment.Normalize();
|
||||
TReal t = DotProduct(v, segment);
|
||||
TVec3 closest(segmentA);
|
||||
if (t >= length)
|
||||
{
|
||||
closest = segmentB;
|
||||
}
|
||||
else
|
||||
{
|
||||
closest = segmentA + segment * length;
|
||||
}
|
||||
closest = closest - testPoint;
|
||||
return closest.LengthSquared();
|
||||
}
|
||||
|
||||
// game @0x00003966
|
||||
TVec2 GetPoint(TLuaTable* pTable)
|
||||
{
|
||||
TReal x = (TReal)pTable->GetNumber(1);
|
||||
TReal y = (TReal)pTable->GetNumber(2);
|
||||
return TVec2(x, y);
|
||||
}
|
||||
|
||||
// game @0x000039f6
|
||||
void FillWindowPtr(TWindow* pWindow, str luaFile)
|
||||
{
|
||||
if (pWindow)
|
||||
{
|
||||
pWindow->DestroyAllChildren();
|
||||
TWindowManager::GetInstance()->RunScript(pWindow, luaFile.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00003a36
|
||||
// Lua: SaveGameString(s). Stores s as "savegame" in the current user's prefs (nothing without a current user).
|
||||
void SaveGameString(str data)
|
||||
{
|
||||
TSettings* settings = TSettings::GetInstance();
|
||||
TPrefs* prefs = settings->GetPreferences();
|
||||
int user = settings->GetCurrentUser();
|
||||
if (user != -1)
|
||||
{
|
||||
prefs->SetStr("savegame", data, user, true);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00003ad6
|
||||
// Lua: LogScore(score, gameData, serverData).
|
||||
void LogScore(int score, str gameData, str serverData)
|
||||
{
|
||||
TSettings::GetInstance()->GetHiscores()->LogScore(score, true, gameData.c_str(), serverData.c_str());
|
||||
}
|
||||
|
||||
// game @0x00003b24
|
||||
// Lua: CheckConfig(key). "local", "anonymous", "firstpeek" read the hiscore platform settings, "xsell" tests for
|
||||
// xsell/xsell.lua, "dev" reads the cheat-mode setting; anything else is false.
|
||||
bool CheckConfig(str key)
|
||||
{
|
||||
if ((key == str("local") && TPlatform::GetInstance()->IsEnabled(TPlatform::kHiscoreLocalOnly)) ||
|
||||
(key == str("anonymous") && TPlatform::GetInstance()->IsEnabled(TPlatform::kHiscoreAnonymous)) ||
|
||||
(key == str("firstpeek") && TPlatform::GetInstance()->IsEnabled(TPlatform::kFirstPeek)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (key == str("xsell"))
|
||||
{
|
||||
return TFile::Exists("xsell/xsell.lua");
|
||||
}
|
||||
if (key == str("dev") && TPlatform::GetInstance()->IsEnabled(TPlatform::kCheatMode))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00003de0
|
||||
// Lua: WriteToFile(name, data). Writes data as text to user:name.
|
||||
void WriteToFile(str name, str data)
|
||||
{
|
||||
name = str("user:") + name;
|
||||
TFile file;
|
||||
file.Open(name, kWriteText);
|
||||
file.Write(data.c_str(), data.length());
|
||||
}
|
||||
|
||||
// game @0x00003ede
|
||||
// Lua: ReadFromFile(name). The text of user:name, read in chunks of up to 1023 bytes.
|
||||
str ReadFromFile(str name)
|
||||
{
|
||||
name = str("user:") + name;
|
||||
TFile file;
|
||||
file.Open(name, kReadText);
|
||||
str result;
|
||||
while (!file.AtEOF())
|
||||
{
|
||||
char buffer[1024];
|
||||
int count = file.Read(buffer, 1023);
|
||||
buffer[count] = 0;
|
||||
if (count > 0)
|
||||
{
|
||||
result = result + str(buffer);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x000040a2
|
||||
// Lua: NextSaveFileName(). Continues the enumeration of user: and returns the next "*.choco3" name without the
|
||||
// "user:" prefix and the extension; "" (and the enumeration restarts) when there are no more files.
|
||||
str NextSaveFileName()
|
||||
{
|
||||
str result("");
|
||||
bool found = false;
|
||||
bool more = true;
|
||||
while (more && !found)
|
||||
{
|
||||
more = TFile::GetNextFile(str("user:"), &saveFileName, false);
|
||||
found = false;
|
||||
if (more)
|
||||
{
|
||||
str extension(".choco3");
|
||||
if (saveFileName.substr(saveFileName.length() - 7, 7) == extension)
|
||||
{
|
||||
result = saveFileName.substr(5, saveFileName.length() - 12);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!more)
|
||||
{
|
||||
saveFileName = "";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x00004272
|
||||
void SetWindowAlpha(TWindow* pWindow, TReal alpha)
|
||||
{
|
||||
TWindowFader fader(alpha);
|
||||
fader.Process(pWindow);
|
||||
}
|
||||
|
||||
// game @0x000042be
|
||||
// Lua: SetAlpha(name, alpha). alpha 0..255.
|
||||
void SetAlpha(str name, float alpha)
|
||||
{
|
||||
TWindow* pWindow = TWindowManager::GetInstance()->GetScreen()->GetChildWindow(name, -1);
|
||||
if (pWindow)
|
||||
{
|
||||
SetWindowAlpha(pWindow, alpha / 255.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00004338
|
||||
// Lua: CurrentTime().
|
||||
uint32_t CurrentTime()
|
||||
{
|
||||
return TPlatform::GetInstance()->Timer();
|
||||
}
|
||||
|
||||
// game @0x0000434e
|
||||
// Lua: SetLayeredLabel(name, label). Sets the text windows "label0" .. "label3" of the layers 0..3 of the named
|
||||
// layered window in the top modal window, then restores its current layer.
|
||||
void SetLayeredLabel(str name, str label)
|
||||
{
|
||||
TLayeredWindow* pLayered =
|
||||
GetChildWindowCast<TLayeredWindow>(TWindowManager::GetInstance()->GetTopModalWindow(), name, -1);
|
||||
if (pLayered)
|
||||
{
|
||||
int32_t current = pLayered->GetCurrentLayer();
|
||||
for (int i = 0; i != 4; i++)
|
||||
{
|
||||
pLayered->SetCurrentLayer(i);
|
||||
TText* pText = GetChildWindowCast<TText>(pLayered, str::getFormatted("label%d", i), -1);
|
||||
if (pText)
|
||||
{
|
||||
pText->SetText(label);
|
||||
}
|
||||
}
|
||||
pLayered->SetCurrentLayer(current);
|
||||
}
|
||||
}
|
||||
|
||||
lua_Number DayOfYear(lua_Number time);
|
||||
void FillWindow(str windowName, str luaFile);
|
||||
void SetWindowPos(str name, lua_Number x, lua_Number y);
|
||||
str LoadGameString();
|
||||
|
||||
// game @0x00004494
|
||||
void RegisterBSGLuaHelpers()
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterDirect(script, "Date", Date);
|
||||
ScriptRegisterDirect(script, "DayOfYear", DayOfYear);
|
||||
ScriptRegisterDirect(script, "Dollars", Dollars);
|
||||
ScriptRegisterDirect(script, "Mod", Mod);
|
||||
ScriptRegisterDirect(script, "SetLayeredLabel", SetLayeredLabel);
|
||||
ScriptRegisterDirect(script, "SetAlpha", SetAlpha);
|
||||
ScriptRegisterDirect(script, "RandRange", RandRange);
|
||||
ScriptRegisterDirect(script, "Floor", Floor);
|
||||
ScriptRegisterDirect(script, "Pow", Pow);
|
||||
ScriptRegisterDirect(script, "FillWindow", FillWindow);
|
||||
ScriptRegisterDirect(script, "SetWindowPos", SetWindowPos);
|
||||
ScriptRegisterDirect(script, "LoadGameString", LoadGameString);
|
||||
ScriptRegisterDirect(script, "SaveGameString", SaveGameString);
|
||||
ScriptRegisterDirect(script, "CheckConfig", CheckConfig);
|
||||
ScriptRegisterDirect(script, "LogScore", LogScore);
|
||||
ScriptRegisterDirect(script, "WriteToFile", WriteToFile);
|
||||
ScriptRegisterDirect(script, "ReadFromFile", ReadFromFile);
|
||||
ScriptRegisterDirect(script, "NextSaveFileName", NextSaveFileName);
|
||||
ScriptRegisterDirect(script, "CurrentTime", CurrentTime);
|
||||
}
|
||||
|
||||
// game @0x00004984
|
||||
// Lua: FillWindow(windowName, luaFile). Replaces the children of the named window (searched from the screen) by
|
||||
// the windows the script builds.
|
||||
void FillWindow(str windowName, str luaFile)
|
||||
{
|
||||
TWindow* pWindow = TWindowManager::GetInstance()->GetScreen()->GetChildWindow(windowName, -1);
|
||||
if (pWindow)
|
||||
{
|
||||
FillWindowPtr(pWindow, luaFile);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00004a0e
|
||||
// Lua: SetWindowPos(name, x, y).
|
||||
void SetWindowPos(str name, lua_Number x, lua_Number y)
|
||||
{
|
||||
TWindow* pWindow = TWindowManager::GetInstance()->GetScreen()->GetChildWindow(name, -1);
|
||||
if (pWindow)
|
||||
{
|
||||
pWindow->SetWindowPos((int)x, (int)y);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00004aa4
|
||||
// Lua: LoadGameString(). The current user's "savegame" pref ("" without a current user).
|
||||
str LoadGameString()
|
||||
{
|
||||
TSettings* settings = TSettings::GetInstance();
|
||||
TPrefs* prefs = settings->GetPreferences();
|
||||
int user = settings->GetCurrentUser();
|
||||
str result;
|
||||
if (user != -1)
|
||||
{
|
||||
result = prefs->GetStr("savegame", "", user);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x00004b9a
|
||||
// An opaque colour goes to TRenderer::FillRect; a translucent one (0 < alpha < 1) is drawn as a lit triangle strip
|
||||
// with the colour as material; alpha <= 0 draws nothing.
|
||||
void BSGFillRect(TURect& rect, const TColor& color)
|
||||
{
|
||||
if (color.a == 1.0f)
|
||||
{
|
||||
TRenderer::GetInstance()->FillRect(rect, color, TTextureRef());
|
||||
}
|
||||
else if (color.a > 0)
|
||||
{
|
||||
TMaterial material;
|
||||
material.mcDiff = color;
|
||||
material.mcAmb = color;
|
||||
material.mcSpec = color;
|
||||
material.mcEmit = color;
|
||||
material.mfPower = 0;
|
||||
TRenderer::GetInstance()->SetMaterial(&material);
|
||||
|
||||
TVert vertices[4];
|
||||
vertices[0].pos.x = (TReal)rect.x1;
|
||||
vertices[1].pos.x = (TReal)rect.x2;
|
||||
vertices[0].pos.y = (TReal)rect.y1;
|
||||
vertices[2].pos.y = (TReal)rect.y2;
|
||||
vertices[3].pos.z = 0;
|
||||
vertices[2].pos.z = 0;
|
||||
vertices[1].pos.z = 0;
|
||||
vertices[0].pos.z = 0;
|
||||
vertices[1].pos.y = vertices[0].pos.y;
|
||||
vertices[2].pos.x = vertices[0].pos.x;
|
||||
vertices[3].pos.x = vertices[1].pos.x;
|
||||
vertices[3].pos.y = vertices[2].pos.y;
|
||||
vertices[0].normal = vertices[1].normal = vertices[2].normal = vertices[3].normal = TVec3(0, 0, 1);
|
||||
TVertexSet vertexSet(vertices, 4);
|
||||
TRenderer::GetInstance()->DrawVertices(TRenderer::kDrawTriStrip, vertexSet);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00004dc4
|
||||
// Lua: DayOfYear(t) = (7 * t) % 365.
|
||||
lua_Number DayOfYear(lua_Number time)
|
||||
{
|
||||
return SseDoubleToUInt32(7.0 * time) % 365;
|
||||
}
|
||||
178
port/game/BSGSound.cpp
Normal file
178
port/game/BSGSound.cpp
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
// Port of the game's BSGSound.cpp (Chocolatier 3, Big Splash Games): the game's sound front end over the CADI-lite
|
||||
// engine (cadilite.cpp) and Playground sounds: init/shutdown (registers the Lua SoundEvent), sound events, mute and
|
||||
// the volume levels, pause / deactivate.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// BSGSound.h (port/game/BSGSound.h, unchanged).
|
||||
//
|
||||
// Binary vs. choc3/cpp_bindings/NOTES.md: BSGSoundEvent sends every event whose name does NOT start with
|
||||
// "firework" to CadiEvent (str::find("firework") != 0, settled from the disassembly @0x00005376); only names that
|
||||
// start with "firework" are played as Playground sounds "sfx/<name>.ogg" (kept in the file's sound map). "ui_click"
|
||||
// is played from "cadi/ui_click.ogg". The notes describe the routing the other way round.
|
||||
//
|
||||
// Header-inline code emitted out of line: lua_pushdirectclosure<void (*)(str)> and its dispatcher are shared with
|
||||
// BSGHelpers.o (game @0x001639d0 / @0x001644ac).
|
||||
//
|
||||
// Strings from the game's __cstring: "Music Volume", "Sfx Volume", "Environments Volume", "/assets/cadi",
|
||||
// "SoundEvent", "ui_click" (@0x00158404), "cadi/ui_click.ogg" (@0x00158410), "firework", ".ogg" (@0x00158430),
|
||||
// "sfx/" (@0x00158438), "Unpause", "Pause".
|
||||
//
|
||||
// Static data: soundMap (TAssetMap, __bss @0x0021edc0), gSoundDeactivated (@0x0021ede0) and gSoundPaused
|
||||
// (@0x0021ede1), both zero-initialized. Static initializer: __static_initialization_and_destruction_0 game
|
||||
// @0x001ab892 constructs soundMap (destroyed by ___tcf_0 game @0x00004ffa); __GLOBAL__I__Z12BSGSoundInitv game
|
||||
// @0x001ab8d0 jumps to it.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "BSGSound.h"
|
||||
|
||||
#include "CadiApi.h"
|
||||
#include "globaldefines.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "pf/assetmap.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/sound.h"
|
||||
#include "pf/soundinstance.h"
|
||||
#include "pf/soundmanager.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
static TAssetMap soundMap;
|
||||
static bool gSoundDeactivated;
|
||||
static bool gSoundPaused;
|
||||
|
||||
// game @0x00004e78
|
||||
void BSGSoundMute(bool mute)
|
||||
{
|
||||
if (mute)
|
||||
{
|
||||
TPlatform::GetInstance()->GetSoundManager()->SetVolume(0);
|
||||
CadiEvent("Music Volume", 0);
|
||||
CadiEvent("Sfx Volume", 0);
|
||||
CadiEvent("Environments Volume", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
TPlatform::GetInstance()->GetSoundManager()->SetVolume(1.0f);
|
||||
TSettings::GetInstance()->SetSoundForCurrentUser();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00004f22
|
||||
void BSGSetMusicLevel(float volume)
|
||||
{
|
||||
TPlatform::GetInstance()->GetSoundManager()->SetTypeVolume(kMusicSoundGroup, volume);
|
||||
CadiEvent("Music Volume", volume);
|
||||
}
|
||||
|
||||
// game @0x00004f6a
|
||||
void BSGSetSoundLevel(float volume)
|
||||
{
|
||||
TPlatform::GetInstance()->GetSoundManager()->SetTypeVolume(kSFXSoundGroup, volume);
|
||||
TPlatform::GetInstance()->GetSoundManager()->SetTypeVolume(0, volume);
|
||||
CadiEvent("Sfx Volume", volume);
|
||||
}
|
||||
|
||||
// game @0x00004fda
|
||||
void BSGSetAmbientLevel(float volume)
|
||||
{
|
||||
CadiEvent("Environments Volume", volume);
|
||||
}
|
||||
|
||||
// game @0x0000500a
|
||||
void BSGSoundInit(void)
|
||||
{
|
||||
str path = TFile::GetCWD() + str("/assets/cadi");
|
||||
CadiInit(path.c_str(), 0);
|
||||
ScriptRegisterDirect(TWindowManager::GetInstance()->GetScript(), "SoundEvent", BSGSoundEvent);
|
||||
}
|
||||
|
||||
// game @0x00005104
|
||||
void BSGSoundShutdown(void)
|
||||
{
|
||||
ScriptUnregisterFunction(TWindowManager::GetInstance()->GetScript(), "SoundEvent");
|
||||
CadiShutdown();
|
||||
}
|
||||
|
||||
// game @0x00005166
|
||||
// Lua: SoundEvent(key). See the file comment for the routing.
|
||||
void BSGSoundEvent(str key)
|
||||
{
|
||||
TSoundRef sound;
|
||||
if (key == str("ui_click"))
|
||||
{
|
||||
sound = soundMap.GetSound("ui_click");
|
||||
if (!sound)
|
||||
{
|
||||
sound = TSound::Get("cadi/ui_click.ogg", true, kSFXSoundGroup);
|
||||
if (sound)
|
||||
{
|
||||
soundMap.AddAsset("ui_click", sound, false);
|
||||
}
|
||||
}
|
||||
if (sound)
|
||||
{
|
||||
sound->Play(false);
|
||||
}
|
||||
}
|
||||
else if (key.find("firework", 0, 0) != 0)
|
||||
{
|
||||
CadiEvent(key.c_str(), 0);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
sound = soundMap.GetSound(key);
|
||||
if (!sound)
|
||||
{
|
||||
sound = TSound::Get(str("sfx/") + key + str(".ogg"), true, kSFXSoundGroup);
|
||||
if (sound)
|
||||
{
|
||||
soundMap.AddAsset(key, sound, false);
|
||||
}
|
||||
}
|
||||
if (sound)
|
||||
{
|
||||
sound->Play(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000055f0
|
||||
void BSGSoundActivate(void)
|
||||
{
|
||||
if (!gSoundPaused && gSoundDeactivated)
|
||||
{
|
||||
gSoundDeactivated = false;
|
||||
BSGSoundEvent("Unpause");
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00005650
|
||||
void BSGSoundDeactivate(void)
|
||||
{
|
||||
if (!gSoundPaused && !gSoundDeactivated)
|
||||
{
|
||||
gSoundDeactivated = true;
|
||||
BSGSoundEvent("Pause");
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000056b0
|
||||
void BSGSoundUnpause(void)
|
||||
{
|
||||
if (gSoundPaused)
|
||||
{
|
||||
gSoundPaused = false;
|
||||
BSGSoundEvent("Unpause");
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00005706
|
||||
void BSGSoundPause(void)
|
||||
{
|
||||
if (!gSoundPaused)
|
||||
{
|
||||
gSoundPaused = true;
|
||||
BSGSoundEvent("Pause");
|
||||
}
|
||||
}
|
||||
200
port/game/BSGStringTable.cpp
Normal file
200
port/game/BSGStringTable.cpp
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
// Port of the game's BSGStringTable.cpp (Chocolatier 3, Big Splash Games): a runtime-loadable string table in
|
||||
// front of the Playground TStringTable. Strings come from Excel XML workbooks (Workbook/Worksheet/Table/Row, the
|
||||
// first two cells' Data are key and value); lookups fall back to the platform string table, and %key% references
|
||||
// inside a string are expanded recursively. The constructor publishes bsgLoadStringFile / bsgStringExists /
|
||||
// bsgGetString to the window script, the destructor removes them.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// BSGStringTable.h (port/game/BSGStringTable.h, unchanged).
|
||||
//
|
||||
// GetString details (settled from the disassembly): a key that starts with '#' is returned without the '#'. In the
|
||||
// looked-up string, "%%" becomes "%" (the search continues after it); "%name%" is replaced (str::replace with
|
||||
// kReplaceAll, from the reference's position on) by GetString(name); a result of "#####" becomes "<--name-->"
|
||||
// before the replacement. The replacement is skipped only if the result still equals "#####" (str::compare, i.e.
|
||||
// operator!=), which cannot happen after that substitution. An unterminated '%' ends the expansion.
|
||||
//
|
||||
// Header-inline code emitted out of line: lua_pushdirectclosure<void (*)(str)> / <bool (*)(str)> /
|
||||
// <str (*)(str)> and their dispatchers are shared with BSGHelpers.o (game @0x001639d0 / @0x00163a10 /
|
||||
// @0x00163ad0, dispatchers @0x001644ac / @0x00164474 / @0x001643cc). The std::map<str, str> members used here are
|
||||
// libstdc++ template code (game @0x00164688 .. @0x00164ce0), not ported.
|
||||
//
|
||||
// Strings from the game's __cstring: "#####", "<--", "-->", "Workbook", "Worksheet", "Table", "Row", "Cell", "Data",
|
||||
// "bsgLoadStringFile", "bsgStringExists", "bsgGetString".
|
||||
//
|
||||
// Static data: BSGStringTable::pInstance (__data @0x001d8080, initialized NULL). No static initializer.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "BSGStringTable.h"
|
||||
|
||||
#include "pf/script.h"
|
||||
#include "pf/simplexml.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
BSGStringTable* BSGStringTable::pInstance = 0;
|
||||
|
||||
// game @0x0000575c
|
||||
str BSGStringTable::GetString(str key) const
|
||||
{
|
||||
str result;
|
||||
if (key[0] == '#')
|
||||
{
|
||||
return key.substr(1, -1);
|
||||
}
|
||||
|
||||
map<str, str>::const_iterator i = strings.find(key);
|
||||
if (i == strings.end())
|
||||
{
|
||||
result = TPlatform::GetInstance()->GetStringTable()->GetString(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = i->second;
|
||||
}
|
||||
|
||||
int start = result.find('%', 0, 0);
|
||||
while (start != -1)
|
||||
{
|
||||
int next = start + 1;
|
||||
int end = result.find('%', 0, next);
|
||||
if (end == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (next == end)
|
||||
{
|
||||
result.erase(start, 1);
|
||||
next = start;
|
||||
}
|
||||
else
|
||||
{
|
||||
int length = end - start;
|
||||
str name = result.substr(next, length - 1);
|
||||
str value = GetString(name);
|
||||
if (value == str("#####"))
|
||||
{
|
||||
value = str("<--") + (name + str("-->"));
|
||||
}
|
||||
next = end;
|
||||
if (value != str("#####"))
|
||||
{
|
||||
name = result.substr(start, length + 1);
|
||||
result.replace(name, value, str::kReplaceAll, start);
|
||||
next = start + value.length();
|
||||
}
|
||||
}
|
||||
if (next == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
start = result.find('%', 0, next + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x00005ccc
|
||||
// Lua: bsgGetString(key).
|
||||
str bsgGetString(str key)
|
||||
{
|
||||
return BSGStringTable::GetInstance()->GetString(key);
|
||||
}
|
||||
|
||||
// game @0x00005d28
|
||||
// Lua: bsgLoadStringFile(file). Adds the rows of an Excel XML workbook; rows with an empty key are skipped, an
|
||||
// existing key is overwritten. Nothing happens when the file does not exist.
|
||||
void BSGStringTable::LoadStringFile(str file)
|
||||
{
|
||||
if (!TFile::Exists(file))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TXmlNode root;
|
||||
root.ParseFile(file.c_str());
|
||||
TXmlNode* pNode = root.GetChild("Workbook");
|
||||
if (pNode)
|
||||
{
|
||||
pNode = pNode->GetChild("Worksheet");
|
||||
if (pNode)
|
||||
{
|
||||
TXmlNode* pTable = pNode->GetChild("Table");
|
||||
if (pTable)
|
||||
{
|
||||
str name;
|
||||
TXmlNode* pRow;
|
||||
pTable->ResetChildren();
|
||||
while (pTable->GetNextChild(&name, &pRow))
|
||||
{
|
||||
if (name.compare(str("Row")) == 0)
|
||||
{
|
||||
str key;
|
||||
str value;
|
||||
TXmlNode* pCell;
|
||||
pRow->ResetChildren();
|
||||
if (pRow->GetNextChild(&name, &pCell) && name == str("Cell"))
|
||||
{
|
||||
pCell = pCell->GetChild("Data");
|
||||
if (pCell)
|
||||
{
|
||||
key = pCell->GetContent();
|
||||
}
|
||||
}
|
||||
if (pRow->GetNextChild(&name, &pCell) && name == str("Cell"))
|
||||
{
|
||||
pCell = pCell->GetChild("Data");
|
||||
if (pCell)
|
||||
{
|
||||
value = pCell->GetContent();
|
||||
}
|
||||
}
|
||||
if (key.length() != 0)
|
||||
{
|
||||
strings[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000060aa
|
||||
// Lua: bsgLoadStringFile(file).
|
||||
void bsgLoadStringFile(str file)
|
||||
{
|
||||
BSGStringTable::GetInstance()->LoadStringFile(file);
|
||||
}
|
||||
|
||||
// game @0x000060f8
|
||||
BSGStringTable::~BSGStringTable(void)
|
||||
{
|
||||
pInstance = 0;
|
||||
TScript* script = TPlatform::GetInstance()->GetWindowManager()->GetScript();
|
||||
ScriptUnregisterFunction(script, "bsgLoadStringFile");
|
||||
ScriptUnregisterFunction(script, "bsgStringExists");
|
||||
ScriptUnregisterFunction(script, "bsgGetString");
|
||||
}
|
||||
|
||||
bool bsgStringExists(str key);
|
||||
|
||||
// game @0x000061dc
|
||||
BSGStringTable::BSGStringTable(void)
|
||||
{
|
||||
pInstance = this;
|
||||
TScript* script = TPlatform::GetInstance()->GetWindowManager()->GetScript();
|
||||
ScriptRegisterDirect(script, "bsgLoadStringFile", bsgLoadStringFile);
|
||||
ScriptRegisterDirect(script, "bsgStringExists", bsgStringExists);
|
||||
ScriptRegisterDirect(script, "bsgGetString", bsgGetString);
|
||||
}
|
||||
|
||||
// game @0x000062ec
|
||||
bool BSGStringTable::StringExists(str key) const
|
||||
{
|
||||
return strings.find(key) != strings.end();
|
||||
}
|
||||
|
||||
// game @0x00006316
|
||||
// Lua: bsgStringExists(key).
|
||||
bool bsgStringExists(str key)
|
||||
{
|
||||
return BSGStringTable::GetInstance()->StringExists(key);
|
||||
}
|
||||
209
port/game/BSGWindow.cpp
Normal file
209
port/game/BSGWindow.cpp
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
// Port of the game's BSGWindow.cpp (Chocolatier 3, Big Splash Games): TBSGWindow, the game's base window: an
|
||||
// optional translucent flat-colour fill, an optional nine-part frame (an animated texture with frames UL, UR, LL,
|
||||
// LR, LEFT, RIGHT, TOP, BOTTOM and an optional ORNAMENT), alpha propagated to the children, right-click events and
|
||||
// optional swallowing of mouse events.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// BSGWindow.h (port/game/BSGWindow.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TWindow 0x30, pFrame +0x30, fill +0x38, color +0x3c, swallowMouse +0x4c; sizeof 0x50
|
||||
// (TBSGWindowDynamicCreate allocates 0x50). The header matches.
|
||||
//
|
||||
// Header-inline code emitted out of line (bodies match BSGWindow.h): OnRightMouseDown game @0x00164db0,
|
||||
// OnRightMouseUp game @0x00164db8, OnMouseMove game @0x00164dc0, OnMouseDown game @0x00164dcc, OnMouseUp game
|
||||
// game @0x00164dd8 (each "swallowMouse || TWindow::OnMouse...(point)" with TWindow's inline "return false", compiled to
|
||||
// "return swallowMouse"), IsKindOf game @0x00164dfc (PFTYPEDEF_DC), GetChildWindowCast<TText> game @0x001655c4
|
||||
// and GetChildWindowCast<TImage> game @0x0016ff30 (instantiated by other objects).
|
||||
//
|
||||
// Float details from the disassembly: DrawFrame steps the edge loops in single precision (cvtsi2ss of the window
|
||||
// edges and of the frame width/height, addss, ucomiss); the ornament's x is (float)((double)(x1 + x2) * 0.5).
|
||||
//
|
||||
// Strings from the game's __cstring: "TBSGWindow", "swallowmouse" (@0x001584d4), "frame" (@0x001584e4), "" ,
|
||||
// ".xml", "color", "fill". No static data; the object has no static initializer.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "BSGWindow.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "Transitions.h"
|
||||
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/screen.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
// game @0x000068dc (TBSGWindowDynamicCreate: new TBSGWindow, sizeof 0x50)
|
||||
// game @0x0000636c (ClassId: returns &TBSGWindowDynamicCreate)
|
||||
// game @0x00006376 (GetTypeName, "TBSGWindow")
|
||||
PFTYPEIMPL_DC(TBSGWindow);
|
||||
|
||||
// game @0x00006380
|
||||
bool TBSGWindow::OnExtendedMouseEvent(TPoint const& point, TPlatform::ExtendedMouseEvents event)
|
||||
{
|
||||
if (swallowMouse)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (event == TPlatform::kMouseRightDown)
|
||||
{
|
||||
return OnRightMouseDown(point);
|
||||
}
|
||||
if (event == TPlatform::kMouseRightUp)
|
||||
{
|
||||
return OnRightMouseUp(point);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x000063cc
|
||||
// Alpha outside [0, 1] (or NaN) is ignored; otherwise it becomes the fill alpha and, with propagate, is applied to
|
||||
// every child (TWindowFader).
|
||||
void TBSGWindow::SetAlpha(TReal alpha, bool propagate)
|
||||
{
|
||||
if (alpha >= 0 && alpha <= 1)
|
||||
{
|
||||
color.a = alpha;
|
||||
if (propagate)
|
||||
{
|
||||
TWindowFader fader(alpha);
|
||||
ForEachChild(&fader, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00006448 (D0) / game @0x00006492 (D1) / game @0x000064d4 (D2)
|
||||
TBSGWindow::~TBSGWindow(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x00006516
|
||||
void TBSGWindow::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
|
||||
swallowMouse = style.GetBool("swallowmouse", false);
|
||||
|
||||
str frameName = style.GetString("frame", "");
|
||||
if (frameName.length() != 0)
|
||||
{
|
||||
if (frameName.find(".xml", 0, 0) == -1)
|
||||
{
|
||||
frameName = frameName + str(".xml");
|
||||
}
|
||||
pFrame = TAnimatedTexture::Get(frameName, "", "");
|
||||
}
|
||||
|
||||
color = style.GetColor("color", color);
|
||||
if (color.a >= 0 && color.a <= 1)
|
||||
{
|
||||
SetAlpha(color.a, true);
|
||||
}
|
||||
|
||||
fill = style.GetBool("fill", fill);
|
||||
}
|
||||
|
||||
// game @0x00006892 (C1) / game @0x00006918 (C2)
|
||||
TBSGWindow::TBSGWindow(void) :
|
||||
fill(true),
|
||||
color(1, 1, 1, 0),
|
||||
swallowMouse(false)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x00006962
|
||||
// Draws the frame around the window rectangle with the screen as viewport: the top and bottom edges tiled from x1
|
||||
// to x2 (clipped to the window's x range), the left and right edges tiled from y1 to y2 (clipped to the window's y
|
||||
// range), then the corners and, when the texture has more than 8 frames, the ornament centred on the top edge.
|
||||
// The viewport and clipping rectangle are restored afterwards.
|
||||
void TBSGWindow::DrawFrame(void)
|
||||
{
|
||||
TRect viewport;
|
||||
TRect clip = TRenderer::GetInstance()->GetClippingRectangle();
|
||||
TRenderer::GetInstance()->GetViewport(&viewport);
|
||||
|
||||
TRect window;
|
||||
GetWindowRect(&window);
|
||||
TRect screen;
|
||||
TPlatform::GetInstance()->GetWindowManager()->GetScreen()->GetWindowRect(&screen);
|
||||
TRenderer::GetInstance()->SetViewport(screen);
|
||||
|
||||
TRenderer::GetInstance()->SetClippingRectangle(
|
||||
TRect(window.x1 > -1 ? window.x1 : 0, screen.y1, window.x2 > -1 ? window.x2 : 0, screen.y2));
|
||||
|
||||
pFrame->SetCurrentFrame(FRAME_TOP);
|
||||
TRect rect = pFrame->GetFrameRect(FRAME_TOP);
|
||||
TReal step = (TReal)(rect.x2 - rect.x1);
|
||||
for (TReal x = (TReal)window.x1; x < (TReal)window.x2; x += step)
|
||||
{
|
||||
pFrame->DrawSprite(x, (TReal)window.y1, color.a, 1, 0, 0);
|
||||
}
|
||||
|
||||
pFrame->SetCurrentFrame(FRAME_BOTTOM);
|
||||
rect = pFrame->GetFrameRect(FRAME_BOTTOM);
|
||||
step = (TReal)(rect.x2 - rect.x1);
|
||||
for (TReal x = (TReal)window.x1; x < (TReal)window.x2; x += step)
|
||||
{
|
||||
pFrame->DrawSprite(x, (TReal)window.y2, color.a, 1, 0, 0);
|
||||
}
|
||||
|
||||
TRenderer::GetInstance()->SetClippingRectangle(
|
||||
TRect(screen.x1, window.y1 > -1 ? window.y1 : 0, screen.x2, window.y2 > -1 ? window.y2 : 0));
|
||||
|
||||
pFrame->SetCurrentFrame(FRAME_LEFT);
|
||||
rect = pFrame->GetFrameRect(FRAME_LEFT);
|
||||
step = (TReal)(rect.y2 - rect.y1);
|
||||
for (TReal y = (TReal)window.y1; y < (TReal)window.y2; y += step)
|
||||
{
|
||||
pFrame->DrawSprite((TReal)window.x1, y, color.a, 1, 0, 0);
|
||||
}
|
||||
|
||||
pFrame->SetCurrentFrame(FRAME_RIGHT);
|
||||
rect = pFrame->GetFrameRect(FRAME_RIGHT);
|
||||
step = (TReal)(rect.y2 - rect.y1);
|
||||
for (TReal y = (TReal)window.y1; y < (TReal)window.y2; y += step)
|
||||
{
|
||||
pFrame->DrawSprite((TReal)window.x2, y, color.a, 1, 0, 0);
|
||||
}
|
||||
|
||||
TRenderer::GetInstance()->SetClippingRectangle(TRect(screen.x1, screen.y1, screen.x2, screen.y2));
|
||||
|
||||
pFrame->SetCurrentFrame(FRAME_UL);
|
||||
pFrame->DrawSprite((TReal)window.x1, (TReal)window.y1, color.a, 1, 0, 0);
|
||||
pFrame->SetCurrentFrame(FRAME_UR);
|
||||
pFrame->DrawSprite((TReal)window.x2, (TReal)window.y1, color.a, 1, 0, 0);
|
||||
pFrame->SetCurrentFrame(FRAME_LL);
|
||||
pFrame->DrawSprite((TReal)window.x1, (TReal)window.y2, color.a, 1, 0, 0);
|
||||
pFrame->SetCurrentFrame(FRAME_LR);
|
||||
pFrame->DrawSprite((TReal)window.x2, (TReal)window.y2, color.a, 1, 0, 0);
|
||||
|
||||
if (pFrame->GetNumFrames() > FRAME_ORNAMENT)
|
||||
{
|
||||
pFrame->SetCurrentFrame(FRAME_ORNAMENT);
|
||||
pFrame->DrawSprite((TReal)((double)(window.x1 + window.x2) * 0.5), (TReal)window.y1, color.a, 1, 0, 0);
|
||||
}
|
||||
|
||||
TRenderer::GetInstance()->SetViewport(viewport);
|
||||
TRenderer::GetInstance()->SetClippingRectangle(clip);
|
||||
}
|
||||
|
||||
// game @0x0000710e
|
||||
void TBSGWindow::Draw(void)
|
||||
{
|
||||
if (fill)
|
||||
{
|
||||
TBegin2d begin2d;
|
||||
TURect rect;
|
||||
GetClientRect(&rect);
|
||||
BSGFillRect(rect, color);
|
||||
begin2d.Done();
|
||||
}
|
||||
|
||||
TWindow::Draw();
|
||||
|
||||
if (pFrame)
|
||||
{
|
||||
TBegin2d begin2d;
|
||||
DrawFrame();
|
||||
begin2d.Done();
|
||||
}
|
||||
}
|
||||
196
port/game/BitmapTint.cpp
Normal file
196
port/game/BitmapTint.cpp
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
// Port of the game's BitmapTint.cpp (Chocolatier 3, Big Splash Games): TBitmapTint, a TImage that is drawn with a
|
||||
// color tint, an offset and an optional horizontal flip, plus its Lua functions (BTSetTint, BTSetOffset,
|
||||
// BTSetBitmap, BTSetFlip).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// BitmapTint.h (port/game/BitmapTint.h, unchanged). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): TBitmapTint : TImage (0x48) tint 0x48 (4 floats r g b a), dx 0x58, dy 0x5c, width 0x60,
|
||||
// height 0x64, hflip 0x68. The header matches. TImage keeps its texture at 0x30 (shared_ptr) and its scale at 0x38.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The constructor sets tint to (1, 1, 1, 1), dx = dy = 0 and hflip = false; width and height are left unset.
|
||||
// The first constructed instance registers the Lua functions (functionsRegistered, __bss, initially false).
|
||||
// - Init keys (strings from the game's __cstring): "image", "mask", "scale" (default 1), "alpha" (bool, texture flag 2),
|
||||
// "mipmap" (non-zero: texture flag 1), "tint" (a table of r g b a, default 1 each; the table is deleted), "dx" / "dy"
|
||||
// (default -9999), "hflip", "w" / "h" (default -1; the window is resized when both are positive).
|
||||
// Texture: image and mask both set: TTexture::GetMerged(image, mask, flags); only image set: TTexture::Get(image,
|
||||
// flags); else none. width / height are taken from the final window rect.
|
||||
// - Draw offsets the sprite by scale * (dx, dy); a dx / dy of exactly -9999 centers the sprite on that axis (half
|
||||
// the window width / height computed in double).
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFTYPEDEF_DC: TBitmapTintDynamicCreate game @0x0003b7fe, ClassId game @0x0003b568, GetTypeName game @0x0003b572,
|
||||
// IsKindOf game @0x00175338. ~TBitmapTint: D1 game @0x001752f8, D0 game @0x00175310 (also deletes).
|
||||
// TWindow::GetCast<TBitmapTint> game @0x00172bbc, GetChildWindowCast<TBitmapTint> game @0x00172bf0 (templates).
|
||||
// The Lua registration emits lua_pushdirectclosure<void (*)(str, TLuaTable*)> game @0x00175110,
|
||||
// <void (*)(str, str, double)> game @0x00175150, <void (*)(str, bool)> game @0x00175190, with their dispatchers
|
||||
// LPCD::ReturnSpecialization<void>::Call<str, TLuaTable*> game @0x001751d0, <str, bool> game @0x0017527c,
|
||||
// <str, str, double> game @0x00175364 and DirectCallFunctionDispatchHelper<void (*)(str, TLuaTable*)> game
|
||||
// game @0x00175244, <void (*)(str, bool)> game @0x00175414, <void (*)(str, str, double)> game @0x0017544c (the
|
||||
// TRectangle registration in Rectangle.cpp shares the (str, TLuaTable*) instances). SetOffset / SetFlip / SetTint(TColor)
|
||||
// have no code in the game binary.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "BitmapTint.h"
|
||||
#include "sseconv.h"
|
||||
|
||||
#include "pf/drawspec.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
PFTYPEIMPL_DC(TBitmapTint);
|
||||
|
||||
// game @0x001d8200 (__data, initial value false)
|
||||
bool TBitmapTint::functionsRegistered = false;
|
||||
|
||||
// game @0x0003b57e
|
||||
void TBitmapTint::SetTint(TLuaTable* pColor)
|
||||
{
|
||||
if (pColor != 0) {
|
||||
tint.r = (float)pColor->GetNumber(1.0, 1.0);
|
||||
tint.g = (float)pColor->GetNumber(2.0, 1.0);
|
||||
tint.b = (float)pColor->GetNumber(3.0, 1.0);
|
||||
tint.a = (float)pColor->GetNumber(4.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003b672
|
||||
TBitmapTint::TBitmapTint(void) :
|
||||
TImage(true),
|
||||
tint(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
dx(0),
|
||||
dy(0),
|
||||
hflip(false)
|
||||
{
|
||||
if (!functionsRegistered) {
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterDirect(script, "BTSetTint", SetBitmapTint);
|
||||
ScriptRegisterDirect(script, "BTSetOffset", SetBitmapOffset);
|
||||
ScriptRegisterDirect(script, "BTSetBitmap", SetBitmapTexture);
|
||||
ScriptRegisterDirect(script, "BTSetFlip", SetBitmapFlip);
|
||||
functionsRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003b83a
|
||||
TBitmapTint* TBitmapTint::ByName(str windowName)
|
||||
{
|
||||
TWindow* pTop = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pTop != 0) {
|
||||
TWindow* pWindow = pTop->GetChildWindow(windowName, -1);
|
||||
if (pWindow != 0) {
|
||||
return pWindow->GetCast<TBitmapTint>();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// game @0x0003b8b6
|
||||
void TBitmapTint::SetBitmapTint(str windowName, TLuaTable* pColor)
|
||||
{
|
||||
TBitmapTint* pTint = ByName(windowName);
|
||||
if (pTint != 0) {
|
||||
pTint->SetTint(pColor);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003b910
|
||||
void TBitmapTint::SetBitmapFlip(str windowName, bool flip)
|
||||
{
|
||||
TBitmapTint* pTint = ByName(windowName);
|
||||
if (pTint != 0) {
|
||||
pTint->hflip = flip;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003b966
|
||||
void TBitmapTint::SetBitmapOffset(str windowName, lua_Number dx, lua_Number dy)
|
||||
{
|
||||
TBitmapTint* pTint = ByName(windowName);
|
||||
if (pTint != 0) {
|
||||
pTint->dx = (float)dx;
|
||||
pTint->dy = (float)dy;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003b9da
|
||||
void TBitmapTint::SetBitmapTexture(str windowName, str bitmapName, lua_Number scale)
|
||||
{
|
||||
TBitmapTint* pTint = ByName(windowName);
|
||||
if (pTint != 0) {
|
||||
TTextureRef pTexture = TTexture::Get(bitmapName, 0);
|
||||
pTint->SetTexture(pTexture, (float)scale);
|
||||
pTint->SetWindowSize(pTint->width, pTint->height);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003bafa
|
||||
void TBitmapTint::Init(TWindowStyle& style)
|
||||
{
|
||||
TImage::Init(style);
|
||||
str image = style.GetString("image", "");
|
||||
str mask = style.GetString("mask", "");
|
||||
TReal scale = (TReal)style.GetNumber("scale", 1.0);
|
||||
uint32_t flags = style.GetBool("alpha", false) ? 2 : 0;
|
||||
if (style.GetNumber("mipmap", 0.0) != 0.0) {
|
||||
flags = flags | 1;
|
||||
}
|
||||
TLuaTable* pTint = style.GetTable("tint");
|
||||
if (pTint != 0) {
|
||||
tint.r = (float)pTint->GetNumber(1.0, 1.0);
|
||||
tint.g = (float)pTint->GetNumber(2.0, 1.0);
|
||||
tint.b = (float)pTint->GetNumber(3.0, 1.0);
|
||||
tint.a = (float)pTint->GetNumber(4.0, 1.0);
|
||||
delete pTint;
|
||||
}
|
||||
dx = (float)style.GetNumber("dx", -9999.0);
|
||||
dy = (float)style.GetNumber("dy", -9999.0);
|
||||
hflip = style.GetBool("hflip", false);
|
||||
|
||||
TTextureRef pTexture;
|
||||
if (mask.length() != 0 && image.length() != 0) {
|
||||
pTexture = TTexture::GetMerged(image, mask, flags);
|
||||
}
|
||||
else if (image.length() != 0) {
|
||||
pTexture = TTexture::Get(image, flags);
|
||||
}
|
||||
SetTexture(pTexture, scale);
|
||||
|
||||
double w = style.GetNumber("w", -1.0);
|
||||
double h = style.GetNumber("h", -1.0);
|
||||
if (0 < SseDoubleToInt32(w) && 0 < SseDoubleToInt32(h)) {
|
||||
SetWindowSize(SseDoubleToInt32(w), SseDoubleToInt32(h));
|
||||
}
|
||||
TRect rect(0, 0, 0, 0);
|
||||
GetWindowRect(&rect);
|
||||
width = rect.x2 - rect.x1;
|
||||
height = rect.y2 - rect.y1;
|
||||
}
|
||||
|
||||
// game @0x0003c25c
|
||||
void TBitmapTint::Draw()
|
||||
{
|
||||
TTextureRef pTexture = GetTexture();
|
||||
if (pTexture) {
|
||||
if (TRenderer::GetInstance()->Begin2d()) {
|
||||
TReal scale = GetScale();
|
||||
TVec2 position(scale * dx, scale * dy);
|
||||
if (dx == -9999.0f) {
|
||||
position.x = (float)((double)(uint32_t)(GetParentRelativeRect().x2 - GetParentRelativeRect().x1) * 0.5);
|
||||
}
|
||||
if (dy == -9999.0f) {
|
||||
position.y = (float)((double)(uint32_t)(GetParentRelativeRect().y2 - GetParentRelativeRect().y1) * 0.5);
|
||||
}
|
||||
TDrawSpec spec(position, 1.0f, scale, 0);
|
||||
spec.mTint = tint;
|
||||
if (hflip) {
|
||||
spec.mFlags = spec.mFlags | 1;
|
||||
}
|
||||
pTexture->DrawSprite(spec);
|
||||
TRenderer::GetInstance()->End2d();
|
||||
}
|
||||
}
|
||||
}
|
||||
277
port/game/BonusGame.cpp
Normal file
277
port/game/BonusGame.cpp
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
// Port of the game's BonusGame.cpp (Chocolatier 3, Big Splash Games): TBonusGame, the crate-picking bonus mini
|
||||
// game (21 crates hiding cash prizes or a devil) with a sparkle particle effect over the opened prize.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// BonusGame.h (port/game/BonusGame.h, unchanged). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): TBonusGame : TWindow (0x30) prize[21] 0x30..0x420 (TCrate, 0x30 each: state 0x0, value 0x4,
|
||||
// x 0x8, y 0xc, r 0x10 (TRect), time 0x20, pText 0x24, pGraphic 0x28/0x2c), selectX 0x420, selectY 0x424,
|
||||
// prizeParticles 0x428, prizeParticleColorStart 0x4e0 (color at 0x4e8), prizeParticleColorEnd 0x4f8 (color at
|
||||
// 0x500), pCrate 0x510, pCrateOpen 0x518, pCrateFront 0x520, sizeof 0x528. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The Lua functions PrepareGame and SelectPrize are registered by the constructor and set to nil by the
|
||||
// destructor. The Lua crate index of SelectPrize is 1-based (prize[index - 1]); StartSparkle gets the same index.
|
||||
// - PrepareGame: value of crate i = bet * _PrizeFactor[i] + 0.5 (unsigned conversion), rounded down to a multiple
|
||||
// of 100, but at least 100 when the factor is positive; then every crate swaps its value with a random crate
|
||||
// (rand() % 21). Returns the sum of the values. _PrizeFactor is the 21 doubles at game @0x00192fa0 (0.435 x3, 0.4,
|
||||
// 0.35 x4, 0.25 x4, 0.24 x3, 0.15, 0.1, 0.05, 0, 0, 0), read from the binary.
|
||||
// - Select opens a waiting crate: sound "crate_click"; a zero value shows "image/whammy_devil" (state BLANK when it
|
||||
// is the final pick, sound "crate_no_money"), otherwise the value is rendered with Dollars() into a TTextGraphic
|
||||
// (font "fonts/fertigo.mvec", flags 5; final pick: color (0.8, 0.2, 0, 1), line height 14; else StartSparkle,
|
||||
// sound "crate_with_money", color (0, 0, 0, 1), line height 16). Returns the crate value.
|
||||
// - StartSparkle sets selectX / selectY to the crate center, the start color (0.0823529, 0.560784, 0.105882, 1),
|
||||
// the end color (same rgb, alpha 0.2) and the script global gSparkleTime = 2.
|
||||
// - TCrate::Draw: waiting crates draw the closed crate at alpha 1 / scale 0.4; opened ones fade (alpha 1 - t / 800)
|
||||
// and grow (scale (1 + t / 1600) * 0.4) with the open crate and its front mask, the devil pulsing or the prize
|
||||
// text growing (peak _GROW_TIME = 400, set by the static initializer game @0x001ababa, then settling at 1.5).
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFTYPEDEF_DC: TBonusGameDynamicCreate game @0x0003de50, ClassId game @0x0003cbfc, GetTypeName game @0x0003cc06,
|
||||
// IsKindOf game @0x001758f4. ~TBonusGame: D1 game @0x0003d594, D0 game @0x0003d3b2 (also deletes; unregisters the
|
||||
// Lua functions, releases the three textures, destroys the particle colors, the particle system and the crates).
|
||||
// TCrate (header inline): TCrate() game @0x00175974 (zeroes value, x, y, r, time, pText; state is left unset),
|
||||
// ~TCrate game @0x00175920 (destroys pText, releases pGraphic). __GLOBAL__I game @0x001abad6.
|
||||
// Lua registration instances: lua_pushdirectclosure<TBonusGame, void (TBonusGame::*)(unsigned, unsigned)> game
|
||||
// @0x001755ec, <(unsigned, unsigned, bool)> game @0x00175638; LPCD::ReturnSpecialization<unsigned>::Call<
|
||||
// TBonusGame, unsigned> game @0x00175684, <TBonusGame, unsigned, bool> game @0x001757a8;
|
||||
// DirectCallMemberDispatcherHelper<(unsigned)> game @0x00175764, <(unsigned, bool)> game @0x001758b0.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "BonusGame.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGSound.h"
|
||||
#include "pf/luaparticlesystem.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/textgraphic.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
PFTYPEIMPL_DC(TBonusGame);
|
||||
|
||||
// game @0x0021ee40 (set to 400 by the static initializer game @0x001ababa)
|
||||
static TReal _GROW_TIME = 400.0f;
|
||||
|
||||
// game @0x00192fa0 (21 doubles)
|
||||
static const double _PrizeFactor[PRIZE_COUNT] = {
|
||||
0.435, 0.435, 0.435, 0.4, 0.35, 0.35, 0.35, 0.35, 0.25, 0.25, 0.25, 0.25, 0.24, 0.24, 0.24, 0.15, 0.1, 0.05, 0.0, 0.0, 0.0
|
||||
};
|
||||
|
||||
// game @0x0003cc10
|
||||
void TBonusGame::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
for (uint32_t i = 0; i != PRIZE_COUNT; i++) {
|
||||
prize[i].state = TCrate::WAITING;
|
||||
str name = str::getFormatted("select_%lu", (unsigned long)(i + 1));
|
||||
TWindow* pWindow = GetChildWindow(name, -1);
|
||||
if (pWindow != 0) {
|
||||
pWindow->GetWindowRect(&prize[i].r);
|
||||
ScreenToClient(&prize[i].r);
|
||||
prize[i].r.x1 = prize[i].r.x1 - 20;
|
||||
prize[i].r.x2 = prize[i].r.x2 + 20;
|
||||
prize[i].x = (float)((double)(prize[i].r.x1 + prize[i].r.x2) * 0.5);
|
||||
prize[i].y = (float)((double)(prize[i].r.y1 + prize[i].r.y2) * 0.5);
|
||||
}
|
||||
}
|
||||
StartWindowAnimation(50, true, true, false);
|
||||
}
|
||||
|
||||
// game @0x0003cd7a
|
||||
bool TBonusGame::OnTaskAnimate(void)
|
||||
{
|
||||
for (uint32_t i = 0; i != PRIZE_COUNT; i++) {
|
||||
if (prize[i].state == TCrate::OPENING) {
|
||||
prize[i].time = prize[i].time + 50;
|
||||
}
|
||||
}
|
||||
prizeParticles.Update(100);
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0003cdc6
|
||||
uint32_t TBonusGame::PrepareGame(uint32_t betAmount)
|
||||
{
|
||||
uint32_t total = 0;
|
||||
for (uint32_t i = 0; i != PRIZE_COUNT; i++) {
|
||||
double scaled = (double)betAmount * _PrizeFactor[i] + 0.5;
|
||||
double clamped = scaled;
|
||||
if (4294967295.0 <= clamped) {
|
||||
clamped = 4294967295.0;
|
||||
}
|
||||
if (clamped <= 0.0) {
|
||||
clamped = 0.0;
|
||||
}
|
||||
uint32_t amount = (uint32_t)clamped;
|
||||
uint32_t value = (amount / 100) * 100;
|
||||
if (value < 100 && 0.0 < _PrizeFactor[i]) {
|
||||
value = 100;
|
||||
}
|
||||
prize[i].value = value;
|
||||
total = total + value;
|
||||
}
|
||||
for (uint32_t i = 0; i != PRIZE_COUNT; i++) {
|
||||
int32_t other = rand() % PRIZE_COUNT;
|
||||
uint32_t saved = prize[i].value;
|
||||
prize[i].value = prize[other].value;
|
||||
prize[other].value = saved;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
// game @0x0003cf0c
|
||||
void TBonusGame::StartSparkle(uint32_t index)
|
||||
{
|
||||
TCrate& crate = prize[index - 1];
|
||||
selectX = (int32_t)crate.x;
|
||||
selectY = (int32_t)crate.y;
|
||||
prizeParticleColorStart.color.a = 1.0f;
|
||||
prizeParticleColorStart.color.b = 0.10588235408067703f;
|
||||
prizeParticleColorStart.color.g = 0.5607843399047852f;
|
||||
prizeParticleColorStart.color.r = 0.08235294371843338f;
|
||||
prizeParticleColorEnd.color.r = prizeParticleColorStart.color.r;
|
||||
prizeParticleColorEnd.color.g = prizeParticleColorStart.color.g;
|
||||
prizeParticleColorEnd.color.b = prizeParticleColorStart.color.b;
|
||||
prizeParticleColorEnd.color.a = 0.2f;
|
||||
prizeParticles.GetScript()->SetGlobalNumber("gSparkleTime", 2.0);
|
||||
}
|
||||
|
||||
// game @0x0003cfea
|
||||
uint32_t TBonusGame::Select(uint32_t index, bool final)
|
||||
{
|
||||
TCrate& crate = prize[index - 1];
|
||||
if (crate.state == TCrate::WAITING) {
|
||||
BSGSoundEvent("crate_click");
|
||||
crate.state = TCrate::OPENING;
|
||||
if (crate.value == 0) {
|
||||
crate.pGraphic = TTexture::Get("image/whammy_devil", 0);
|
||||
if (final) {
|
||||
crate.state = TCrate::BLANK;
|
||||
}
|
||||
BSGSoundEvent("crate_no_money");
|
||||
}
|
||||
else {
|
||||
TColor color(0, 0, 0, 1.0f);
|
||||
uint32_t lineHeight;
|
||||
if (!final) {
|
||||
StartSparkle(index);
|
||||
BSGSoundEvent("crate_with_money");
|
||||
lineHeight = 0x10;
|
||||
}
|
||||
else {
|
||||
color.g = 0.2f;
|
||||
color.r = 0.800000011920929f;
|
||||
lineHeight = 0xe;
|
||||
}
|
||||
crate.pText = TTextGraphic::Create(Dollars((double)crate.value), crate.r.x2 - crate.r.x1,
|
||||
crate.r.y2 - crate.r.y1, 5, "fonts/fertigo.mvec", lineHeight, color);
|
||||
}
|
||||
}
|
||||
return crate.value;
|
||||
}
|
||||
|
||||
// game @0x0003d222
|
||||
void TBonusGame::Init(TWindowStyle& style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
pCrate = TTexture::Get("image/box_closed", 0);
|
||||
pCrateOpen = TTexture::Get("image/box_open", 0);
|
||||
pCrateFront = TTexture::Get("image/box_open_mask", 0);
|
||||
}
|
||||
|
||||
// game @0x0003d594 (D1), game @0x0003d3b2 (D0)
|
||||
TBonusGame::~TBonusGame()
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptUnregisterFunction(script, "PrepareGame");
|
||||
ScriptUnregisterFunction(script, "SelectPrize");
|
||||
}
|
||||
|
||||
// game @0x0003d770
|
||||
void TBonusGame::TCrate::Draw(TBonusGame& game)
|
||||
{
|
||||
TTextureRef pTexture;
|
||||
TReal alpha;
|
||||
TReal scale;
|
||||
if (state == WAITING) {
|
||||
pTexture = game.pCrate;
|
||||
scale = 0.4f;
|
||||
alpha = 1.0f;
|
||||
}
|
||||
else {
|
||||
uint32_t t = time;
|
||||
alpha = 1.0f - (TReal)t / 800.0f;
|
||||
scale = (1.0f + (TReal)t / 1600.0f) * 0.4f;
|
||||
if (0.0f < alpha && state != BLANK) {
|
||||
game.pCrateOpen->DrawSprite(x, y, alpha, scale, 0, 0);
|
||||
t = time;
|
||||
}
|
||||
if (value == 0) {
|
||||
uint32_t phase = t % 1000;
|
||||
if (500 < phase) {
|
||||
phase = 1000 - phase;
|
||||
}
|
||||
TReal devilScale = (float)((double)phase / 1000.0 + 0.5);
|
||||
if (state == BLANK) {
|
||||
devilScale = 0.25f;
|
||||
}
|
||||
if (pGraphic) {
|
||||
pGraphic->DrawSprite(x, y, 1.0f, devilScale, 0, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
TReal elapsed = (TReal)t;
|
||||
TReal textScale = 1.0f;
|
||||
if (elapsed < 800.0f) {
|
||||
if (elapsed <= _GROW_TIME) {
|
||||
textScale = elapsed / (_GROW_TIME + _GROW_TIME) + 1.0f;
|
||||
}
|
||||
else {
|
||||
textScale = (elapsed - _GROW_TIME) / (_GROW_TIME * -2.0f) + 1.5f;
|
||||
}
|
||||
}
|
||||
if (pText != 0) {
|
||||
pText->Draw(r, textScale, 0, 1.0f, TTextureRef());
|
||||
}
|
||||
}
|
||||
if (alpha <= 0.0f) {
|
||||
return;
|
||||
}
|
||||
if (state == BLANK) {
|
||||
return;
|
||||
}
|
||||
pTexture = game.pCrateFront;
|
||||
}
|
||||
pTexture->DrawSprite(x, y, alpha, scale, 0, 0);
|
||||
}
|
||||
|
||||
// game @0x0003da5a
|
||||
void TBonusGame::Draw(void)
|
||||
{
|
||||
TWindow::Draw();
|
||||
TBegin2d begin2d;
|
||||
for (uint32_t i = 0; i != PRIZE_COUNT; i++) {
|
||||
prize[i].Draw(*this);
|
||||
}
|
||||
prizeParticles.Draw(TVec3((float)selectX, (float)selectY, 0));
|
||||
begin2d.Done();
|
||||
}
|
||||
|
||||
// game @0x0003db00
|
||||
TBonusGame::TBonusGame(void) :
|
||||
selectX(0),
|
||||
selectY(0),
|
||||
prizeParticles(0)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "PrepareGame", this, TBonusGame::PrepareGame);
|
||||
ScriptRegisterMemberDirect(script, "SelectPrize", this, TBonusGame::Select);
|
||||
prizeParticles.RegisterDataSource("gSparkleColorStart", &prizeParticleColorStart);
|
||||
prizeParticles.RegisterDataSource("gSparkleColorEnd", &prizeParticleColorEnd);
|
||||
prizeParticles.GetScript()->SetGlobalString("gSparkleTexture", "money");
|
||||
prizeParticles.Init("glitz/sparkle.lua");
|
||||
}
|
||||
196
port/game/Character.cpp
Normal file
196
port/game/Character.cpp
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
// Port of the game's Character.cpp (Chocolatier 3, Big Splash Games): Character, a window that shows a character
|
||||
// portrait (an animated texture whose frames are moods) and cross-fades between the mood frames.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// Character.h (port/game/Character.h, unchanged). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): Character : TBSGWindow (0x50) name 0x50, pImage 0x54/0x58 (shared_ptr), alpha 0x5c,
|
||||
// scale 0x60, happinessFrame 0x64, targetHappinessFrame 0x68, timer 0x6c. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The constructor sets only alpha and scale (1.0f each) and registers the window in visibleCharacters; the frame
|
||||
// fields and the timer are left as the allocator leaves them.
|
||||
// - Strings from the game's __cstring: "" (@0x001581bc), "name", "alpha", "scale", "happiness", ".xml",
|
||||
// "characters/", ".png", "characters/temp_char". Defaults: alpha 1, scale 1, happiness 50.
|
||||
// - PostChildrenInit loads "characters/<name>.xml" as an animated texture; failing that "characters/<name>.png" and
|
||||
// then "characters/temp_char" as a plain texture. When scale != 1 the window size is the texture size times
|
||||
// the scale plus 0.5, converted to unsigned (the game's saturating double to uint conversion), and the window is
|
||||
// never made smaller than its current rect.
|
||||
// - SetMood: three frames map happiness to frame 1 (0..33), 0 (33..66), 2 (66..); otherwise frame
|
||||
// min(frames - 1, (int)((frames - 1) * happiness / 100) + 1), a window animation (50 ms) starts when it changes.
|
||||
// - Draw cross-fades the current frame (full alpha) with the target frame (alpha * timer / 200).
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFTYPEDEF_DC: CharacterDynamicCreate game @0x000073de, ClassId game @0x000071b8, GetTypeName game @0x000071c2,
|
||||
// IsKindOf game @0x00165160. TWindow::GetCast<Character> game @0x001745c0 (template instance).
|
||||
// ~Character (removes this from visibleCharacters, releases pImage, destroys name, ~TBSGWindow): D1 game
|
||||
// @0x000072c8, D0 game @0x00007238 (also deletes). Constructor C1 game @0x00007350.
|
||||
// visibleCharacters initializer: __GLOBAL__I__ZN9Character7ClassIdEv game @0x001ab92a. The std::list<Character*>
|
||||
// instantiations (game @0x00164fc0..0x00165128) are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "Character.h"
|
||||
#include "sseconv.h"
|
||||
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
PFTYPEIMPL_DC(Character);
|
||||
|
||||
list<Character*> Character::visibleCharacters;
|
||||
|
||||
// game @0x000071cc
|
||||
void Character::SetAlpha(TReal alpha_)
|
||||
{
|
||||
alpha = alpha_;
|
||||
}
|
||||
|
||||
// game @0x000071da
|
||||
bool Character::OnTaskAnimate(void)
|
||||
{
|
||||
if (timer < 200) {
|
||||
timer += 50;
|
||||
if (timer >= 200) {
|
||||
timer = 200;
|
||||
happinessFrame = targetHappinessFrame;
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
return timer < 200;
|
||||
}
|
||||
|
||||
// game @0x00007350
|
||||
Character::Character(void) :
|
||||
alpha(1.0f),
|
||||
scale(1.0f)
|
||||
{
|
||||
visibleCharacters.push_back(this);
|
||||
}
|
||||
|
||||
// game @0x000072c8 (D1), game @0x00007238 (D0)
|
||||
Character::~Character()
|
||||
{
|
||||
visibleCharacters.remove(this);
|
||||
}
|
||||
|
||||
// game @0x0000741c
|
||||
void Character::Draw(void)
|
||||
{
|
||||
if (pImage) {
|
||||
TBegin2d begin2d;
|
||||
TAnimatedTextureRef pAnimated = pImage->GetCast<TAnimatedTexture>();
|
||||
if (!pAnimated) {
|
||||
TReal x = (TReal)pImage->GetWidth() * scale * 0.5f;
|
||||
TReal y = (TReal)pImage->GetHeight() * scale * 0.5f;
|
||||
pImage->DrawSprite(x, y, alpha, scale, 0, 0);
|
||||
}
|
||||
else {
|
||||
pAnimated->SetCurrentFrame(0);
|
||||
TReal x = (TReal)pImage->GetWidth() * scale * 0.5f;
|
||||
TReal y = (TReal)pImage->GetHeight() * scale * 0.5f;
|
||||
pAnimated->DrawSprite(x, y, alpha, scale, 0, 0);
|
||||
if (pAnimated->GetNumFrames() > 1) {
|
||||
pAnimated->SetCurrentFrame(happinessFrame);
|
||||
pAnimated->DrawSprite(x, y, alpha, scale, 0, 0);
|
||||
if (happinessFrame != targetHappinessFrame) {
|
||||
pAnimated->SetCurrentFrame(targetHappinessFrame);
|
||||
pAnimated->DrawSprite(x, y, ((TReal)timer * alpha) / 200.0f, scale, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
begin2d.Done();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000076fa
|
||||
void Character::SetMood(TReal newHappiness)
|
||||
{
|
||||
TAnimatedTextureRef pAnimated;
|
||||
if (pImage) {
|
||||
pAnimated = pImage->GetCast<TAnimatedTexture>();
|
||||
}
|
||||
if (pAnimated) {
|
||||
int32_t frames = pAnimated->GetNumFrames();
|
||||
if (frames == 3) {
|
||||
int32_t frame = (int32_t)((double)(newHappiness * 3.0f) / 100.0);
|
||||
targetHappinessFrame = frame;
|
||||
if (frame == 0) {
|
||||
targetHappinessFrame = 1;
|
||||
}
|
||||
else {
|
||||
targetHappinessFrame = (frame != 1) * 2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (frames < 2) {
|
||||
return;
|
||||
}
|
||||
frames = frames - 1;
|
||||
int32_t frame = (int32_t)((double)((TReal)frames * newHappiness) / 100.0) + 1;
|
||||
if (frame <= frames) {
|
||||
frames = frame;
|
||||
}
|
||||
targetHappinessFrame = frames;
|
||||
}
|
||||
if (happinessFrame != targetHappinessFrame) {
|
||||
timer = 0;
|
||||
StartWindowAnimation(50, true, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00007866
|
||||
void Character::SetCharacterMood(str name, TReal happiness)
|
||||
{
|
||||
for (list<Character*>::iterator it = visibleCharacters.begin(); it != visibleCharacters.end(); ++it) {
|
||||
if ((*it)->name.compare(name) == 0) {
|
||||
(*it)->SetMood(happiness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000078ba
|
||||
void Character::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TBSGWindow::PostChildrenInit(style);
|
||||
name = style.GetString("name", "");
|
||||
alpha = (TReal)style.GetNumber("alpha", 1.0);
|
||||
scale = (TReal)style.GetNumber("scale", 1.0);
|
||||
TReal happiness = (TReal)style.GetNumber("happiness", 50.0);
|
||||
|
||||
str xmlName = str("characters/") + name + str(".xml");
|
||||
TAnimatedTextureRef pAnimated = TAnimatedTexture::Get(xmlName, "", "");
|
||||
if (!pAnimated) {
|
||||
str pngName = str("characters/") + name + str(".png");
|
||||
pImage = TTexture::Get(pngName, 0);
|
||||
if (!pImage) {
|
||||
pImage = TTexture::Get("characters/temp_char", 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pAnimated->SetCurrentFrame(0);
|
||||
pImage = pAnimated;
|
||||
}
|
||||
|
||||
if (pImage) {
|
||||
uint32_t w = pImage->GetWidth();
|
||||
uint32_t h = pImage->GetHeight();
|
||||
if (scale != 1.0f) {
|
||||
w = SseDoubleToUInt32((double)((TReal)w * scale) + 0.5);
|
||||
h = SseDoubleToUInt32((double)(scale * (TReal)h) + 0.5);
|
||||
}
|
||||
uint32_t curW = (uint32_t)(GetParentRelativeRect().x2 - GetParentRelativeRect().x1);
|
||||
if (w < curW) {
|
||||
w = curW;
|
||||
}
|
||||
uint32_t curH = (uint32_t)(GetParentRelativeRect().y2 - GetParentRelativeRect().y1);
|
||||
if (h < curH) {
|
||||
h = curH;
|
||||
}
|
||||
SetWindowSize(w, h);
|
||||
}
|
||||
SetMood(happiness);
|
||||
happinessFrame = targetHappinessFrame;
|
||||
}
|
||||
760
port/game/ChocolateFactory.cpp
Normal file
760
port/game/ChocolateFactory.cpp
Normal file
|
|
@ -0,0 +1,760 @@
|
|||
// Port of the game's ChocolateFactory.cpp (Chocolatier 3, Big Splash Games): ChocolateFactory, the chocolate-making
|
||||
// minigame window. It reads its tuning from the window style (times, conveyor / tray / product / gun / ring /
|
||||
// recycler paths and speeds, the recipe), builds the sprite scene (conveyor queue, trays, the machine with its two
|
||||
// animated arms, the product box, the gun, the timer face with its hand), and runs the game from the window's
|
||||
// animation task: countdown, playing, ending and game-over states, the clock, the machine animation and the ticks
|
||||
// of the six scaling tasks. Messages from the tasks (missed ingredient, products, score, speed-up, flying ring) are
|
||||
// handled in OnMessage.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// ChocolateFactory.h (port/game/ChocolateFactory.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TWindow 0x0..0x30, TBSGWindow 0x30..0x50 (pFrame 0x30, fill 0x38, color 0x3c, swallowMouse
|
||||
// 0x4c); productName 0x50, productCode 0x54, recipe 0x58, state 0x64, pBaseSprite 0x68, pSoundHandler 0x70,
|
||||
// pConveyor 0x74, pConveyorTask 0x7c, pGunTask 0x80, pGun 0x84, machineTime 0x8c, pTrayTemplate 0x90, pUpperArm
|
||||
// 0x98, pLowerArm 0xa0, speedUpFactor 0xa8, maxSpeed 0xac, pTrayTask 0xb0, pProductTask 0xb4, pRecyclerTask 0xb8,
|
||||
// pRingTask 0xbc, missCount 0xc0, missPosition 0xc4, missed 0xd0, gamePaused 0xdc, warnOnMiss 0xdd, countdownTime
|
||||
// 0xe0, gameTime 0xe4, warnTime 0xe8, clock 0xec, score 0xf0, bonusScore 0xf4, pTime 0xf8, pCountdown 0xfc, pScore
|
||||
// 0x100, pTimer 0x104, pTimerHand 0x10c, pScoreDisplay 0x114; sizeof 0x11c (ChocolateFactoryDynamicCreate allocates
|
||||
// 0x11c bytes). The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Message ids: 0x3e9 kAppDeactivate, 0x3eb kMissedIngredientEvent, 0x3ec kManufactureProductEvent, 0x3ed
|
||||
// kProduceProductEvent, 0x3ee kCountBonusProductEvent, 0x3ef kCountProductEvent, 0x3f0 kFillTrayEvent, 0x3f1
|
||||
// kColorMatchEvent (chocothree.h, TMessage::kUserMessageBase = 1000). kManufactureProductEvent falls through to
|
||||
// kProduceProductEvent, kCountBonusProductEvent to kCountProductEvent.
|
||||
// - Virtual calls on the task objects: slot 0 is Reset(float) (called with 1.0f), slot 1 Restart(uint32_t) (called
|
||||
// with 15); TScalingTask::GetScale is the float at +0xc. The AnyFlying() / AnyProducts() / AnyFull() tests are
|
||||
// the std::list / std::set size() == 0 checks the game inlines.
|
||||
// - GAME_COUNTDOWN is 1, GAME_PLAYING 2, GAME_ENDING 3, GAME_ABORTED 4, GAME_OVER 5 (header order).
|
||||
// - Window style defaults (double constants pushed by the game): countdowntime 3000, gametime 60000, warntime 8000,
|
||||
// conveyortime 1200, conveyorcount 5, colorcount 1, producttime 3000, speedup 1.1, maxspeed 8, traytime 30000,
|
||||
// trayend 0, traycount 5, gunspeed 250, ringspeed 500, recyclertime 20000. The unsigned values are converted with
|
||||
// the game's inline clamp (see ClampToUInt32).
|
||||
// - The game's unsigned -> double conversions (machineTime, window width / height) are the usual SSE2 magic-number
|
||||
// sequences (constants @0x001928a0..@0x001928b8 and @0x001928f0..@0x00192908); doubles used: 0.5 (@0x001ab488),
|
||||
// pi (@0x001ab4a8), 0.95 (@0x001ab4b0), 0.05 (@0x001ab4b8), 400.0 (@0x001ab4c0); floats 1.0 (@0x001ab6e4), 0.0
|
||||
// (@0x001ab6e8), 0.5 (@0x001ab6ec); the sign mask @0x00192890 is the float negation.
|
||||
// - OnKeyDown reads the cheat-mode config value with TPlatform::GetConfig but never uses it; the dev menu is opened
|
||||
// whenever bit 0 of the key flags is set (the game's code, kept as is).
|
||||
// - TWindow offset +4 (read as the receiver of the "go" / "pause" / "information" child lookups) is mParent.
|
||||
// - LoadAppearance and BuildItemAppearance (game @0x0001fcd2 / @0x0001fff4) are declared in the original
|
||||
// CustomItems.h and live in their own object file; they are declared here.
|
||||
//
|
||||
// Strings from the game's __cstring: "ChocolateFactory", "cursor/cursor", "cursor/gun_aimer",
|
||||
// "ChocolateFactoryTime", "go", "pause", "information", "gPauseText", "ui/game_pause.lua", "game_paused",
|
||||
// "DoModal('dev/dev_menu.lua')", "recipe", "productName", "productCode", "warnOnMiss", "countdowntime", "gametime",
|
||||
// "warntime", "conveyortime", "conveyorcount", "colorcount", "conveyorpath", "rainbow", "producttime",
|
||||
// "productpath", "appearance", "speedup", "maxspeed", "traytime", "trayend", "traycount", "traypath", "machine",
|
||||
// "", "image/machine_stack_finger_upper", "image/machine_stack_finger_lower", "image/tray%d", "items/",
|
||||
// "image/box_open", "image/box_open_mask", "gunspeed", "image/gun_base", "image/gun.xml", "ringspeed", "missed",
|
||||
// "recycler", "recyclerpath", "recyclertime", "image/timer_face", "image/timer_hand", "game_over",
|
||||
// "chocolate_making_game", "chocolate_making_game_outro", "chocolate_making_game_intro", "ui/chocolate_gameover.lua",
|
||||
// "whistle", "clock_tick", "start_bell", "0:00", "%lu:%02lu", "%d", "%lu", "0", "snatch",
|
||||
// "ingredient_failure_factory shutdown", "ingredient_failure_%lu", "choco_first_missed", "RecycleCount", "restart",
|
||||
// "time", "countdown", "score".
|
||||
//
|
||||
// Compiler-generated or header-inline code emitted out of line:
|
||||
// - PFTYPEDEF_DC: IsKindOf game @0x001666b4 (compares the id against &ChocolateFactoryDynamicCreate, else calls
|
||||
// TBSGWindow::IsKindOf), ChocolateFactoryDynamicCreate game @0x000093d8 (new ChocolateFactory, sizeof 0x11c),
|
||||
// ClassId game @0x00007fec, GetTypeName game @0x00007ff6; the ChocolateFactory vtable is at game @0x0021b828.
|
||||
// - ChocolateFactory::GetScore game @0x0016549c (inline in ChocolateFactory.h).
|
||||
// - lua_pushdirectclosure<ChocolateFactory, F> for F = void (str) game @0x001654d8, void () game @0x00165524,
|
||||
// uint32_t () game @0x00165570; LPCD::DirectCallMemberDispatcherHelper<ChocolateFactory, F>::
|
||||
// DirectCallMemberDispatcher for F = void (str) game @0x00165720 (ReturnSpecialization<void>::Call<ChocolateFactory,
|
||||
// str> game @0x001656a8), uint32_t () game @0x00166628 (ReturnSpecialization<unsigned int>::Call<ChocolateFactory>
|
||||
// game @0x00165764), void () game @0x0016666c (pf/luapluscd.h templates; the dispatchers Init's constructor
|
||||
// registers as "StartGame", "PauseGame", "ResumeGame" and "GetScore").
|
||||
// - ChocolateFactory has no out-of-line members beyond those above; the std::vector / std::set / boost::shared_ptr
|
||||
// instantiations are library code. The game also lists undecodable exception-handling clones (.eh) of the
|
||||
// constructor and destructors; they are not source functions.
|
||||
//
|
||||
// Static data: ChocolateFactory::pInstance (__ZN16ChocolateFactory9pInstanceE, NULL).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "ChocolateFactory.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGSound.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/gamestate.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/modalwindow.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/text.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
// CustomItems.h (original, no port header yet): game @0x0001fcd2 / @0x0001fff4.
|
||||
void LoadAppearance(TLuaTable& productTable, vector<str>& appearance, vector<TColor>& tints);
|
||||
void BuildItemAppearance(TSpriteRef pBase, vector<str> const& appearance, vector<TColor> const& tints, TReal scale);
|
||||
|
||||
// The game's inline double -> uint32_t conversion (see the notes above).
|
||||
static uint32_t ClampToUInt32(double value)
|
||||
{
|
||||
double clamped = value;
|
||||
if (4294967295.0 <= value) {
|
||||
clamped = 4294967295.0;
|
||||
}
|
||||
if (clamped <= 0.0) {
|
||||
clamped = 0.0;
|
||||
}
|
||||
double bias = (2147483648.0 <= value) ? 2147483648.0 : 0.0;
|
||||
return (uint32_t)(int32_t)(clamped - bias) ^ ((2147483648.0 <= value) ? 0x80000000u : 0u);
|
||||
}
|
||||
|
||||
ChocolateFactory* ChocolateFactory::pInstance = NULL;
|
||||
|
||||
// game @0x00007fec (ClassId), @0x00007ff6 (GetTypeName), @0x000093d8 (ChocolateFactoryDynamicCreate)
|
||||
PFTYPEIMPL_DC(ChocolateFactory);
|
||||
|
||||
// game @0x00008ea8
|
||||
ChocolateFactory::ChocolateFactory(void)
|
||||
{
|
||||
pSoundHandler = NULL;
|
||||
pConveyorTask = NULL;
|
||||
pGunTask = NULL;
|
||||
machineTime = 0;
|
||||
pTrayTask = NULL;
|
||||
pProductTask = NULL;
|
||||
pRecyclerTask = NULL;
|
||||
pRingTask = NULL;
|
||||
gamePaused = false;
|
||||
warnOnMiss = false;
|
||||
pTime = NULL;
|
||||
pCountdown = NULL;
|
||||
pScore = NULL;
|
||||
pInstance = this;
|
||||
fill = false;
|
||||
pBaseSprite = TSprite::Create(0, TTextureRef());
|
||||
pSoundHandler = new TSoundHandler();
|
||||
state = GAME_INIT;
|
||||
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "StartGame", this, ChocolateFactory::StartGame);
|
||||
ScriptRegisterMemberDirect(script, "PauseGame", this, ChocolateFactory::PauseGame);
|
||||
ScriptRegisterMemberDirect(script, "ResumeGame", this, ChocolateFactory::ResumeGame);
|
||||
ScriptRegisterMemberDirect(script, "GetScore", this, ChocolateFactory::GetScore);
|
||||
}
|
||||
|
||||
// game @0x00008808 (D0, deleting), game @0x00008b5c (D1, complete)
|
||||
ChocolateFactory::~ChocolateFactory(void)
|
||||
{
|
||||
pInstance = NULL;
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(false);
|
||||
if (TWindowManager::GetInstance()->OrphanMessageListener(pSoundHandler)) {
|
||||
delete pSoundHandler;
|
||||
}
|
||||
delete pTrayTask;
|
||||
delete pConveyorTask;
|
||||
delete pGunTask;
|
||||
delete pRingTask;
|
||||
delete pProductTask;
|
||||
delete pRecyclerTask;
|
||||
}
|
||||
|
||||
// game @0x000087ae
|
||||
void ChocolateFactory::ToggleForeground(void)
|
||||
{
|
||||
if (pInstance != NULL) {
|
||||
pInstance->PauseGame("game_paused");
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000081a4
|
||||
void ChocolateFactory::ParseRecipe(TWindowStyle& style)
|
||||
{
|
||||
recipe.clear();
|
||||
productName = style.GetString("productName", "");
|
||||
productCode = style.GetString("productCode", "");
|
||||
TLuaTable* pRecipe = style.GetTable("recipe");
|
||||
if (pRecipe != NULL) {
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaObjectWrapper* pItem;
|
||||
while ((pItem = pRecipe->GetNext(&key)) != NULL) {
|
||||
recipe.push_back(pItem->AsString());
|
||||
delete pItem;
|
||||
}
|
||||
delete pRecipe;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00009414
|
||||
void ChocolateFactory::Init(TWindowStyle& style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(true);
|
||||
RandSeed(TPlatform::GetInstance()->Timer());
|
||||
FindParentModal()->SetDefaultFocus(this);
|
||||
|
||||
warnOnMiss = style.GetBool("warnOnMiss", false);
|
||||
countdownTime = ClampToUInt32(style.GetNumber("countdowntime", 3000));
|
||||
gameTime = ClampToUInt32(style.GetNumber("gametime", 60000));
|
||||
warnTime = ClampToUInt32(style.GetNumber("warntime", 8000));
|
||||
|
||||
ParseRecipe(style);
|
||||
|
||||
// Ingredient conveyor
|
||||
TCurveRef pConveyorCurve;
|
||||
float conveyorTime = (float)style.GetNumber("conveyortime", 1200);
|
||||
uint32_t conveyorCount = ClampToUInt32(style.GetNumber("conveyorcount", 5));
|
||||
uint8_t colorCount = (uint8_t)(int)style.GetNumber("colorcount", 1);
|
||||
TLuaTable* pConveyorPath = style.GetTable("conveyorpath");
|
||||
if (pConveyorPath != NULL) {
|
||||
pConveyorCurve = TCurve::Create(*pConveyorPath);
|
||||
delete pConveyorPath;
|
||||
}
|
||||
pConveyor = ::shared_ptr<IngredientQueue>(new IngredientQueue(recipe, colorCount, pConveyorCurve, conveyorCount, pBaseSprite));
|
||||
pConveyorTask = new IngredientQueueTask(pConveyor, conveyorTime);
|
||||
pConveyor->EnableRainbow(style.GetBool("rainbow", false));
|
||||
|
||||
// Products
|
||||
TCurveRef pProductCurve;
|
||||
float productTime = (float)style.GetNumber("producttime", 3000);
|
||||
TLuaTable* pProductPath = style.GetTable("productpath");
|
||||
if (pProductPath != NULL) {
|
||||
pProductCurve = TCurve::Create(*pProductPath);
|
||||
delete pProductPath;
|
||||
}
|
||||
vector<str> appearance;
|
||||
vector<TColor> tints;
|
||||
TLuaTable* pAppearance = style.GetTable("appearance");
|
||||
if (pAppearance != NULL) {
|
||||
LoadAppearance(*pAppearance, appearance, tints);
|
||||
delete pAppearance;
|
||||
}
|
||||
pProductTask = new ChocolateProductQueueTask(pProductCurve, productTime, appearance, tints);
|
||||
|
||||
// Trays
|
||||
speedUpFactor = (float)style.GetNumber("speedup", 1.1);
|
||||
maxSpeed = (float)style.GetNumber("maxspeed", 8);
|
||||
float trayTime = (float)style.GetNumber("traytime", 30000);
|
||||
float trayEnd = (float)style.GetNumber("trayend", 0);
|
||||
pTrayTask = new ChocolateTrayTask(trayTime);
|
||||
uint32_t trayCount = ClampToUInt32(style.GetNumber("traycount", 5));
|
||||
TCurveRef pTrayCurve;
|
||||
TLuaTable* pTrayPath = style.GetTable("traypath");
|
||||
if (pTrayPath != NULL) {
|
||||
pTrayCurve = TCurve::Create(*pTrayPath);
|
||||
delete pTrayPath;
|
||||
}
|
||||
for (uint32_t i = 0; i < trayCount; i++) {
|
||||
float t = (float)i / (float)trayCount;
|
||||
ChocolateTrayRef pTray = ChocolateTray::Create(recipe, pTrayCurve, t, trayEnd);
|
||||
pBaseSprite->AddChild(pTray);
|
||||
pTray->BuildPistons(pBaseSprite);
|
||||
pTray->Update(0);
|
||||
pTrayTask->AddTray(pTray);
|
||||
}
|
||||
|
||||
// Machinery
|
||||
str machineName = style.GetString("machine", "");
|
||||
TSpriteRef pMachine = TSprite::Create(6, TTexture::Get(machineName, 0));
|
||||
pMachine->GetDrawSpec().mMatrix[2] = TVec3(695.0f, 301.0f, 1.0f);
|
||||
|
||||
pUpperArm = TSprite::Create(-1, TTexture::Get("image/machine_stack_finger_upper", 0));
|
||||
pUpperArm->GetDrawSpec().mCenter = TVec2(41.0f, 14.0f);
|
||||
pUpperArm->GetDrawSpec().mFlags |= TDrawSpec::kUseCenter;
|
||||
pUpperArm->GetDrawSpec().mMatrix[2] = TVec3(-74.0f, -51.0f, 1.0f);
|
||||
pMachine->AddChild(pUpperArm);
|
||||
|
||||
pLowerArm = TSprite::Create(-1, TTexture::Get("image/machine_stack_finger_lower", 0));
|
||||
pLowerArm->GetDrawSpec().mCenter = TVec2(41.0f, 119.0f);
|
||||
pLowerArm->GetDrawSpec().mFlags |= TDrawSpec::kUseCenter;
|
||||
pLowerArm->GetDrawSpec().mMatrix[2] = TVec3(-74.0f, 50.0f, 1.0f);
|
||||
pMachine->AddChild(pLowerArm);
|
||||
|
||||
pBaseSprite->AddChild(pMachine);
|
||||
|
||||
pTrayTemplate = TSprite::Create(0, TTexture::Get(str::getFormatted("image/tray%d", (int)recipe.size()), 0));
|
||||
pTrayTemplate->GetDrawSpec().mMatrix[2] = TVec3(0.0f, -2.0f, 1.0f);
|
||||
pMachine->AddChild(pTrayTemplate);
|
||||
for (uint32_t i = 0; i < recipe.size(); i++) {
|
||||
TSpriteRef pItem = TSprite::Create(0, TTexture::Get(str("items/") + recipe[i], 0));
|
||||
pItem->GetDrawSpec().mMatrix[2] = TVec3(ChocolateTray::GetSlotPosition(i, (uint32_t)recipe.size()), 1.0f);
|
||||
pTrayTemplate->AddChild(pItem);
|
||||
}
|
||||
|
||||
// Product box
|
||||
TSpriteRef pBox = TSprite::Create(1, TTexture::Get("image/box_open", 0));
|
||||
pBox->GetDrawSpec().mMatrix[2] = TVec3(pProductCurve->GetEndPoint(), 1.0f);
|
||||
pBaseSprite->AddChild(pBox);
|
||||
pBox = TSprite::Create(3, TTexture::Get("image/box_open_mask", 0));
|
||||
pBox->GetDrawSpec().mMatrix[2] = TVec3(pProductCurve->GetEndPoint(), 1.0f);
|
||||
pBaseSprite->AddChild(pBox);
|
||||
TSpriteRef pBoxContents = TSprite::Create(0, TTextureRef());
|
||||
BuildItemAppearance(pBoxContents, appearance, tints, 0.5f);
|
||||
pBoxContents->GetDrawSpec().mMatrix[2] = TVec3(0.0f, 9.0f, 1.0f);
|
||||
pBox->AddChild(pBoxContents);
|
||||
|
||||
// Ingredient gun
|
||||
TVec2 gunPosition;
|
||||
float gunSpeed = (float)style.GetNumber("gunspeed", 250);
|
||||
if (pConveyorCurve) {
|
||||
gunPosition = pConveyorCurve->GetEndPoint();
|
||||
}
|
||||
TSpriteRef pGunBase = TSprite::Create(0, TTexture::Get("image/gun_base", 0));
|
||||
pGunBase->GetDrawSpec().mMatrix[2] = TVec3(gunPosition, 1.0f);
|
||||
pBaseSprite->AddChild(pGunBase);
|
||||
|
||||
pGun = TAnimatedSprite::Create(10);
|
||||
pGun->SetTexture(TAnimatedTexture::Get("image/gun.xml", "", ""));
|
||||
pGun->SetCurrentFrame(0);
|
||||
pGun->GetDrawSpec().mMatrix[2] = TVec3(gunPosition, 1.0f);
|
||||
pBaseSprite->AddChild(pGun);
|
||||
pGunTask = new ChocolateGunTask(pGun, gunSpeed, pConveyor, pTrayTask);
|
||||
|
||||
// Bonuses
|
||||
float ringSpeed = (float)style.GetNumber("ringspeed", 500);
|
||||
pRingTask = new FlyingRingTask(ringSpeed);
|
||||
|
||||
// Missed ingredients
|
||||
TLuaTable* pMissed = style.GetTable("missed");
|
||||
if (pMissed != NULL) {
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaObjectWrapper* pEntry;
|
||||
while ((pEntry = pMissed->GetNext(&key)) != NULL) {
|
||||
if (pEntry->IsTable()) {
|
||||
missPosition.push_back(GetPoint(static_cast<TLuaTable*>(pEntry)));
|
||||
}
|
||||
delete pEntry;
|
||||
}
|
||||
delete pMissed;
|
||||
}
|
||||
|
||||
// Recyclers
|
||||
if (style.GetBool("recycler", false)) {
|
||||
TLuaTable* pRecyclerPath = style.GetTable("recyclerpath");
|
||||
if (pRecyclerPath != NULL) {
|
||||
float recyclerTime = (float)style.GetNumber("recyclertime", 20000);
|
||||
pRecyclerTask = new RecyclerTask(recyclerTime);
|
||||
TCurveRef pRecyclerCurve = TCurve::Create(*pRecyclerPath);
|
||||
delete pRecyclerPath;
|
||||
RecyclerRef pRecycler = Recycler::Create(pRecyclerCurve, 0);
|
||||
pBaseSprite->AddChild(pRecycler);
|
||||
pRecyclerTask->AddRecycler(pRecycler);
|
||||
pGunTask->AttachRecyclers(pRecyclerTask);
|
||||
}
|
||||
}
|
||||
|
||||
// Timer
|
||||
pTimer = TSprite::Create(0, TTexture::Get("image/timer_face", 0));
|
||||
pBaseSprite->AddChild(pTimer);
|
||||
pTimerHand = TSprite::Create(0, TTexture::Get("image/timer_hand", 0));
|
||||
pTimer->AddChild(pTimerHand);
|
||||
|
||||
PauseGame("game_paused");
|
||||
}
|
||||
|
||||
// game @0x0000d2e0
|
||||
void ChocolateFactory::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TBSGWindow::PostChildrenInit(style);
|
||||
pTime = GetChildWindowCast<TText>("time", -1);
|
||||
pCountdown = GetChildWindowCast<TText>("countdown", -1);
|
||||
pScore = GetChildWindowCast<TText>("score", -1);
|
||||
TVec2 timerPosition(720.0f, 80.0f);
|
||||
if (pScore != NULL) {
|
||||
TPoint at = pScore->GetWindowPos();
|
||||
ClientToScreen(&at);
|
||||
timerPosition.x = (float)((double)at.x + (double)pScore->GetWindowWidth() * 0.5);
|
||||
timerPosition.y = (float)((double)at.y + 0.5 * (double)pScore->GetWindowHeight());
|
||||
}
|
||||
pTimer->GetDrawSpec().mMatrix[2] = TVec3(timerPosition, 1.0f);
|
||||
SetAlpha(1.0f, true);
|
||||
ResetGame();
|
||||
}
|
||||
|
||||
// game @0x0000cf02
|
||||
void ChocolateFactory::ResetGame(void)
|
||||
{
|
||||
clock = gameTime + countdownTime;
|
||||
score = 0;
|
||||
bonusScore = 0;
|
||||
missCount = 0;
|
||||
state = GAME_COUNTDOWN;
|
||||
pTrayTask->Reset(1.0f);
|
||||
pConveyorTask->Reset(1.0f);
|
||||
pGunTask->Reset(1.0f);
|
||||
pRingTask->Reset(1.0f);
|
||||
pProductTask->Reset(1.0f);
|
||||
if (pRecyclerTask != NULL) {
|
||||
pRecyclerTask->Reset(1.0f);
|
||||
}
|
||||
PauseGame("game_paused");
|
||||
for (vector<TSpriteRef>::iterator it = missed.begin(); it != missed.end(); ++it) {
|
||||
pBaseSprite->RemoveChild(*it);
|
||||
}
|
||||
missed.clear();
|
||||
if (pScore != NULL) {
|
||||
pScore->SetText("0");
|
||||
}
|
||||
if (pTime != NULL) {
|
||||
pTime->SetText("");
|
||||
}
|
||||
BSGSoundEvent("chocolate_making_game_intro");
|
||||
BSGHideWindow(GetParent()->GetChildWindow("go", -1));
|
||||
BSGHideWindow(GetParent()->GetChildWindow("pause", -1));
|
||||
}
|
||||
|
||||
// game @0x0000d1d6
|
||||
void ChocolateFactory::StartGame(void)
|
||||
{
|
||||
TGameState* pGameState = TGameState::GetInstance();
|
||||
pGameState->SetState("ChocolateFactoryTime", "restart");
|
||||
pGameState->SetState("RecycleCount", 0);
|
||||
ResetGame();
|
||||
StartWindowAnimation(10, true, false, true);
|
||||
SetGameState(GAME_COUNTDOWN);
|
||||
ResumeGame();
|
||||
}
|
||||
|
||||
// game @0x0000c82c
|
||||
void ChocolateFactory::ResumeGame(void)
|
||||
{
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/gun_aimer"), TPoint(0x10, 0x10), false);
|
||||
if (gamePaused) {
|
||||
BSGSoundUnpause();
|
||||
TGameState::GetInstance()->SetState("ChocolateFactoryTime", 1);
|
||||
BSGHideWindow(GetParent()->GetChildWindow("go", -1));
|
||||
BSGShowWindow(GetParent()->GetChildWindow("pause", -1));
|
||||
TWindow* pInformation = GetParent()->GetChildWindow("information", -1);
|
||||
if (pInformation != NULL) {
|
||||
BSGHideWindow(pInformation);
|
||||
}
|
||||
pTrayTask->Restart(15);
|
||||
pConveyorTask->Restart(15);
|
||||
pGunTask->Restart(15);
|
||||
pRingTask->Restart(15);
|
||||
pProductTask->Restart(15);
|
||||
if (pRecyclerTask != NULL) {
|
||||
pRecyclerTask->Restart(15);
|
||||
}
|
||||
StartWindowAnimation(10, true, false, true);
|
||||
SetGameState(state);
|
||||
gamePaused = false;
|
||||
}
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(true);
|
||||
}
|
||||
|
||||
// game @0x00008384
|
||||
void ChocolateFactory::PauseGame(str textKey)
|
||||
{
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/cursor"), TPoint(1, 1), false);
|
||||
if (!gamePaused) {
|
||||
if (state != GAME_INIT) {
|
||||
BSGSoundPause();
|
||||
}
|
||||
TGameState::GetInstance()->SetState("ChocolateFactoryTime", 0);
|
||||
BSGShowWindow(GetParent()->GetChildWindow("go", -1));
|
||||
BSGHideWindow(GetParent()->GetChildWindow("pause", -1));
|
||||
gamePaused = true;
|
||||
pTrayTask->Pause();
|
||||
pConveyorTask->Pause();
|
||||
pGunTask->Pause();
|
||||
pRingTask->Pause();
|
||||
pProductTask->Pause();
|
||||
if (pRecyclerTask != NULL) {
|
||||
pRecyclerTask->Pause();
|
||||
}
|
||||
StopWindowAnimation();
|
||||
TWindow* pInformation = GetParent()->GetChildWindow("information", -1);
|
||||
if (pInformation != NULL) {
|
||||
TWindowManager::GetInstance()->GetScript()->SetGlobalString("gPauseText", textKey);
|
||||
FillWindowPtr(pInformation, "ui/game_pause.lua");
|
||||
BSGShowWindow(pInformation);
|
||||
}
|
||||
}
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(false);
|
||||
}
|
||||
|
||||
// game @0x0000bc48
|
||||
void ChocolateFactory::SetGameState(GameState newState)
|
||||
{
|
||||
if (newState == GAME_COUNTDOWN) {
|
||||
pTrayTask->Restart(15);
|
||||
pConveyorTask->Pause();
|
||||
pGunTask->Pause();
|
||||
pRingTask->Pause();
|
||||
pProductTask->Pause();
|
||||
}
|
||||
else if (newState == GAME_PLAYING) {
|
||||
BSGSoundEvent("chocolate_making_game");
|
||||
pTrayTask->Restart(15);
|
||||
pConveyorTask->Restart(15);
|
||||
pGunTask->Restart(15);
|
||||
pRingTask->Restart(15);
|
||||
pProductTask->Restart(15);
|
||||
}
|
||||
else {
|
||||
if (newState == GAME_ENDING) {
|
||||
BSGSoundEvent("game_over");
|
||||
BSGSoundEvent("chocolate_making_game_outro");
|
||||
pConveyorTask->Pause();
|
||||
pConveyorTask->Reset(1.0f);
|
||||
if (pTrayTask->AnyFull()) {
|
||||
pTrayTask->SetScale(5.0f);
|
||||
}
|
||||
}
|
||||
else if (newState == GAME_ABORTED) {
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/cursor"), TPoint(1, 1), false);
|
||||
BSGSoundEvent("game_over");
|
||||
BSGSoundEvent("chocolate_making_game_outro");
|
||||
pConveyorTask->Pause();
|
||||
pConveyorTask->Reset(1.0f);
|
||||
pGunTask->Pause();
|
||||
}
|
||||
else if (newState == GAME_OVER) {
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/cursor"), TPoint(1, 1), false);
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(false);
|
||||
pTrayTask->Pause();
|
||||
pConveyorTask->Pause();
|
||||
pConveyorTask->Reset(1.0f);
|
||||
pGunTask->Pause();
|
||||
pRingTask->Pause();
|
||||
pProductTask->Pause();
|
||||
if (pRecyclerTask != NULL) {
|
||||
pRecyclerTask->Pause();
|
||||
}
|
||||
StopWindowAnimation();
|
||||
TWindow* pInformation = GetParent()->GetChildWindow("information", -1);
|
||||
if (pInformation != NULL) {
|
||||
FillWindowPtr(pInformation, "ui/chocolate_gameover.lua");
|
||||
BSGShowWindow(pInformation);
|
||||
BSGHideWindow(GetParent()->GetChildWindow("go", -1));
|
||||
BSGHideWindow(GetParent()->GetChildWindow("pause", -1));
|
||||
}
|
||||
}
|
||||
state = newState;
|
||||
return;
|
||||
}
|
||||
if (pRecyclerTask != NULL) {
|
||||
pRecyclerTask->Restart(15);
|
||||
}
|
||||
state = newState;
|
||||
}
|
||||
|
||||
// game @0x0000cac4
|
||||
void ChocolateFactory::MissedIngredient(IngredientRef pIngredient)
|
||||
{
|
||||
missed.push_back(pIngredient);
|
||||
if (missCount < missPosition.size()) {
|
||||
pIngredient->GetDrawSpec().mMatrix.Identity();
|
||||
pIngredient->GetDrawSpec().mMatrix.Scale(0.6f, 0.6f);
|
||||
pIngredient->GetDrawSpec().mMatrix[2] = TVec3(missPosition[missCount], 1.0f);
|
||||
}
|
||||
missCount++;
|
||||
if (missCount == missPosition.size()) {
|
||||
SetGameState(GAME_ABORTED);
|
||||
BSGSoundEvent("ingredient_failure_factory shutdown");
|
||||
}
|
||||
else {
|
||||
pTrayTask->SetScale(0.5f * pTrayTask->GetScale());
|
||||
if (pTrayTask->GetScale() < 1.0f) {
|
||||
pTrayTask->SetScale(1.0f);
|
||||
}
|
||||
str sound = str::getFormatted("ingredient_failure_%lu", (unsigned long)missCount);
|
||||
BSGSoundEvent(sound);
|
||||
if (warnOnMiss && missCount == 1) {
|
||||
PauseGame("choco_first_missed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0000cce8
|
||||
bool ChocolateFactory::OnMessage(TMessage* pMessage)
|
||||
{
|
||||
switch (pMessage->mType) {
|
||||
case kAppDeactivate:
|
||||
PauseGame("game_paused");
|
||||
break;
|
||||
case kMissedIngredientEvent:
|
||||
MissedIngredient(static_cast<MissedIngredientMessage*>(pMessage)->pIngredient);
|
||||
return true;
|
||||
case kManufactureProductEvent:
|
||||
if (machineTime == 0) {
|
||||
machineTime = 1;
|
||||
}
|
||||
BSGSoundEvent("snatch");
|
||||
// fall through
|
||||
case kProduceProductEvent:
|
||||
pProductTask->AddProduct(pBaseSprite);
|
||||
return true;
|
||||
case kCountBonusProductEvent:
|
||||
bonusScore++;
|
||||
// fall through
|
||||
case kCountProductEvent:
|
||||
score++;
|
||||
if (pScore == NULL) {
|
||||
return true;
|
||||
}
|
||||
pScore->SetText(str::getFormatted("%lu", (unsigned long)score));
|
||||
return true;
|
||||
case kFillTrayEvent:
|
||||
pTrayTask->SetScale(speedUpFactor * pTrayTask->GetScale());
|
||||
if (maxSpeed < pTrayTask->GetScale()) {
|
||||
pTrayTask->SetScale(maxSpeed);
|
||||
}
|
||||
break;
|
||||
case kColorMatchEvent:
|
||||
static_cast<FlyingRingStartMessage*>(pMessage)->Initiate(pRingTask, TVec2(689.0f, 555.0f));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0000866c
|
||||
bool ChocolateFactory::OnKeyDown(char key, uint32_t flags)
|
||||
{
|
||||
if (key == TEvent::kEscape) {
|
||||
if (!gamePaused) {
|
||||
PauseGame("game_paused");
|
||||
}
|
||||
str cheatMode = TPlatform::GetConfig(str(TPlatform::kCheatMode), "");
|
||||
if ((flags & 1) != 0) {
|
||||
TWindowManager::GetInstance()->DoLuaString(this, "DoModal('dev/dev_menu.lua')");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00008000
|
||||
bool ChocolateFactory::OnMouseDown(TPoint const& point)
|
||||
{
|
||||
if (state == GAME_PLAYING) {
|
||||
pGunTask->Fire(point);
|
||||
}
|
||||
return swallowMouse;
|
||||
}
|
||||
|
||||
// game @0x000080d2
|
||||
bool ChocolateFactory::OnMouseMove(TPoint const& point)
|
||||
{
|
||||
TVec3 gunPosition(pGun->GetDrawSpec().mMatrix[2]);
|
||||
TVec2 direction;
|
||||
direction.x = (float)point.x - gunPosition.x;
|
||||
direction.y = (float)point.y - gunPosition.y;
|
||||
direction.Normalize();
|
||||
float angle = acosf(direction.y);
|
||||
if (0.0f < direction.x) {
|
||||
angle = -angle;
|
||||
}
|
||||
TMat3 rotation = TMat3::GetRotation((float)((double)angle + 3.141592653589793));
|
||||
rotation[2] = gunPosition;
|
||||
pGun->GetDrawSpec().mMatrix = rotation;
|
||||
return swallowMouse;
|
||||
}
|
||||
|
||||
// game @0x0000c180
|
||||
bool ChocolateFactory::OnTaskAnimate(void)
|
||||
{
|
||||
if (!TPlatform::GetInstance()->IsForeground()) {
|
||||
PauseGame("game_paused");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (state == GAME_ABORTED ||
|
||||
(state == GAME_ENDING && !pRingTask->AnyFlying() && !pGunTask->AnyFlying() && !pProductTask->AnyProducts() && !pTrayTask->AnyFull())) {
|
||||
float newScale = (float)((double)pTrayTask->GetScale() * 0.95);
|
||||
if (!((double)newScale < 0.05)) {
|
||||
pTrayTask->SetScale(newScale);
|
||||
}
|
||||
else {
|
||||
SetGameState(GAME_OVER);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t oldClock = clock;
|
||||
if (state == GAME_COUNTDOWN) {
|
||||
if (gameTime + 10U < oldClock) {
|
||||
clock = oldClock - 10;
|
||||
if (oldClock / 1000 > (oldClock - 10) / 1000) {
|
||||
BSGSoundEvent("clock_tick");
|
||||
if (pCountdown != NULL) {
|
||||
pCountdown->SetText(str::getFormatted("%d", (int)(((clock - gameTime) + 999U) / 1000)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
clock = oldClock - 10;
|
||||
BSGSoundEvent("start_bell");
|
||||
SetGameState(GAME_PLAYING);
|
||||
if (pCountdown != NULL) {
|
||||
pCountdown->SetText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (state == GAME_PLAYING) {
|
||||
if (oldClock < 0xb) {
|
||||
if (pTimerHand) {
|
||||
pTimerHand->GetDrawSpec().mMatrix.Identity();
|
||||
}
|
||||
if (pTime != NULL) {
|
||||
pTime->SetText("0:00");
|
||||
}
|
||||
SetGameState(GAME_ENDING);
|
||||
}
|
||||
else {
|
||||
clock = oldClock - 10;
|
||||
if (warnTime < oldClock && oldClock - 10 <= warnTime) {
|
||||
BSGSoundEvent("whistle");
|
||||
}
|
||||
if (pTime != NULL) {
|
||||
uint32_t seconds = (clock + 999U) / 1000;
|
||||
pTime->SetText(str::getFormatted("%lu:%02lu", (unsigned long)(seconds / 0x3c), (unsigned long)(seconds % 0x3c)));
|
||||
}
|
||||
if (pTimerHand) {
|
||||
float turn = (float)((double)((float)clock / (float)gameTime + (float)clock / (float)gameTime) * 3.141592653589793);
|
||||
pTimerHand->GetDrawSpec().mMatrix = TMat3::GetRotation(-turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pRecyclerTask != NULL) {
|
||||
pRecyclerTask->Tick(10);
|
||||
}
|
||||
pTrayTask->Tick(10);
|
||||
pConveyorTask->Tick(10);
|
||||
pGunTask->Tick(10);
|
||||
pRingTask->Tick(10);
|
||||
pProductTask->Tick(10);
|
||||
|
||||
if (machineTime != 0) {
|
||||
uint32_t next = machineTime + 10;
|
||||
machineTime = (next < 400) ? next : 0;
|
||||
double machineTimeD = (double)machineTime;
|
||||
float angle = (float)(((machineTimeD + machineTimeD) * 3.141592653589793) / 400.0);
|
||||
|
||||
TVec3 position(pTrayTemplate->GetDrawSpec().mMatrix[2]);
|
||||
pTrayTemplate->GetDrawSpec().mMatrix = TMat3::GetRotation(angle);
|
||||
pTrayTemplate->GetDrawSpec().mMatrix[2] = position;
|
||||
|
||||
position = pUpperArm->GetDrawSpec().mMatrix[2];
|
||||
pUpperArm->GetDrawSpec().mMatrix = TMat3::GetRotation(-angle);
|
||||
pUpperArm->GetDrawSpec().mMatrix[2] = position;
|
||||
|
||||
position = pLowerArm->GetDrawSpec().mMatrix[2];
|
||||
pLowerArm->GetDrawSpec().mMatrix = TMat3::GetRotation(angle);
|
||||
pLowerArm->GetDrawSpec().mMatrix[2] = position;
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00008030
|
||||
void ChocolateFactory::Draw(void)
|
||||
{
|
||||
TBSGWindow::Draw();
|
||||
TBegin2d begin2d;
|
||||
if (pBaseSprite) {
|
||||
pBaseSprite->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
}
|
||||
begin2d.Done();
|
||||
}
|
||||
145
port/game/ChocolateGun.cpp
Normal file
145
port/game/ChocolateGun.cpp
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
// Port of the game's ChocolateGun.cpp (Chocolatier 3, Big Splash Games): ChocolateGunTask, the minigame task that
|
||||
// owns the gun sprite of the chocolate factory. Fire pops the next ingredient off the conveyor and shoots it at the
|
||||
// clicked point as a FlyingIngredient; Animate advances every flying ingredient and offers it to the trays (a hit
|
||||
// within 16 + the tray radius of the flight segment, if the tray can accept it) and to the recycler bins (a hit
|
||||
// within 16 + the bin radius of the ingredient), and drops ingredients that reached the end of the flight.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// ChocolateGun.h (port/game/ChocolateGun.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TScalingTask 0x0..0x1c (vptr 0x0), pGun 0x1c, pConveyor 0x24, pTrayTask 0x2c, pRecyclerTask
|
||||
// 0x30 (set to 0 by the constructor), gunTime 0x34, flying (std::list<FlyingIngredientRef>) 0x38. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4, the "flight finished" value of
|
||||
// FlyingIngredient::Tick), 16.0f (@0x001ab6f8, the hit radius added to the tray / bin radius), 1000.0f
|
||||
// (@0x001ab6fc, the flight speed: the direction is scaled to length 1000).
|
||||
// - Strings from the game's __cstring: "DoAnim" (@0x001589c8), "launch" (@0x001589d0, the sound message text, event
|
||||
// 0x3ea = kSoundEvent).
|
||||
// - Ingredient vtable slots used by Animate: HitTray 0x2c, HitRecycler 0x30, Die 0x34. TSprite vtable slot 0x14 in
|
||||
// Reset is TSprite::RemoveChild, called on the sprite parent (the TSprite at +0xc) of each flying ingredient.
|
||||
// - The tray set is at ChocolateTrayTask +0x20 (nodes at +0x2c begin, header +0x24), the bin set at RecyclerTask +0x20.
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in ChocolateGun.h):
|
||||
// ~ChocolateGunTask (implicit): D1 game @0x0016749c (list, then the pConveyor and pGun shared_ptr releases).
|
||||
// std::list<FlyingIngredientRef> instantiations are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "ChocolateGun.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x0000d504
|
||||
ChocolateGunTask::ChocolateGunTask(TAnimatedSpriteRef pGun_, TReal gunTime_, ::shared_ptr<IngredientQueue> pConveyor_, ChocolateTrayTask* pTrayTask_)
|
||||
: TScalingTask(), pGun(pGun_), pConveyor(pConveyor_), pTrayTask(pTrayTask_), pRecyclerTask(0), gunTime(gunTime_), flying()
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0000d588
|
||||
void ChocolateGunTask::Reset(TReal newScale)
|
||||
{
|
||||
TScalingTask::Reset(newScale);
|
||||
|
||||
for (list<FlyingIngredientRef>::iterator it = flying.begin(); it != flying.end(); ++it) {
|
||||
TSprite* pParent = (*it)->pIngredient->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild((*it)->pIngredient);
|
||||
}
|
||||
}
|
||||
flying.clear();
|
||||
}
|
||||
|
||||
// game @0x0000d628
|
||||
bool ChocolateGunTask::Animate(void)
|
||||
{
|
||||
TReal tElapsed = AnimateDelta(gunTime);
|
||||
|
||||
list<FlyingIngredientRef>::iterator it = flying.begin();
|
||||
while (it != flying.end()) {
|
||||
list<FlyingIngredientRef>::iterator cur = it;
|
||||
++it;
|
||||
FlyingIngredientRef& pFlying = *cur;
|
||||
|
||||
TVec3 oldPos(pFlying->pIngredient->GetPosition());
|
||||
TReal result = pFlying->Tick(tElapsed);
|
||||
|
||||
if (result == 1.0f) {
|
||||
if (pFlying->pIngredient->Die()) {
|
||||
flying.erase(cur);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
TVec3 newPos(pFlying->pIngredient->GetPosition());
|
||||
|
||||
bool done = false;
|
||||
for (set<ChocolateTrayRef>::iterator trayIt = pTrayTask->GetTrays().begin(); trayIt != pTrayTask->GetTrays().end(); ++trayIt) {
|
||||
TVec3 trayPos((*trayIt)->GetDrawSpec().mMatrix[2]);
|
||||
TReal dist2 = PointToSegmentDistanceSquared(oldPos, newPos, trayPos);
|
||||
TReal reach = 16.0f + (*trayIt)->GetRadius();
|
||||
if (dist2 <= reach * reach) {
|
||||
if ((*trayIt)->CanAccept(IngredientRef(pFlying->pIngredient))) {
|
||||
if (pFlying->pIngredient->HitTray(ChocolateTrayRef(*trayIt))) {
|
||||
flying.erase(cur);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (done) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pRecyclerTask != 0) {
|
||||
for (set<RecyclerRef>::iterator binIt = pRecyclerTask->GetBins().begin(); binIt != pRecyclerTask->GetBins().end(); ++binIt) {
|
||||
TVec3 diff = (*binIt)->GetDrawSpec().mMatrix[2] - pFlying->pIngredient->GetDrawSpec().mMatrix[2];
|
||||
TReal reach = 16.0f + (*binIt)->GetRadius();
|
||||
if (diff.LengthSquared() <= reach * reach) {
|
||||
if ((*binIt)->CanAccept(IngredientRef(pFlying->pIngredient))) {
|
||||
if (pFlying->pIngredient->HitRecycler(RecyclerRef(*binIt))) {
|
||||
flying.erase(cur);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0000d9f0
|
||||
bool ChocolateGunTask::Fire(TPoint const& point)
|
||||
{
|
||||
IngredientRef pIngredient = pConveyor->PopConveyor();
|
||||
if (!pIngredient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pIngredient->SetLayer(INGREDIENT_FLYING_LAYER);
|
||||
|
||||
TVec3 start(pGun->GetDrawSpec().mMatrix[2]);
|
||||
TVec2 direction;
|
||||
direction.x = (TReal)point.x - start.x;
|
||||
direction.y = (TReal)point.y - start.y;
|
||||
TReal length = direction.Length();
|
||||
direction = direction * (1000.0f / length);
|
||||
|
||||
FlyingIngredientRef pFlying = FlyingIngredient::Create(IngredientRef(pIngredient));
|
||||
pFlying->startPoint.x = start.x;
|
||||
pFlying->startPoint.y = start.y;
|
||||
pFlying->direction = direction;
|
||||
flying.push_back(pFlying);
|
||||
|
||||
pGun->Play("DoAnim");
|
||||
TWindowManager::GetInstance()->PostWindowMessage(new TMessage(kSoundEvent, "launch"));
|
||||
|
||||
return true;
|
||||
}
|
||||
137
port/game/ChocolateQueue.cpp
Normal file
137
port/game/ChocolateQueue.cpp
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
// Port of the game's ChocolateQueue.cpp (Chocolatier 3, Big Splash Games): ChocolateProduct (a finished chocolate
|
||||
// that rides the factory's product conveyor curve) and ChocolateProductQueueTask (the task that creates the products
|
||||
// and moves them along the curve, one per frame step, until they reach the end).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// ChocolateQueue.h (port/game/ChocolateQueue.h, unchanged). CustomItems.h (the shipped header, copied unchanged to
|
||||
// port/game) declares BuildItemAppearance, which AddProduct calls.
|
||||
//
|
||||
// Layout (game, i386): ChocolateProduct: TSprite 0x0..0x80, pCurve 0x80, t 0x88; sizeof 0x8c (Create allocates 0x8c
|
||||
// bytes). ChocolateProductQueueTask: TScalingTask 0x0..0x1c, pCurve 0x1c, conveyorTime 0x24, appearanceCache 0x28,
|
||||
// appearance 0x34, tints 0x40, products (std::list<ChocolateProductRef>) 0x4c. The headers match.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4), 0.5f (AddProduct's BuildItemAppearance scale, an
|
||||
// immediate); double 0.1 (@0x001ab4c8).
|
||||
// - Strings from the game's __cstring: "FactoryGame" (the factory child window), "" (@0x001581bc) and
|
||||
// "chocolate_counted" (the sound message text; event 0x3ea = kSoundEvent). The count message is event 0x3ef =
|
||||
// kCountProductEvent.
|
||||
// - ChocolateProductQueueTask::Animate walks the list in order and stops as soon as the previous (surviving)
|
||||
// product's t is below 0.1 (the first product tests against an initial 1.0f), so products that follow a product
|
||||
// that has just left the start are not updated in that call. A product whose Update returns false is removed from
|
||||
// its sprite parent, the "FactoryGame" child of the top modal window (looked up once and kept, retried while
|
||||
// missing) is sent kCountProductEvent, the sound "chocolate_counted" is posted, and the product is erased.
|
||||
// - ChocolateProductQueueTask::Reset only calls TScalingTask::Reset (it clears nothing).
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in the header):
|
||||
// ~ChocolateProduct (inline in ChocolateQueue.h): D0 game @0x001683d8, D1 game @0x0016842c (releases pCurve, then
|
||||
// ~TSprite).
|
||||
// ~ChocolateProductQueueTask (implicit): D1 game @0x00167390 (products, tints, appearance, appearanceCache, pCurve).
|
||||
// std::list<ChocolateProductRef> instantiations and boost::shared_ptr<ChocolateProduct> template code are not
|
||||
// ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "ChocolateQueue.h"
|
||||
#include "CustomItems.h"
|
||||
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/window.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x0000dc2c
|
||||
bool ChocolateProduct::Update(TReal elapsed)
|
||||
{
|
||||
t = elapsed + t;
|
||||
if (1.0f < t) {
|
||||
t = 1.0f;
|
||||
}
|
||||
GetDrawSpec().mMatrix[2] = TVec3(pCurve->GetPoint(t, 0), 1.0f);
|
||||
return t <= 1.0f && 1.0f != t;
|
||||
}
|
||||
|
||||
// game @0x0000dcca
|
||||
void ChocolateProductQueueTask::Reset(TReal newScale)
|
||||
{
|
||||
TScalingTask::Reset(newScale);
|
||||
}
|
||||
|
||||
// game @0x0000dcd4
|
||||
ChocolateProduct::ChocolateProduct(TCurveRef pCurve_)
|
||||
: TSprite(2), pCurve(pCurve_), t(0)
|
||||
{
|
||||
GetDrawSpec().mMatrix[2] = TVec3(pCurve->GetStartPoint(), 1.0f);
|
||||
}
|
||||
|
||||
// game @0x0000dd88
|
||||
ChocolateProductRef ChocolateProduct::Create(TCurveRef pCurve)
|
||||
{
|
||||
return ChocolateProductRef(new ChocolateProduct(pCurve));
|
||||
}
|
||||
|
||||
// game @0x0000de10
|
||||
ChocolateProductQueueTask::ChocolateProductQueueTask(TCurveRef pCurve_, TReal conveyorTime_, vector<str> appearance_, vector<TColor> tints_)
|
||||
: TScalingTask(), pCurve(pCurve_), conveyorTime(conveyorTime_), appearanceCache(), appearance(appearance_), tints(tints_), products()
|
||||
{
|
||||
for (int i = 0; i < (int)appearance.size(); i++) {
|
||||
TTextureRef pTexture = TTexture::Get(appearance[i], 0);
|
||||
if (pTexture) {
|
||||
appearanceCache.push_back(pTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0000dfa4
|
||||
bool ChocolateProductQueueTask::Animate(void)
|
||||
{
|
||||
TReal tElapsed = AnimateDelta(conveyorTime);
|
||||
|
||||
TWindow* pFactory = NULL;
|
||||
TReal lastT = 1.0f;
|
||||
list<ChocolateProductRef>::iterator it = products.begin();
|
||||
while (it != products.end() && !((double)lastT < 0.1)) {
|
||||
list<ChocolateProductRef>::iterator cur = it;
|
||||
++it;
|
||||
|
||||
if (!(*cur)->Update(tElapsed)) {
|
||||
TSprite* pParent = (*cur)->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild(*cur);
|
||||
}
|
||||
|
||||
bool send = true;
|
||||
if (pFactory == NULL) {
|
||||
send = false;
|
||||
pFactory = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pFactory != NULL) {
|
||||
pFactory = pFactory->GetChildWindow("FactoryGame", -1);
|
||||
if (pFactory != NULL) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (send) {
|
||||
pFactory->SendWindowMessage(new TMessage(kCountProductEvent, "", pFactory));
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->PostWindowMessage(new TMessage(kSoundEvent, "chocolate_counted", NULL));
|
||||
products.erase(cur);
|
||||
lastT = 1.0f;
|
||||
} else {
|
||||
lastT = (*cur)->GetT();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0000e1f4
|
||||
void ChocolateProductQueueTask::AddProduct(TSpriteRef pBase)
|
||||
{
|
||||
ChocolateProductRef pProduct = ChocolateProduct::Create(pCurve);
|
||||
BuildItemAppearance(pProduct, appearance, tints, 0.5f);
|
||||
products.push_back(pProduct);
|
||||
pBase->AddChild(pProduct);
|
||||
}
|
||||
393
port/game/ChocolateTray.cpp
Normal file
393
port/game/ChocolateTray.cpp
Normal file
|
|
@ -0,0 +1,393 @@
|
|||
// Port of the game's ChocolateTray.cpp (Chocolatier 3, Big Splash Games): ChocolateTray (a tray that rides the
|
||||
// factory's tray curve, takes the ingredients of one recipe into its slots, and is cleared and counted as a product
|
||||
// once every slot is filled) and ChocolateTrayTask (the task that moves all trays). A tray has one slot per recipe
|
||||
// ingredient, laid out on a circle of radius 50 around the tray; filling it with ingredients of one colour starts the
|
||||
// colour-match sound and flying rings.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// ChocolateTray.h (port/game/ChocolateTray.h, unchanged; IsFull has no out-of-line code in the game and is defined
|
||||
// here, see below).
|
||||
//
|
||||
// Layout (game, i386): ChocolateTray: TSprite 0x0..0x80, lastUpdate 0x80, offset 0x84, endpoint 0x88, radius 0x8c,
|
||||
// pCurve 0x90, slots (std::vector<IngredientRef>) 0x98, fillCount 0xa4, color 0xa8 (byte), pTrayRing 0xac,
|
||||
// pClearAnimation 0xb4, pPiston[4] 0xbc, recipe (reference) 0xdc; sizeof 0xe0 (Create allocates 0xe0 bytes).
|
||||
// ChocolateTrayTask: TScalingTask 0x0..0x1c, trayCycleTime 0x1c, trays (std::set<ChocolateTrayRef>) 0x20 (tree
|
||||
// header 0x24, leftmost node 0x2c). The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4), 50.0f (@0x001ab700, the slot circle radius and the
|
||||
// piston base offset), 75.0f (0x42960000, the initial / restored radius, an immediate); doubles 2*pi
|
||||
// (@0x001ab4d0), 0.25 (@0x001ab4d8). The slot angle is (double)i * 2*pi / (double)slotCount converted to float;
|
||||
// the slot position is (sinf(angle) * 50, -(cosf(angle) * 50)) (the negation is the xor with the 0x80000000
|
||||
// mask at 0x00192940).
|
||||
// - Strings from the game's __cstring: "image/tray%d", "_ring", "image/powerup.xml", "image/tray_arm_1".."_4",
|
||||
// "FactoryGame", "DoAnim", "ingredient_complete_full_bonus", "ingredient_complete" (@0x00158acc),
|
||||
// "ingredient_complete_colormatch" (@0x00158aac), "ingredient_color_match_%lu" (@0x00158ae0),
|
||||
// "ingredient_success_%lu" (@0x00158afc), "" (@0x001581bc).
|
||||
// - Events (EChocoThreeMessages): kSoundEvent 0x3ea, kManufactureProductEvent 0x3ec, kProduceProductEvent 0x3ed,
|
||||
// kFillTrayEvent 0x3f0 (sent to the top modal window itself, the others to its "FactoryGame" child).
|
||||
// - Ingredient vtable slots used: SetColor 0x28. TSprite vtable slot 0x14 is RemoveChild.
|
||||
// - BuildPiston(str, int) game @0x0000e8ca is a file-level function (no declaration in the header); BuildPistons
|
||||
// passes layer 0xffffff9c = -100 for all four arms. The 8 or-ed into the draw flags (+0x70) is kUseCenter.
|
||||
// - ChocolateTray::IsFull has no out-of-line code in the game (only its exception-handling clone); the game inlines
|
||||
// its test fillCount == recipe.size() in AnyFull, Update and AddIngredient, which is what is defined here.
|
||||
// ChocolateTray::CountFilled has no code in the game at all and is not defined.
|
||||
// - SetColor shows the tray ring (SetVisible(color != 0)) after tinting it with kFactoryColors[color].
|
||||
// - ChocolateTrayTask::Reset does not call TScalingTask::Reset: it clears every tray without animation and sets
|
||||
// scale = newScale and lastClock = taskClock (time and lastTime stay).
|
||||
// - ChocolateTrayTask::Animate: with all trays full (also true for an empty tray set) it posts the sound
|
||||
// "ingredient_complete_full_bonus" and clears every tray with animation, sending each kProduceProductEvent.
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFSHAREDTYPEDEF / PFTYPEIMPL: ClassId game @0x0000e31c, GetTypeName game @0x0000e326 ("ChocolateTray"),
|
||||
// IsKindOf game @0x00168b04 (the ChocolateTray class id, else TSprite::IsKindOf), GetRef game @0x00169754
|
||||
// (header inline: shared_from_this()->GetCast<ChocolateTray>()).
|
||||
// ~ChocolateTray (declared, empty body): D1 game @0x0000e6d2, D0 game @0x0000e7ca (the vptr store, the four
|
||||
// pPiston, pClearAnimation, pTrayRing, slots and pCurve members in reverse order, then ~TSprite).
|
||||
// ChocolateTrayTask constructor (header inline) game @0x00167298: TScalingTask(), trayCycleTime, empty set.
|
||||
// The std::set<ChocolateTrayRef> instantiations are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "ChocolateTray.h"
|
||||
#include "FlyingRing.h"
|
||||
#include "IngredientQueue.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/window.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
PFTYPEIMPL(ChocolateTray);
|
||||
|
||||
// game @0x0000e8ca
|
||||
static TSpriteRef BuildPiston(str name, int layer)
|
||||
{
|
||||
TTextureRef pTexture = TTexture::Get(name, 0);
|
||||
TSpriteRef pSprite = TSprite::Create(layer, pTexture);
|
||||
pSprite->GetDrawSpec().mFlags |= TDrawSpec::kUseCenter;
|
||||
int height = pTexture->GetHeight();
|
||||
uint32_t width = pTexture->GetWidth();
|
||||
pSprite->GetDrawSpec().mCenter = TVec2((TReal)(width >> 1), (TReal)(height - 2));
|
||||
return pSprite;
|
||||
}
|
||||
|
||||
// game @0x0000e330
|
||||
TVec2 ChocolateTray::GetSlotPosition(uint32_t i, uint32_t slotCount)
|
||||
{
|
||||
TVec2 position;
|
||||
TReal angle = (TReal)(((double)i * 6.283185307179586) / (double)slotCount);
|
||||
position.x = sinf(angle) * 50.0f;
|
||||
position.y = -(cosf(angle) * 50.0f);
|
||||
return position;
|
||||
}
|
||||
|
||||
// game @0x0000e41e
|
||||
void ChocolateTray::Scale(TReal scale)
|
||||
{
|
||||
radius = scale * radius;
|
||||
GetDrawSpec().mMatrix.Scale(scale);
|
||||
}
|
||||
|
||||
// game @0x0000e452
|
||||
TVec2 ChocolateTray::GetSlotPosition(uint32_t i) const
|
||||
{
|
||||
return GetSlotPosition(i, (uint32_t)recipe.size());
|
||||
}
|
||||
|
||||
// game @0x0000e48c
|
||||
void ChocolateTray::SetColor(uint8_t newColor)
|
||||
{
|
||||
color = newColor;
|
||||
for (uint32_t i = 0; i < (uint32_t)slots.size(); i++) {
|
||||
if (slots[i]) {
|
||||
slots[i]->SetColor(newColor);
|
||||
}
|
||||
}
|
||||
if (pTrayRing) {
|
||||
pTrayRing->GetDrawSpec().mTint = kFactoryColors[color];
|
||||
pTrayRing->SetVisible(color != 0);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0000e54a
|
||||
bool ChocolateTray::CanAccept(IngredientRef pIngredient) const
|
||||
{
|
||||
for (uint32_t i = 0; i < (uint32_t)recipe.size(); i++) {
|
||||
str name = pIngredient->GetName();
|
||||
bool match = true;
|
||||
if (!(recipe[i] == name) || slots[i]) {
|
||||
match = false;
|
||||
}
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0000e608
|
||||
void ChocolateTray::GetGlobalSlotPositions(vector<TVec2>& v) const
|
||||
{
|
||||
for (uint32_t i = 0; i < (uint32_t)recipe.size(); i++) {
|
||||
TVec2 position = GetSlotPosition(i);
|
||||
position.x = position.x + GetDrawSpec().mMatrix[2].x;
|
||||
position.y = position.y + GetDrawSpec().mMatrix[2].y;
|
||||
v.push_back(position);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0000e67e
|
||||
bool ChocolateTrayTask::AnyFull(void)
|
||||
{
|
||||
for (set<ChocolateTrayRef>::iterator it = trays.begin(); it != trays.end(); ++it) {
|
||||
if ((*it)->IsFull()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// (no out-of-line code in the game; see the notes above)
|
||||
bool ChocolateTray::IsFull(void) const
|
||||
{
|
||||
return fillCount == (uint32_t)recipe.size();
|
||||
}
|
||||
|
||||
// game @0x0000e6d2 (D1), game @0x0000e7ca (D0)
|
||||
ChocolateTray::~ChocolateTray(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0000ea2c
|
||||
void ChocolateTray::BuildPistons(TSpriteRef pParent)
|
||||
{
|
||||
pPiston[0] = BuildPiston("image/tray_arm_4", -100);
|
||||
pPiston[1] = BuildPiston("image/tray_arm_3", -100);
|
||||
pPiston[2] = BuildPiston("image/tray_arm_2", -100);
|
||||
pPiston[3] = BuildPiston("image/tray_arm_1", -100);
|
||||
|
||||
pParent->AddChild(pPiston[0]);
|
||||
pParent->AddChild(pPiston[1]);
|
||||
pParent->AddChild(pPiston[2]);
|
||||
pParent->AddChild(pPiston[3]);
|
||||
}
|
||||
|
||||
// game @0x0000ed14
|
||||
ChocolateTray::ChocolateTray(ProductRecipe& recipe_, TCurveRef pCurve_, TReal offset_, TReal endpoint_)
|
||||
: TSprite(5), offset(offset_), endpoint(endpoint_), radius(75.0f), pCurve(pCurve_), slots(), fillCount(0), color(0),
|
||||
pTrayRing(), pClearAnimation(), recipe(recipe_)
|
||||
{
|
||||
str name = str::getFormatted("image/tray%d", (uint32_t)recipe.size());
|
||||
SetTexture(TTexture::Get(name, 0));
|
||||
|
||||
name = name + "_ring";
|
||||
pTrayRing = TSprite::Create(0, TTexture::Get(name, 0));
|
||||
AddChild(pTrayRing);
|
||||
pTrayRing->SetVisible(false);
|
||||
|
||||
slots.resize(recipe.size());
|
||||
|
||||
pClearAnimation = TAnimatedSprite::Create(2);
|
||||
pClearAnimation->SetTexture(TTextureRef(TAnimatedTexture::Get("image/powerup.xml", "", "")));
|
||||
pClearAnimation->SetCurrentFrame(pClearAnimation->GetNumFrames() - 1);
|
||||
AddChild(pClearAnimation);
|
||||
|
||||
lastUpdate = offset;
|
||||
}
|
||||
|
||||
// game @0x0000f308
|
||||
ChocolateTrayRef ChocolateTray::Create(ProductRecipe& recipe, TCurveRef pCurve, TReal offset, TReal endpoint)
|
||||
{
|
||||
return ChocolateTrayRef(new ChocolateTray(recipe, pCurve, offset, endpoint));
|
||||
}
|
||||
|
||||
// game @0x0000f3a6
|
||||
void ChocolateTray::Clear(bool animate)
|
||||
{
|
||||
for (uint32_t i = 0; i < (uint32_t)slots.size(); i++) {
|
||||
if (slots[i]) {
|
||||
RemoveChild(slots[i]);
|
||||
slots[i] = IngredientRef();
|
||||
}
|
||||
}
|
||||
|
||||
fillCount = 0;
|
||||
color = 0;
|
||||
if (pTrayRing) {
|
||||
pTrayRing->SetVisible(false);
|
||||
}
|
||||
if (animate && pClearAnimation) {
|
||||
pClearAnimation->Play("DoAnim");
|
||||
}
|
||||
|
||||
TVec3 position(GetDrawSpec().mMatrix[2]);
|
||||
radius = 75.0f;
|
||||
GetDrawSpec().mMatrix.Identity();
|
||||
GetDrawSpec().mMatrix[2] = position;
|
||||
}
|
||||
|
||||
// game @0x0000f562
|
||||
void ChocolateTrayTask::Reset(TReal newScale)
|
||||
{
|
||||
for (set<ChocolateTrayRef>::iterator it = trays.begin(); it != trays.end(); ++it) {
|
||||
(*it)->Clear(false);
|
||||
}
|
||||
scale = newScale;
|
||||
lastClock = taskClock;
|
||||
}
|
||||
|
||||
// game @0x0000f5ac
|
||||
void ChocolateTray::Update(TReal t)
|
||||
{
|
||||
TReal sum = t + offset;
|
||||
TReal frac = sum - floorf(sum);
|
||||
|
||||
if (pCurve) {
|
||||
TVec2 point = pCurve->GetPoint(frac, 0);
|
||||
GetDrawSpec().mMatrix[2] = TVec3(point, 1.0f);
|
||||
}
|
||||
|
||||
TVec3 position(GetDrawSpec().mMatrix[2]);
|
||||
double step = (double)(position.y - 50.0f) * 0.25;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (pPiston[i]) {
|
||||
position.y = (TReal)((double)(4 - i) * step);
|
||||
pPiston[i]->GetDrawSpec().mMatrix[2] = position;
|
||||
}
|
||||
}
|
||||
|
||||
TReal last = lastUpdate;
|
||||
if ((frac < last && ((endpoint <= frac && endpoint <= last) || (frac <= endpoint && last <= endpoint))) ||
|
||||
((last < frac && last <= endpoint) && endpoint <= frac)) {
|
||||
if (IsFull()) {
|
||||
TWindow* pTop = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pTop != NULL) {
|
||||
TWindow* pFactory = pTop->GetChildWindow("FactoryGame", -1);
|
||||
if (pFactory != NULL) {
|
||||
pFactory->SendWindowMessage(new TMessage(kManufactureProductEvent, "", pFactory));
|
||||
}
|
||||
}
|
||||
Clear(true);
|
||||
}
|
||||
}
|
||||
lastUpdate = frac;
|
||||
}
|
||||
|
||||
// game @0x0000f836
|
||||
bool ChocolateTrayTask::Animate(void)
|
||||
{
|
||||
TScalingTask::Animate();
|
||||
TReal t = GetT(trayCycleTime);
|
||||
|
||||
bool allFull = true;
|
||||
for (set<ChocolateTrayRef>::iterator it = trays.begin(); it != trays.end(); ++it) {
|
||||
(*it)->Update(t);
|
||||
if (!(*it)->IsFull()) {
|
||||
allFull = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (allFull) {
|
||||
TWindow* pFactory = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pFactory != NULL) {
|
||||
pFactory = pFactory->GetChildWindow("FactoryGame", -1);
|
||||
}
|
||||
TWindowManager::GetInstance()->PostWindowMessage(new TMessage(kSoundEvent, "ingredient_complete_full_bonus", NULL));
|
||||
for (set<ChocolateTrayRef>::iterator it = trays.begin(); it != trays.end(); ++it) {
|
||||
(*it)->Clear(true);
|
||||
if (pFactory != NULL) {
|
||||
pFactory->SendWindowMessage(new TMessage(kProduceProductEvent, "", pFactory));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0000fa44
|
||||
bool ChocolateTray::AddIngredient(IngredientRef pIngredient)
|
||||
{
|
||||
str sound("");
|
||||
bool result = false;
|
||||
|
||||
for (uint32_t i = 0; i < (uint32_t)recipe.size(); i++) {
|
||||
str name = pIngredient->GetName();
|
||||
bool match = true;
|
||||
if (!(recipe[i] == name) || slots[i]) {
|
||||
match = false;
|
||||
}
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TVec2 slotPosition = GetSlotPosition(i);
|
||||
TSprite* pParent = pIngredient->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild(pIngredient);
|
||||
}
|
||||
AddChild(pIngredient);
|
||||
slots[i] = pIngredient;
|
||||
pIngredient->GetDrawSpec().mMatrix[2] = TVec3(slotPosition, 1.0f);
|
||||
fillCount++;
|
||||
|
||||
uint8_t trayColor = color;
|
||||
uint8_t ingredientColor = pIngredient->GetColor();
|
||||
if (trayColor != ingredientColor) {
|
||||
if (trayColor == 0) {
|
||||
SetColor(ingredientColor);
|
||||
} else if (ingredientColor == 0) {
|
||||
pIngredient->SetColor(trayColor);
|
||||
} else {
|
||||
SetColor(4);
|
||||
}
|
||||
}
|
||||
|
||||
if (fillCount == (uint32_t)recipe.size()) {
|
||||
TWindow* pTop = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pTop != NULL) {
|
||||
pTop->SendWindowMessage(new TMessage(kFillTrayEvent, "", pTop));
|
||||
}
|
||||
if (color == 4 || color == 0) {
|
||||
sound = "ingredient_complete";
|
||||
} else {
|
||||
sound = "ingredient_complete_colormatch";
|
||||
}
|
||||
} else {
|
||||
if (color == 4) {
|
||||
sound = str::getFormatted("ingredient_success_%lu", (unsigned long)fillCount);
|
||||
} else {
|
||||
sound = str::getFormatted("ingredient_color_match_%lu", (unsigned long)fillCount);
|
||||
}
|
||||
}
|
||||
|
||||
if (color != 0 && color != 4) {
|
||||
if (fillCount == (uint32_t)recipe.size()) {
|
||||
TWindow* pTop2 = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pTop2 != NULL) {
|
||||
TWindow* pFactory = pTop2->GetChildWindow("FactoryGame", -1);
|
||||
if (pFactory != NULL) {
|
||||
TMessage* pStart = new FlyingRingStartMessage(GetRef(), color);
|
||||
pStart->mDestination = pFactory;
|
||||
pFactory->SendWindowMessage(pStart);
|
||||
pFactory->SendWindowMessage(new TMessage(kProduceProductEvent, "", pFactory));
|
||||
}
|
||||
}
|
||||
Clear(true);
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sound.length() != 0) {
|
||||
TWindowManager::GetInstance()->PostWindowMessage(new TMessage(kSoundEvent, sound, NULL));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
785
port/game/CoffeeFactory.cpp
Normal file
785
port/game/CoffeeFactory.cpp
Normal file
|
|
@ -0,0 +1,785 @@
|
|||
// Port of the game's CoffeeFactory.cpp (Chocolatier 3, Big Splash Games): CoffeeBonus, the "+N" text sprite that floats
|
||||
// up from the middle of a collected group of ingredients, and CoffeeFactory, the coffee-making minigame window. It
|
||||
// reads its tuning from the window style (times, conveyor / product / grid / gun paths and speeds, hood positions, the
|
||||
// match bonus table, the recipe), builds the sprite scene (ingredient conveyor, the hopper machine with its collection
|
||||
// task, the product box, the ingredient grid, the gun, the timer face with its hand) and runs the game from the
|
||||
// window's animation task: countdown, playing, ending and game-over states, the clock and the ticks of the five
|
||||
// scaling tasks and the bonus sprites. Messages from the tasks (missed ingredient, products, score, collected
|
||||
// ingredients) are handled in OnMessage.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// CoffeeFactory.h (port/game/CoffeeFactory.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): CoffeeBonus: pSprite 0x0 (TTextSpriteRef), startPos 0x8, time 0x14; sizeof 0x18 (the caller
|
||||
// allocates 0x18 bytes). CoffeeFactory: TWindow 0x0..0x30, TBSGWindow 0x30..0x50 (pFrame 0x30, fill 0x38, color 0x3c,
|
||||
// swallowMouse 0x4c); productName 0x50, productCode 0x54, recipe 0x58, state 0x64, pBaseSprite 0x68, pSoundHandler
|
||||
// 0x70, pConveyor 0x74, pConveyorTask 0x7c, pGunTask 0x80, pGun 0x84, speedUpFactor 0x8c, maxSpeed 0x90, pGridTask
|
||||
// 0x94, pGrid 0x98, pHopper 0xa0, pCollectionTask 0xa8, pProductTask 0xac, matchBonus 0xb0, bonusSprites 0xbc,
|
||||
// missCount 0xc4, missPosition 0xc8, missed 0xd4, gamePaused 0xe0, warnOnMiss 0xe1, countdownTime 0xe4, gameTime 0xe8,
|
||||
// warnTime 0xec, clock 0xf0, score 0xf4 (GetScore), bonusScore 0xf8, pTime 0xfc, pCountdown 0x100, pScore 0x104,
|
||||
// pTimer 0x108, pTimerHand 0x110, pScoreDisplay 0x118; sizeof 0x120 (CoffeeFactoryDynamicCreate allocates 0x120
|
||||
// bytes). The headers match.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Message ids: 0x3eb kMissedIngredientEvent, 0x3ec kManufactureProductEvent and 0x3ed kProduceProductEvent (both add
|
||||
// a product), 0x3ee kCountBonusProductEvent (falls through to) 0x3ef kCountProductEvent, 0x3f2
|
||||
// kCollectedIngredientEvent (chocothree.h, TMessage::kUserMessageBase = 1000). Unlike the chocolate factory there is
|
||||
// no kAppDeactivate, kFillTrayEvent or kColorMatchEvent case.
|
||||
// - Virtual calls on the task objects: slot 0 is Reset(float) (called with 1.0f), slot 1 Restart(uint32_t) (called
|
||||
// with 15), slot 3 Pause() of CoffeeGridTask (the other tasks call the non-virtual TScalingTask::Pause); the
|
||||
// TScalingTask scale is the float at +0xc. AnyFlying() / AnyProducts() are the std::list size() == 0 tests the game
|
||||
// inlines (flying list of the gun task at +0x38, products list of the product task at +0x60).
|
||||
// - GAME_COUNTDOWN is 1, GAME_PLAYING 2, GAME_ENDING 3, GAME_ABORTED 4, GAME_OVER 5 (header order).
|
||||
// - Window style defaults (double constants pushed by the game): countdowntime 3000, gametime 60000, warntime 8000,
|
||||
// conveyortime 1200, conveyorcount 5, colorcount 1, producttime 3000, productspacing 1000, speedup 1.1, maxspeed 8,
|
||||
// columns 9, rows 9, gridx 10, gridy 10, griddx 50, griddy 50, gridspeed 3000, gunspeed 250; matchBonus entries
|
||||
// default 0. The unsigned values are converted with the game's inline clamp (see ClampToUInt32).
|
||||
// - Init builds matchBonus as {0, table[1], table[2], ...} (the table is read by number key 1..GetSize()).
|
||||
// - Init reads the "autoFillGunPos" table into a local TVec2 that is never used; kept as is.
|
||||
// - The constructor does not initialise pCollectionTask / pProductTask (Init always sets them); kept as is.
|
||||
// - The machine sprite is "image/machine_2" when the recipe has three entries and "image/machine_5" otherwise.
|
||||
// - OnKeyDown reads the cheat-mode config value with TPlatform::GetConfig but never uses it; the dev menu is opened
|
||||
// whenever bit 0 of the key flags is set (the game's code, kept as is).
|
||||
// - TWindow offset +4 (read as the receiver of the "go" / "pause" / "information" child lookups) is mParent.
|
||||
// - CoffeeBonus::Tick: alpha (TDrawSpec::mAlpha, +0x5c of the sprite) = t * -0.8 + 1.0 with t = time / 2000.0f, the
|
||||
// position is startPos + (0, -150, 0) * t; the sprite is removed from its parent after 2000 ms.
|
||||
// - LoadAppearance and BuildItemAppearance (game @0x0001fcd2 / @0x0001fff4) are declared in the original
|
||||
// CustomItems.h and live in their own object file; they are declared here.
|
||||
// - Float constants: 0.5f (@0x001ab6ec), 1.0f (@0x001ab6e4), 0.0f (@0x001ab6e8), 2000.0f (@0x001ab704, CoffeeBonus
|
||||
// time scale); doubles pi (@0x001ab4a8), 0.5 (@0x001ab488), -0.8 (@0x001ab4e0), 1.0 (@0x001ab470); the sign mask
|
||||
// @0x001929f0 is the float negation. The unsigned -> double conversions are the usual SSE2 magic-number sequences.
|
||||
//
|
||||
// Strings from the game's __cstring: "CoffeeFactory", "cursor/cursor", "go", "pause", "information", "gPauseText",
|
||||
// "ui/game_pause.lua", "game_paused", "DoModal('dev/dev_menu.lua')", "recipe", "productName", "productCode",
|
||||
// "warnOnMiss", "matchBonus", "countdowntime", "gametime", "warntime", "conveyortime", "conveyorcount", "colorcount",
|
||||
// "conveyorpath", "producttime", "productspacing", "productpath", "appearance", "image/machine_2",
|
||||
// "image/machine_5", "image/box_open", "image/box_open_mask", "top_hood", "bottom_hood",
|
||||
// "image/conveyor_base_mask_lower", "image/conveyor_base_mask_upper", "speedup", "maxspeed", "columns", "rows",
|
||||
// "gridx", "gridy", "griddx", "griddy", "gridspeed", "gunspeed", "image/gun_base", "image/gun.xml", "missed",
|
||||
// "autoFillGunPos", "image/timer_face", "image/timer_hand", "coffee_making_game", "coffee_making_game_intro",
|
||||
// "coffee_making_game_outro", "game_over", "ui/chocolate_gameover.lua", "whistle", "clock_tick", "start_bell", "0:00",
|
||||
// "%lu:%02lu", "%d", "%lu", "0", "ingredient_failure_factory shutdown", "ingredient_failure_%lu",
|
||||
// "coffee_first_missed", "ingredient_match_0", "ingredient_match_%lu", "ingredient_match_5", "+%lu",
|
||||
// "fonts/fertigo.mvec", "time", "countdown", "score", "StartGame", "PauseGame", "ResumeGame", "GetScore".
|
||||
//
|
||||
// Compiler-generated or header-inline code emitted out of line:
|
||||
// - PFTYPEDEF_DC: IsKindOf game @0x00169fe0 (compares the id against &CoffeeFactoryDynamicCreate, else calls
|
||||
// TBSGWindow::IsKindOf), CoffeeFactoryDynamicCreate game @0x0001236e (new CoffeeFactory, sizeof 0x120), ClassId
|
||||
// game @0x00010c40, GetTypeName game @0x00010c4a; the CoffeeFactory vtable is at game @0x0021b968.
|
||||
// - CoffeeFactory::GetScore game @0x001699f0 (inline in CoffeeFactory.h; returns the field at +0xf4).
|
||||
// - lua_pushdirectclosure<CoffeeFactory, F> for F = void (str) game @0x00169a00, void () game @0x00169a4c,
|
||||
// uint32_t () game @0x00169a98; LPCD::DirectCallMemberDispatcherHelper<CoffeeFactory, F>::DirectCallMemberDispatcher
|
||||
// for F = void (str) game @0x00169bcc (ReturnSpecialization<void>::Call<CoffeeFactory, str> game @0x00169b54),
|
||||
// uint32_t () game @0x00169f54 (ReturnSpecialization<unsigned int>::Call<CoffeeFactory> game @0x00169c10), void ()
|
||||
// game @0x00169f98 (pf/luapluscd.h templates; the dispatchers the constructor registers as "StartGame",
|
||||
// "PauseGame", "ResumeGame" and "GetScore").
|
||||
// - The destructors delete the five tasks inline (IngredientQueueTask and CoffeeGridTask have implicit destructors,
|
||||
// inlined at the delete sites; CoffeeGunTask, CoffeeProductQueueTask and HopperCollectionTask call their
|
||||
// out-of-line D1). The std::list<shared_ptr<CoffeeBonus>>, std::vector and boost::shared_ptr<CoffeeBonus>
|
||||
// instantiations are library code and not ported. The game also lists undecodable exception-handling clones (.eh)
|
||||
// of the constructor and destructors; they are not source functions.
|
||||
//
|
||||
// Static data: CoffeeFactory::pInstance (__ZN13CoffeeFactory9pInstanceE, NULL).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "CoffeeFactory.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGSound.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/modalwindow.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/text.h"
|
||||
#include "pf/textsprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
// CustomItems.h (original, no port header yet): game @0x0001fcd2 / @0x0001fff4.
|
||||
void LoadAppearance(TLuaTable& productTable, vector<str>& appearance, vector<TColor>& tints);
|
||||
void BuildItemAppearance(TSpriteRef pBase, vector<str> const& appearance, vector<TColor> const& tints, TReal scale);
|
||||
|
||||
// The game's inline double -> uint32_t conversion (see the notes above).
|
||||
static uint32_t ClampToUInt32(double value)
|
||||
{
|
||||
double clamped = value;
|
||||
if (4294967295.0 <= value) {
|
||||
clamped = 4294967295.0;
|
||||
}
|
||||
if (clamped <= 0.0) {
|
||||
clamped = 0.0;
|
||||
}
|
||||
double bias = (2147483648.0 <= value) ? 2147483648.0 : 0.0;
|
||||
return (uint32_t)(int32_t)(clamped - bias) ^ ((2147483648.0 <= value) ? 0x80000000u : 0u);
|
||||
}
|
||||
|
||||
// game @0x00011576
|
||||
CoffeeBonus::CoffeeBonus(list<IngredientRef>& collection, uint32_t bonusCount)
|
||||
{
|
||||
time = 0;
|
||||
TVec3 position;
|
||||
for (list<IngredientRef>::iterator it = collection.begin(); it != collection.end(); ++it) {
|
||||
TVec3 sum = position + (*it)->GetPosition();
|
||||
position = sum;
|
||||
}
|
||||
position.x = position.x / (float)collection.size();
|
||||
position.y = position.y / (float)collection.size();
|
||||
position.z = 1.0f;
|
||||
startPos = position;
|
||||
TSprite* pParent = collection.front()->GetParent();
|
||||
pSprite = TTextSprite::Create(0x78, 0x78, 5, "fonts/fertigo.mvec", 0x50, TColor(1.0f, 1.0f, 1.0f, 1.0f), 0x3e7);
|
||||
pSprite->SetText(str::getFormatted("+%lu", (unsigned long)bonusCount));
|
||||
pSprite->GetDrawSpec().mMatrix[2] = position;
|
||||
pParent->AddChild(TSpriteRef(pSprite));
|
||||
}
|
||||
|
||||
// game @0x00011442
|
||||
bool CoffeeBonus::Tick(uint32_t elapsed)
|
||||
{
|
||||
float t = (float)time / 2000.0f;
|
||||
TVec3 offset = TVec3(0.0f, -150.0f, 0.0f) * t;
|
||||
TVec3 position = startPos + offset;
|
||||
pSprite->GetDrawSpec().mMatrix[2] = position;
|
||||
pSprite->GetDrawSpec().mAlpha = (float)((double)t * -0.8 + 1.0);
|
||||
uint32_t oldTime = time;
|
||||
time = elapsed + oldTime;
|
||||
if (elapsed + oldTime < 2000) {
|
||||
return true;
|
||||
}
|
||||
pSprite->GetParent()->RemoveChild(TSpriteRef(pSprite));
|
||||
return false;
|
||||
}
|
||||
|
||||
CoffeeFactory* CoffeeFactory::pInstance = NULL;
|
||||
|
||||
// game @0x00010c40 (ClassId), @0x00010c4a (GetTypeName), @0x0001236e (CoffeeFactoryDynamicCreate)
|
||||
PFTYPEIMPL_DC(CoffeeFactory);
|
||||
|
||||
// game @0x00011e3a
|
||||
CoffeeFactory::CoffeeFactory(void)
|
||||
{
|
||||
pSoundHandler = NULL;
|
||||
pConveyorTask = NULL;
|
||||
pGunTask = NULL;
|
||||
pGridTask = NULL;
|
||||
warnOnMiss = false;
|
||||
gamePaused = false;
|
||||
pTime = NULL;
|
||||
pCountdown = NULL;
|
||||
pScore = NULL;
|
||||
pInstance = this;
|
||||
fill = false;
|
||||
pBaseSprite = TSprite::Create(0, TTextureRef());
|
||||
pSoundHandler = new TSoundHandler();
|
||||
state = GAME_INIT;
|
||||
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "StartGame", this, CoffeeFactory::StartGame);
|
||||
ScriptRegisterMemberDirect(script, "PauseGame", this, CoffeeFactory::PauseGame);
|
||||
ScriptRegisterMemberDirect(script, "ResumeGame", this, CoffeeFactory::ResumeGame);
|
||||
ScriptRegisterMemberDirect(script, "GetScore", this, CoffeeFactory::GetScore);
|
||||
}
|
||||
|
||||
// game @0x000117d2 (D0, deleting), game @0x00011b0a (D1, complete)
|
||||
CoffeeFactory::~CoffeeFactory(void)
|
||||
{
|
||||
pInstance = NULL;
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(false);
|
||||
if (TWindowManager::GetInstance()->OrphanMessageListener(pSoundHandler)) {
|
||||
delete pSoundHandler;
|
||||
}
|
||||
delete pConveyorTask;
|
||||
delete pGunTask;
|
||||
delete pProductTask;
|
||||
delete pCollectionTask;
|
||||
delete pGridTask;
|
||||
}
|
||||
|
||||
// game @0x000113e8
|
||||
void CoffeeFactory::ToggleForeground(void)
|
||||
{
|
||||
if (pInstance != NULL) {
|
||||
pInstance->PauseGame("game_paused");
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00010e38
|
||||
void CoffeeFactory::ParseRecipe(TWindowStyle& style)
|
||||
{
|
||||
recipe.clear();
|
||||
productName = style.GetString("productName", "");
|
||||
productCode = style.GetString("productCode", "");
|
||||
TLuaTable* pRecipe = style.GetTable("recipe");
|
||||
if (pRecipe != NULL) {
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaObjectWrapper* pItem;
|
||||
while ((pItem = pRecipe->GetNext(&key)) != NULL) {
|
||||
recipe.push_back(pItem->AsString());
|
||||
delete pItem;
|
||||
}
|
||||
delete pRecipe;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000123aa
|
||||
void CoffeeFactory::Init(TWindowStyle& style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
RandSeed(TPlatform::GetInstance()->Timer());
|
||||
FindParentModal()->SetDefaultFocus(this);
|
||||
|
||||
warnOnMiss = style.GetBool("warnOnMiss", false);
|
||||
|
||||
// Match bonuses: entry 0 is zero, entries 1.. come from the "matchBonus" table
|
||||
TLuaTable* pMatchBonus = style.GetTable("matchBonus");
|
||||
if (pMatchBonus != NULL) {
|
||||
matchBonus.push_back(0);
|
||||
uint32_t index = 0;
|
||||
while (index < pMatchBonus->GetSize()) {
|
||||
index = index + 1;
|
||||
matchBonus.push_back(ClampToUInt32(pMatchBonus->GetNumber((double)index, 0.0)));
|
||||
}
|
||||
delete pMatchBonus;
|
||||
}
|
||||
|
||||
countdownTime = ClampToUInt32(style.GetNumber("countdowntime", 3000));
|
||||
gameTime = ClampToUInt32(style.GetNumber("gametime", 60000));
|
||||
warnTime = ClampToUInt32(style.GetNumber("warntime", 8000));
|
||||
|
||||
ParseRecipe(style);
|
||||
|
||||
// Ingredient conveyor
|
||||
TCurveRef pConveyorCurve;
|
||||
float conveyorTime = (float)style.GetNumber("conveyortime", 1200);
|
||||
uint32_t conveyorCount = ClampToUInt32(style.GetNumber("conveyorcount", 5));
|
||||
uint8_t colorCount = (uint8_t)(int)style.GetNumber("colorcount", 1);
|
||||
TLuaTable* pConveyorPath = style.GetTable("conveyorpath");
|
||||
if (pConveyorPath != NULL) {
|
||||
pConveyorCurve = TCurve::Create(*pConveyorPath);
|
||||
delete pConveyorPath;
|
||||
}
|
||||
pConveyor = ::shared_ptr<IngredientQueue>(new IngredientQueue(recipe, colorCount, pConveyorCurve, conveyorCount, pBaseSprite));
|
||||
pConveyorTask = new IngredientQueueTask(pConveyor, conveyorTime);
|
||||
|
||||
// Products
|
||||
TCurveRef pProductCurve;
|
||||
float productTime = (float)style.GetNumber("producttime", 3000);
|
||||
float productSpacing = (float)style.GetNumber("productspacing", 1000);
|
||||
TLuaTable* pProductPath = style.GetTable("productpath");
|
||||
if (pProductPath != NULL) {
|
||||
pProductCurve = TCurve::Create(*pProductPath);
|
||||
delete pProductPath;
|
||||
}
|
||||
vector<str> appearance;
|
||||
vector<TColor> tints;
|
||||
TLuaTable* pAppearance = style.GetTable("appearance");
|
||||
if (pAppearance != NULL) {
|
||||
LoadAppearance(*pAppearance, appearance, tints);
|
||||
delete pAppearance;
|
||||
}
|
||||
|
||||
// Hopper (machine) and its collection task
|
||||
str machineName((recipe.size() == 3) ? "image/machine_2" : "image/machine_5");
|
||||
pHopper = CoffeeHopper::Create(TVec2(695.0f, 301.0f), recipe, machineName);
|
||||
pBaseSprite->AddChild(pHopper);
|
||||
pCollectionTask = new HopperCollectionTask(pHopper);
|
||||
pProductTask = new CoffeeProductQueueTask(pBaseSprite, pHopper, pProductCurve, productTime, productSpacing, appearance, tints);
|
||||
|
||||
// Product box
|
||||
TSpriteRef pBox = TSprite::Create(1, TTexture::Get("image/box_open", 0));
|
||||
pBox->GetDrawSpec().mMatrix[2] = TVec3(pProductCurve->GetEndPoint(), 1.0f);
|
||||
pBaseSprite->AddChild(pBox);
|
||||
pBox = TSprite::Create(3, TTexture::Get("image/box_open_mask", 0));
|
||||
pBox->GetDrawSpec().mMatrix[2] = TVec3(pProductCurve->GetEndPoint(), 1.0f);
|
||||
pBaseSprite->AddChild(pBox);
|
||||
TSpriteRef pBoxContents = TSprite::Create(0, TTextureRef());
|
||||
BuildItemAppearance(pBoxContents, appearance, tints, 0.5f);
|
||||
pBoxContents->GetDrawSpec().mMatrix[2] = TVec3(0.0f, 9.0f, 1.0f);
|
||||
pBox->AddChild(pBoxContents);
|
||||
|
||||
// Conveyor hoods
|
||||
TVec2 topHood;
|
||||
TVec2 bottomHood;
|
||||
TLuaTable* pTopHood = style.GetTable("top_hood");
|
||||
if (pTopHood != NULL) {
|
||||
topHood = GetPoint(pTopHood);
|
||||
delete pTopHood;
|
||||
}
|
||||
TLuaTable* pBottomHood = style.GetTable("bottom_hood");
|
||||
if (pBottomHood != NULL) {
|
||||
bottomHood = GetPoint(pBottomHood);
|
||||
delete pBottomHood;
|
||||
}
|
||||
TSpriteRef pMask = TSprite::Create(7, TTexture::Get("image/conveyor_base_mask_lower", 0));
|
||||
pMask->GetDrawSpec().mMatrix[2] = TVec3(bottomHood, 1.0f);
|
||||
pBaseSprite->AddChild(pMask);
|
||||
pMask = TSprite::Create(7, TTexture::Get("image/conveyor_base_mask_upper", 0));
|
||||
pMask->GetDrawSpec().mMatrix[2] = TVec3(topHood, 1.0f);
|
||||
pBaseSprite->AddChild(pMask);
|
||||
|
||||
// Grid
|
||||
speedUpFactor = (float)style.GetNumber("speedup", 1.1);
|
||||
maxSpeed = (float)style.GetNumber("maxspeed", 8);
|
||||
uint32_t gridColumns = ClampToUInt32(style.GetNumber("columns", 9));
|
||||
uint32_t gridRows = ClampToUInt32(style.GetNumber("rows", 9));
|
||||
float gridX = (float)style.GetNumber("gridx", 10);
|
||||
float gridY = (float)style.GetNumber("gridy", 10);
|
||||
float gridDX = (float)style.GetNumber("griddx", 50);
|
||||
float gridDY = (float)style.GetNumber("griddy", 50);
|
||||
pGrid = CoffeeIngredientGrid::Create(recipe, gridX, gridY, gridColumns, gridRows, gridDX, gridDY);
|
||||
pBaseSprite->AddChild(pGrid);
|
||||
float gridSpeed = (float)style.GetNumber("gridspeed", 3000);
|
||||
pGridTask = new CoffeeGridTask(pGrid, gridSpeed);
|
||||
|
||||
// Ingredient gun
|
||||
TVec2 gunPosition;
|
||||
float gunSpeed = (float)style.GetNumber("gunspeed", 250);
|
||||
if (pConveyorCurve) {
|
||||
gunPosition = pConveyorCurve->GetEndPoint();
|
||||
}
|
||||
TSpriteRef pGunBase = TSprite::Create(0, TTexture::Get("image/gun_base", 0));
|
||||
pGunBase->GetDrawSpec().mMatrix[2] = TVec3(gunPosition, 1.0f);
|
||||
pBaseSprite->AddChild(pGunBase);
|
||||
|
||||
pGun = TAnimatedSprite::Create(10);
|
||||
pGun->SetTexture(TAnimatedTexture::Get("image/gun.xml", "", ""));
|
||||
pGun->SetCurrentFrame(0);
|
||||
pGun->GetDrawSpec().mMatrix[2] = TVec3(gunPosition, 1.0f);
|
||||
pBaseSprite->AddChild(pGun);
|
||||
pGunTask = new CoffeeGunTask(pGun, gunSpeed, pConveyor, pGrid);
|
||||
|
||||
// Missed ingredients
|
||||
TLuaTable* pMissed = style.GetTable("missed");
|
||||
if (pMissed != NULL) {
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaObjectWrapper* pEntry;
|
||||
while ((pEntry = pMissed->GetNext(&key)) != NULL) {
|
||||
if (pEntry->IsTable()) {
|
||||
missPosition.push_back(GetPoint(static_cast<TLuaTable*>(pEntry)));
|
||||
}
|
||||
delete pEntry;
|
||||
}
|
||||
delete pMissed;
|
||||
}
|
||||
|
||||
// "autoFillGunPos" is read but never used
|
||||
TVec2 autoFillGunPos;
|
||||
TLuaTable* pAutoFillGunPos = style.GetTable("autoFillGunPos");
|
||||
if (pAutoFillGunPos != NULL) {
|
||||
autoFillGunPos = GetPoint(pAutoFillGunPos);
|
||||
delete pAutoFillGunPos;
|
||||
}
|
||||
|
||||
// Timer
|
||||
pTimer = TSprite::Create(0, TTexture::Get("image/timer_face", 0));
|
||||
pBaseSprite->AddChild(pTimer);
|
||||
pTimerHand = TSprite::Create(0, TTexture::Get("image/timer_hand", 0));
|
||||
pTimer->AddChild(pTimerHand);
|
||||
|
||||
PauseGame("game_paused");
|
||||
}
|
||||
|
||||
// game @0x00015c10
|
||||
void CoffeeFactory::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TBSGWindow::PostChildrenInit(style);
|
||||
pTime = GetChildWindowCast<TText>("time", -1);
|
||||
pCountdown = GetChildWindowCast<TText>("countdown", -1);
|
||||
pScore = GetChildWindowCast<TText>("score", -1);
|
||||
TVec2 timerPosition(720.0f, 80.0f);
|
||||
if (pScore != NULL) {
|
||||
TPoint at = pScore->GetWindowPos();
|
||||
ClientToScreen(&at);
|
||||
timerPosition.x = (float)((double)at.x + (double)pScore->GetWindowWidth() * 0.5);
|
||||
timerPosition.y = (float)((double)at.y + 0.5 * (double)pScore->GetWindowHeight());
|
||||
}
|
||||
pTimer->GetDrawSpec().mMatrix[2] = TVec3(timerPosition, 1.0f);
|
||||
SetAlpha(1.0f, true);
|
||||
ResetGame();
|
||||
}
|
||||
|
||||
// game @0x000158ea
|
||||
void CoffeeFactory::ResetGame(void)
|
||||
{
|
||||
clock = gameTime + countdownTime;
|
||||
score = 0;
|
||||
bonusScore = 0;
|
||||
missCount = 0;
|
||||
state = GAME_COUNTDOWN;
|
||||
pGrid->Reset();
|
||||
pConveyorTask->Reset(1.0f);
|
||||
pGunTask->Reset(1.0f);
|
||||
pProductTask->Reset(1.0f);
|
||||
pCollectionTask->Reset(1.0f);
|
||||
pGridTask->Reset(1.0f);
|
||||
PauseGame("game_paused");
|
||||
for (vector<TSpriteRef>::iterator it = missed.begin(); it != missed.end(); ++it) {
|
||||
pBaseSprite->RemoveChild(*it);
|
||||
}
|
||||
missed.clear();
|
||||
if (pScore != NULL) {
|
||||
pScore->SetText("0");
|
||||
}
|
||||
if (pTime != NULL) {
|
||||
pTime->SetText("");
|
||||
}
|
||||
BSGSoundEvent("coffee_making_game_intro");
|
||||
BSGHideWindow(GetParent()->GetChildWindow("go", -1));
|
||||
BSGHideWindow(GetParent()->GetChildWindow("pause", -1));
|
||||
}
|
||||
|
||||
// game @0x00015bb8
|
||||
void CoffeeFactory::StartGame(void)
|
||||
{
|
||||
ResetGame();
|
||||
StartWindowAnimation(10, true, false, true);
|
||||
SetGameState(GAME_COUNTDOWN);
|
||||
ResumeGame();
|
||||
}
|
||||
|
||||
// game @0x00014c88
|
||||
void CoffeeFactory::ResumeGame(void)
|
||||
{
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/cursor"), TPoint(0x10, 0x10), false);
|
||||
if (gamePaused) {
|
||||
BSGSoundUnpause();
|
||||
BSGHideWindow(GetParent()->GetChildWindow("go", -1));
|
||||
BSGShowWindow(GetParent()->GetChildWindow("pause", -1));
|
||||
TWindow* pInformation = GetParent()->GetChildWindow("information", -1);
|
||||
if (pInformation != NULL) {
|
||||
BSGHideWindow(pInformation);
|
||||
}
|
||||
pConveyorTask->Restart(15);
|
||||
pGunTask->Restart(15);
|
||||
pProductTask->Restart(15);
|
||||
pCollectionTask->Restart(15);
|
||||
pGridTask->Restart(15);
|
||||
StartWindowAnimation(10, true, false, true);
|
||||
SetGameState(state);
|
||||
gamePaused = false;
|
||||
}
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(true);
|
||||
}
|
||||
|
||||
// game @0x00011018
|
||||
void CoffeeFactory::PauseGame(str textKey)
|
||||
{
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/cursor"), TPoint(1, 1), false);
|
||||
if (!gamePaused) {
|
||||
if (state != GAME_INIT) {
|
||||
BSGSoundPause();
|
||||
}
|
||||
BSGShowWindow(GetParent()->GetChildWindow("go", -1));
|
||||
BSGHideWindow(GetParent()->GetChildWindow("pause", -1));
|
||||
gamePaused = true;
|
||||
pConveyorTask->Pause();
|
||||
pGunTask->Pause();
|
||||
pProductTask->Pause();
|
||||
pCollectionTask->Pause();
|
||||
pGridTask->Pause();
|
||||
StopWindowAnimation();
|
||||
TWindow* pInformation = GetParent()->GetChildWindow("information", -1);
|
||||
if (pInformation != NULL) {
|
||||
TWindowManager::GetInstance()->GetScript()->SetGlobalString("gPauseText", textKey);
|
||||
FillWindowPtr(pInformation, "ui/game_pause.lua");
|
||||
BSGShowWindow(pInformation);
|
||||
}
|
||||
}
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(false);
|
||||
}
|
||||
|
||||
// game @0x0001479e
|
||||
void CoffeeFactory::SetGameState(GameState newState)
|
||||
{
|
||||
if (newState == GAME_COUNTDOWN) {
|
||||
pConveyorTask->Pause();
|
||||
pGunTask->Pause();
|
||||
pProductTask->Pause();
|
||||
pCollectionTask->Pause();
|
||||
}
|
||||
else if (newState == GAME_PLAYING) {
|
||||
BSGSoundEvent("coffee_making_game");
|
||||
pConveyorTask->Restart(15);
|
||||
pGunTask->Restart(15);
|
||||
pProductTask->Restart(15);
|
||||
pCollectionTask->Restart(15);
|
||||
pGridTask->Reset(1.0f);
|
||||
pGridTask->Restart(15);
|
||||
state = newState;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (newState == GAME_ENDING) {
|
||||
pConveyorTask->Pause();
|
||||
pConveyorTask->Reset(1.0f);
|
||||
BSGSoundEvent("coffee_making_game_outro");
|
||||
BSGSoundEvent("game_over");
|
||||
}
|
||||
else if (newState != GAME_ABORTED) {
|
||||
if (newState == GAME_OVER) {
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/cursor"), TPoint(1, 1), false);
|
||||
TWindowManager::GetInstance()->SetTopModalOnly(false);
|
||||
pConveyorTask->Pause();
|
||||
pConveyorTask->Reset(1.0f);
|
||||
pCollectionTask->Pause();
|
||||
pCollectionTask->Reset(1.0f);
|
||||
pGunTask->Pause();
|
||||
pProductTask->Pause();
|
||||
pGridTask->Pause();
|
||||
StopWindowAnimation();
|
||||
TWindow* pInformation = GetParent()->GetChildWindow("information", -1);
|
||||
if (pInformation != NULL) {
|
||||
FillWindowPtr(pInformation, "ui/chocolate_gameover.lua");
|
||||
BSGShowWindow(pInformation);
|
||||
BSGHideWindow(GetParent()->GetChildWindow("go", -1));
|
||||
BSGHideWindow(GetParent()->GetChildWindow("pause", -1));
|
||||
}
|
||||
}
|
||||
state = newState;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/cursor"), TPoint(1, 1), false);
|
||||
BSGSoundEvent("coffee_making_game_outro");
|
||||
BSGSoundEvent("game_over");
|
||||
pConveyorTask->Pause();
|
||||
pConveyorTask->Reset(1.0f);
|
||||
}
|
||||
}
|
||||
pGridTask->Pause();
|
||||
state = newState;
|
||||
}
|
||||
|
||||
// game @0x00014ec8
|
||||
void CoffeeFactory::MissedIngredient(IngredientRef pIngredient)
|
||||
{
|
||||
missed.push_back(pIngredient);
|
||||
if (missCount < missPosition.size()) {
|
||||
pIngredient->GetDrawSpec().mMatrix.Identity();
|
||||
pIngredient->GetDrawSpec().mMatrix.Scale(0.6f, 0.6f);
|
||||
pIngredient->GetDrawSpec().mMatrix[2] = TVec3(missPosition[missCount], 1.0f);
|
||||
}
|
||||
missCount++;
|
||||
if (missCount == missPosition.size()) {
|
||||
SetGameState(GAME_ABORTED);
|
||||
BSGSoundEvent("ingredient_failure_factory shutdown");
|
||||
}
|
||||
else {
|
||||
pGridTask->SetScale(0.5f * pGridTask->GetScale());
|
||||
if (pGridTask->GetScale() < 1.0f) {
|
||||
pGridTask->SetScale(1.0f);
|
||||
}
|
||||
str sound = str::getFormatted("ingredient_failure_%lu", (unsigned long)missCount);
|
||||
BSGSoundEvent(sound);
|
||||
if (warnOnMiss && missCount == 1) {
|
||||
PauseGame("coffee_first_missed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000150ec
|
||||
bool CoffeeFactory::OnMessage(TMessage* pMessage)
|
||||
{
|
||||
switch (pMessage->mType) {
|
||||
case kMissedIngredientEvent:
|
||||
MissedIngredient(static_cast<MissedIngredientMessage*>(pMessage)->pIngredient);
|
||||
return true;
|
||||
case kManufactureProductEvent:
|
||||
case kProduceProductEvent:
|
||||
pProductTask->AddProduct(pBaseSprite);
|
||||
return true;
|
||||
case kCountBonusProductEvent:
|
||||
bonusScore++;
|
||||
// fall through
|
||||
case kCountProductEvent:
|
||||
score++;
|
||||
if (pScore == NULL) {
|
||||
return true;
|
||||
}
|
||||
pScore->SetText(str::getFormatted("%lu", (unsigned long)score));
|
||||
return true;
|
||||
case kCollectedIngredientEvent: {
|
||||
list<IngredientRef>& collect = static_cast<CollectedIngredientMessage*>(pMessage)->collect;
|
||||
uint32_t count = (uint32_t)collect.size();
|
||||
pGridTask->SetScale(speedUpFactor * pGridTask->GetScale());
|
||||
if (maxSpeed < pGridTask->GetScale()) {
|
||||
pGridTask->SetScale(maxSpeed);
|
||||
}
|
||||
str sound("ingredient_match_0");
|
||||
uint32_t bonus;
|
||||
if (count < matchBonus.size()) {
|
||||
bonus = matchBonus[count];
|
||||
}
|
||||
else {
|
||||
bonus = matchBonus.back();
|
||||
}
|
||||
if (bonus != 0) {
|
||||
bonusScore = bonus + bonusScore;
|
||||
score = bonus + score;
|
||||
if (pScore != NULL) {
|
||||
pScore->SetText(str::getFormatted("%lu", (unsigned long)score));
|
||||
}
|
||||
if (bonus < 6) {
|
||||
sound = str::getFormatted("ingredient_match_%lu", (unsigned long)bonus);
|
||||
}
|
||||
else {
|
||||
sound = "ingredient_match_5";
|
||||
}
|
||||
CoffeeBonusRef pBonus(new CoffeeBonus(collect, bonus));
|
||||
bonusSprites.push_back(pBonus);
|
||||
}
|
||||
BSGSoundEvent(sound);
|
||||
pCollectionTask->Add(collect);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000112a6
|
||||
bool CoffeeFactory::OnKeyDown(char key, uint32_t flags)
|
||||
{
|
||||
if (key == TEvent::kEscape) {
|
||||
if (!gamePaused) {
|
||||
PauseGame("game_paused");
|
||||
}
|
||||
str cheatMode = TPlatform::GetConfig(str(TPlatform::kCheatMode), "");
|
||||
if ((flags & 1) != 0) {
|
||||
TWindowManager::GetInstance()->DoLuaString(this, "DoModal('dev/dev_menu.lua')");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00010c54
|
||||
bool CoffeeFactory::OnMouseDown(TPoint const& point)
|
||||
{
|
||||
if (state == GAME_PLAYING) {
|
||||
pGunTask->Fire(point);
|
||||
}
|
||||
return swallowMouse;
|
||||
}
|
||||
|
||||
// game @0x00010d26
|
||||
bool CoffeeFactory::OnMouseMove(TPoint const& point)
|
||||
{
|
||||
TVec3 gunPosition(pGun->GetDrawSpec().mMatrix[2]);
|
||||
TVec2 direction;
|
||||
direction.x = (float)point.x - gunPosition.x;
|
||||
direction.y = (float)point.y - gunPosition.y;
|
||||
direction.Normalize();
|
||||
float targetX;
|
||||
float targetY;
|
||||
if (state == GAME_PLAYING) {
|
||||
targetY = (float)point.y;
|
||||
targetX = (float)point.x;
|
||||
}
|
||||
else {
|
||||
targetY = -1.0f;
|
||||
targetX = -1.0f;
|
||||
}
|
||||
pGrid->SetTargetPosition(targetX, targetY);
|
||||
float angle = acosf(direction.y);
|
||||
if (0.0f < direction.x) {
|
||||
angle = -angle;
|
||||
}
|
||||
TMat3 rotation = TMat3::GetRotation((float)((double)angle + 3.141592653589793));
|
||||
rotation[2] = gunPosition;
|
||||
pGun->GetDrawSpec().mMatrix = rotation;
|
||||
return swallowMouse;
|
||||
}
|
||||
|
||||
// game @0x00015434
|
||||
bool CoffeeFactory::OnTaskAnimate(void)
|
||||
{
|
||||
if (!TPlatform::GetInstance()->IsForeground()) {
|
||||
PauseGame("game_paused");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (state == GAME_ABORTED || (state == GAME_ENDING && !pGunTask->AnyFlying() && !pProductTask->AnyProducts())) {
|
||||
SetGameState(GAME_OVER);
|
||||
}
|
||||
|
||||
uint32_t oldClock = clock;
|
||||
if (state == GAME_COUNTDOWN) {
|
||||
if (gameTime + 10U < oldClock) {
|
||||
clock = oldClock - 10;
|
||||
if (oldClock / 1000 > (oldClock - 10) / 1000) {
|
||||
BSGSoundEvent("clock_tick");
|
||||
if (pCountdown != NULL) {
|
||||
pCountdown->SetText(str::getFormatted("%d", (int)(((clock - gameTime) + 999U) / 1000)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
clock = oldClock - 10;
|
||||
BSGSoundEvent("start_bell");
|
||||
SetGameState(GAME_PLAYING);
|
||||
if (pCountdown != NULL) {
|
||||
pCountdown->SetText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (state == GAME_PLAYING) {
|
||||
if (oldClock < 0xb) {
|
||||
if (pTimerHand) {
|
||||
pTimerHand->GetDrawSpec().mMatrix.Identity();
|
||||
}
|
||||
if (pTime != NULL) {
|
||||
pTime->SetText("0:00");
|
||||
}
|
||||
SetGameState(GAME_ENDING);
|
||||
}
|
||||
else {
|
||||
clock = oldClock - 10;
|
||||
if (warnTime < oldClock && oldClock - 10 <= warnTime) {
|
||||
BSGSoundEvent("whistle");
|
||||
}
|
||||
if (pTime != NULL) {
|
||||
uint32_t seconds = (clock + 999U) / 1000;
|
||||
pTime->SetText(str::getFormatted("%lu:%02lu", (unsigned long)(seconds / 0x3c), (unsigned long)(seconds % 0x3c)));
|
||||
}
|
||||
if (pTimerHand) {
|
||||
float turn = (float)((double)((float)clock / (float)gameTime + (float)clock / (float)gameTime) * 3.141592653589793);
|
||||
pTimerHand->GetDrawSpec().mMatrix = TMat3::GetRotation(-turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pConveyorTask->Tick(10);
|
||||
pGunTask->Tick(10);
|
||||
pProductTask->Tick(10);
|
||||
pCollectionTask->Tick(10);
|
||||
pGridTask->Tick(10);
|
||||
|
||||
list<CoffeeBonusRef>::iterator it = bonusSprites.begin();
|
||||
while (it != bonusSprites.end()) {
|
||||
list<CoffeeBonusRef>::iterator current = it;
|
||||
++it;
|
||||
if (!(*current)->Tick(10)) {
|
||||
bonusSprites.erase(current);
|
||||
}
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00010c84
|
||||
void CoffeeFactory::Draw(void)
|
||||
{
|
||||
TBSGWindow::Draw();
|
||||
TBegin2d begin2d;
|
||||
if (pBaseSprite) {
|
||||
pBaseSprite->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
}
|
||||
begin2d.Done();
|
||||
}
|
||||
443
port/game/CoffeeGrid.cpp
Normal file
443
port/game/CoffeeGrid.cpp
Normal file
|
|
@ -0,0 +1,443 @@
|
|||
// Port of the game's CoffeeGrid.cpp (Chocolatier 3, Big Splash Games): the coffee factory's ingredient grid on the
|
||||
// conveyor belt. CoffeeIngredientGrid is the sprite holding the grid of CoffeeIngredientSlot (a slot = available flag,
|
||||
// the ingredient type string and the ingredient sprite), the two belt seam sprites that scroll with it, and the target
|
||||
// marker (highlight sprite + the picture of the ingredient being aimed). CoffeeGridTask is the scaling task that
|
||||
// scrolls the belt and calls ShiftRows each time the belt wraps.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// CoffeeGrid.h (port/game/CoffeeGrid.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): CoffeeGridTask: TScalingTask 0x0..0x1c, pGrid 0x1c, gridTime 0x24, oldT 0x28 (not set by the
|
||||
// constructor), rootPosition 0x2c (TVec3). CoffeeIngredientSlot: available 0x0, contents 0x4, pIngredient 0x8; sizeof
|
||||
// 0x10. CoffeeIngredientGrid: TSprite 0x0..0x80, pSeam1 0x80, pSeam2 0x88, pTarget 0x90, pTargetImage 0x98, recipe
|
||||
// (std::vector<str>, copied by the constructor) 0xa0, dx 0xac, dy 0xb0, columns 0xb4, rows 0xb8, slots 0xbc,
|
||||
// fillCount 0xc8; sizeof 0xcc (Create allocates 0xcc bytes). The headers match.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 0.5f (@0x001ab6ec, the slot centre factor), double 0.5 (@0x001ab488, the
|
||||
// half texture width of the seam sprites); 1.0f (the z of every TVec3 built from a TVec2) is an immediate.
|
||||
// - Strings from the game's __cstring: "Stop_conveyor_belt_loop", "conveyor_belt_loop" (BSGSoundEvent keys),
|
||||
// "image/conveyor_belt_wide_seam" (used when columns == 8), "image/conveyor_belt_narrow_seam",
|
||||
// "image/conveyor_belt_gridtarget", "cursor/cursor", "cursor/blank_cursor", "FactoryGame" (the factory child window).
|
||||
// - The sprite position is TSprite::mDrawSpec.mMatrix[2] (sprite +0x38); the sprite's alpha at +0x5c is 0.5f for the
|
||||
// target image.
|
||||
// - Layers: the slot placeholder sprites 1, the seams 0, the target 0, the target image -1; ingredients are put on
|
||||
// layer 5 by AddIngredient and on layer 7 by RemoveIngredient. Texture virtual slot 0x24 in the constructor is
|
||||
// TTexture::GetWidth (declaration order of TTexture).
|
||||
// - The constructor lays the slot placeholder sprites out before the grid's own position is set (x/y are stored into
|
||||
// mMatrix[2] afterwards), so GetSlotPosition inside that loop still sees the default position.
|
||||
// - ShiftRows swaps (via a temporary slot copy) every row except the last with the last row, then walks only the
|
||||
// first row: a non empty slot's ingredient is removed from its parent without a null test of the parent, then each
|
||||
// first-row slot gets a random recipe entry (RandRange(0, 2 * recipe.size()); an index past the recipe leaves the
|
||||
// slot as is). It finally moves both seam sprites down by one row height, wrapping by the grid height.
|
||||
// - ClearGrid is the flood fill over equal contents (left, up, remove, right, down); ClearFrom sends the collected
|
||||
// list to the "FactoryGame" child window of the top modal window (the message is leaked when the window is not
|
||||
// found, as in the game).
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in CoffeeGrid.h):
|
||||
// CoffeeIngredientSlot: constructor (inline in CoffeeGrid.h) game @0x0016b79c, copy constructor game @0x0016b188,
|
||||
// operator= game @0x0016a9fc, ~CoffeeIngredientSlot game @0x0016acc0.
|
||||
// ~CoffeeIngredientGrid (implicit): D1 game @0x0016af38, D0 game @0x0016ae20 (slots, recipe, the four sprite
|
||||
// releases, then ~TSprite).
|
||||
// std::vector<CoffeeIngredientSlot> instantiations, boost::shared_ptr<CoffeeIngredientGrid> template code and the
|
||||
// __gnu_cxx / std helpers are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "CoffeeGrid.h"
|
||||
#include "BSGSound.h"
|
||||
#include "BSGHelpers.h"
|
||||
|
||||
#include "pf/platform.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/window.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x00015e34 (a 5-byte tail call: CoffeeGridTask::Reset only calls TScalingTask::Reset; no Ghidra export row)
|
||||
void CoffeeGridTask::Reset(TReal newScale)
|
||||
{
|
||||
TScalingTask::Reset(newScale);
|
||||
}
|
||||
|
||||
// game @0x00015e3e
|
||||
void CoffeeGridTask::Pause(void)
|
||||
{
|
||||
BSGSoundEvent("Stop_conveyor_belt_loop");
|
||||
TScalingTask::Pause();
|
||||
}
|
||||
|
||||
// game @0x00015e90
|
||||
void CoffeeGridTask::Restart(uint32_t delay)
|
||||
{
|
||||
BSGSoundEvent("conveyor_belt_loop");
|
||||
TScalingTask::Restart(delay);
|
||||
}
|
||||
|
||||
// game @0x00016374
|
||||
CoffeeGridTask::CoffeeGridTask(CoffeeIngredientGridRef pGrid_, TReal gridTime_)
|
||||
: TScalingTask(), pGrid(pGrid_), gridTime(gridTime_), rootPosition()
|
||||
{
|
||||
rootPosition = pGrid->GetDrawSpec().mMatrix[2];
|
||||
}
|
||||
|
||||
// game @0x0001782e
|
||||
bool CoffeeGridTask::Animate(void)
|
||||
{
|
||||
TScalingTask::Animate();
|
||||
TReal t = GetT(gridTime);
|
||||
if (t < oldT) {
|
||||
pGrid->ShiftRows();
|
||||
}
|
||||
pGrid->GetDrawSpec().mMatrix[2].y = t * pGrid->GetSlotHeight() + rootPosition.y;
|
||||
oldT = t;
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00015ee8
|
||||
uint32_t CoffeeIngredientGrid::CountVertical(uint32_t index) const
|
||||
{
|
||||
str type = slots[index].contents;
|
||||
uint32_t row = index / columns;
|
||||
uint32_t col = index - columns * row;
|
||||
uint32_t n = 0;
|
||||
uint32_t above = row;
|
||||
uint32_t top;
|
||||
bool same;
|
||||
do {
|
||||
top = above;
|
||||
if (row == n) break;
|
||||
above = top - 1;
|
||||
same = (slots[above * columns + col].contents == type);
|
||||
n++;
|
||||
} while (same);
|
||||
uint32_t below;
|
||||
do {
|
||||
below = row;
|
||||
if (rows - 1U <= below) break;
|
||||
same = (slots[(below + 1) * columns + col].contents == type);
|
||||
row = below + 1;
|
||||
} while (same);
|
||||
return (below - top) + 1;
|
||||
}
|
||||
|
||||
// game @0x00016002
|
||||
uint32_t CoffeeIngredientGrid::CountHorizontal(uint32_t index) const
|
||||
{
|
||||
str type = slots[index].contents;
|
||||
uint32_t col = index % columns;
|
||||
uint32_t n = 0;
|
||||
uint32_t left = col;
|
||||
uint32_t i = index;
|
||||
uint32_t first;
|
||||
bool same;
|
||||
do {
|
||||
first = left;
|
||||
i = i - 1;
|
||||
if (n == col) break;
|
||||
same = (slots[i].contents == type);
|
||||
n++;
|
||||
left = first - 1;
|
||||
} while (same);
|
||||
uint32_t last;
|
||||
do {
|
||||
last = col;
|
||||
index = index + 1;
|
||||
if (columns - 1U <= last) break;
|
||||
same = (slots[index].contents == type);
|
||||
col = last + 1;
|
||||
} while (same);
|
||||
return (last - first) + 1;
|
||||
}
|
||||
|
||||
// game @0x00016112
|
||||
int32_t CoffeeIngredientGrid::GetSlotIndex(TReal x, TReal y) const
|
||||
{
|
||||
TVec3 position = GetDrawSpec().mMatrix[2];
|
||||
if (position.x <= x && position.y <= y) {
|
||||
if (x < (TReal)columns * dx + position.x && y < (TReal)rows * dy + position.y) {
|
||||
int32_t index = columns * (int32_t)((y - position.y) / dy) + (int32_t)((x - position.x) / dx);
|
||||
if (index < (int32_t)slots.size()) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// game @0x00016216
|
||||
int32_t CoffeeIngredientGrid::GetSlotIndex(IngredientRef pIngredient) const
|
||||
{
|
||||
TVec3 position = pIngredient->GetDrawSpec().mMatrix[2];
|
||||
return GetSlotIndex(position.x, position.y);
|
||||
}
|
||||
|
||||
// game @0x0001624e
|
||||
TVec2 CoffeeIngredientGrid::GetRelativeSlotPosition(uint32_t index) const
|
||||
{
|
||||
TVec2 result;
|
||||
if (index < slots.size()) {
|
||||
uint32_t row = index / columns;
|
||||
uint32_t col = index % columns;
|
||||
if (col < columns && row < rows) {
|
||||
result.x = (TReal)col * dx + dx * 0.5f;
|
||||
result.y = (TReal)row * dy + dy * 0.5f;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x00016316
|
||||
TVec2 CoffeeIngredientGrid::GetSlotPosition(uint32_t index) const
|
||||
{
|
||||
TVec3 position = GetDrawSpec().mMatrix[2];
|
||||
TVec2 result = GetRelativeSlotPosition(index);
|
||||
result.x = result.x + position.x;
|
||||
result.y = result.y + position.y;
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x000163e8
|
||||
void CoffeeIngredientGrid::SetTargetImage(IngredientRef pIngredient)
|
||||
{
|
||||
TTextureRef pTexture;
|
||||
if (pIngredient) {
|
||||
pTexture = pIngredient->GetTexture();
|
||||
}
|
||||
pTargetImage->SetTexture(pTexture);
|
||||
}
|
||||
|
||||
// game @0x000164c8
|
||||
void CoffeeIngredientGrid::SetTargetPosition(TReal x, TReal y)
|
||||
{
|
||||
if (pTarget) {
|
||||
int32_t index = GetSlotIndex(x, y);
|
||||
if (index < 0) {
|
||||
if (pTarget->IsVisible()) {
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/cursor"), TPoint(1, 1), false);
|
||||
}
|
||||
pTarget->SetVisible(false);
|
||||
} else {
|
||||
if (!pTarget->IsVisible()) {
|
||||
TPlatform::GetInstance()->SetCursor(TTexture::GetSimple("cursor/blank_cursor"), TPoint(1, 1), false);
|
||||
}
|
||||
pTarget->SetVisible(true);
|
||||
pTarget->GetDrawSpec().mMatrix[2] = TVec3(GetRelativeSlotPosition(index), 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000166ea
|
||||
CoffeeIngredientGrid::CoffeeIngredientGrid(ProductRecipe& recipe_, TReal x, TReal y, uint32_t columns_, uint32_t rows_, TReal colW, TReal rowH)
|
||||
: TSprite(0), pSeam1(), pSeam2(), pTarget(), pTargetImage(), recipe(recipe_), dx(colW), dy(rowH), columns(columns_), rows(rows_), slots(), fillCount(0)
|
||||
{
|
||||
slots.resize(columns * rows);
|
||||
for (uint32_t i = 0; i < slots.size(); i++) {
|
||||
TVec2 position = GetSlotPosition(i);
|
||||
TSpriteRef pSlot = TSprite::Create(1, TTextureRef());
|
||||
pSlot->GetDrawSpec().mMatrix[2] = TVec3(position, 1.0f);
|
||||
AddChild(pSlot);
|
||||
}
|
||||
|
||||
GetDrawSpec().mMatrix[2].x = x;
|
||||
GetDrawSpec().mMatrix[2].y = y;
|
||||
|
||||
TTextureRef pSeamTexture;
|
||||
if (columns == 8) {
|
||||
pSeamTexture = TTexture::Get("image/conveyor_belt_wide_seam", 0);
|
||||
} else {
|
||||
pSeamTexture = TTexture::Get("image/conveyor_belt_narrow_seam", 0);
|
||||
}
|
||||
|
||||
pSeam1 = TSprite::Create(0, pSeamTexture);
|
||||
pSeam1->GetDrawSpec().mMatrix[2] = TVec3((TReal)((double)pSeamTexture->GetWidth() * 0.5), 0.0f, 1.0f);
|
||||
AddChild(pSeam1);
|
||||
|
||||
pSeam2 = TSprite::Create(0, pSeamTexture);
|
||||
TReal seamY = (TReal)(rows >> 1) * dy;
|
||||
pSeam2->GetDrawSpec().mMatrix[2] = TVec3((TReal)((double)pSeamTexture->GetWidth() * 0.5), seamY, 1.0f);
|
||||
AddChild(pSeam2);
|
||||
|
||||
pTarget = TSprite::Create(0, TTexture::Get("image/conveyor_belt_gridtarget", 0));
|
||||
pTarget->SetVisible(false);
|
||||
pTargetImage = TSprite::Create(-1, TTextureRef());
|
||||
pTargetImage->GetDrawSpec().mAlpha = 0.5f;
|
||||
pTarget->AddChild(pTargetImage);
|
||||
AddChild(pTarget);
|
||||
}
|
||||
|
||||
// game @0x0001701e
|
||||
CoffeeIngredientGridRef CoffeeIngredientGrid::Create(ProductRecipe& recipe, TReal x, TReal y, uint32_t columns, uint32_t rows, TReal colW, TReal rowH)
|
||||
{
|
||||
return CoffeeIngredientGridRef(new CoffeeIngredientGrid(recipe, x, y, columns, rows, colW, rowH));
|
||||
}
|
||||
|
||||
// game @0x0001709c
|
||||
void CoffeeIngredientGrid::Reset(void)
|
||||
{
|
||||
fillCount = 0;
|
||||
for (vector<CoffeeIngredientSlot>::iterator it = slots.begin(); it != slots.end(); ++it) {
|
||||
it->contents = "";
|
||||
if (it->pIngredient) {
|
||||
TSprite* pParent = it->pIngredient->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild(it->pIngredient);
|
||||
}
|
||||
it->pIngredient = IngredientRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000171b0
|
||||
bool CoffeeIngredientGrid::IsSlotEmpty(int32_t index) const
|
||||
{
|
||||
if (-1 < index) {
|
||||
if (index < (int32_t)slots.size()) {
|
||||
return slots[index].IsEmpty();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00017208
|
||||
bool CoffeeIngredientGrid::CanAccept(IngredientRef pIngredient) const
|
||||
{
|
||||
int32_t index = GetSlotIndex(pIngredient);
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
return slots[index].IsEmpty();
|
||||
}
|
||||
|
||||
// game @0x0001729c
|
||||
void CoffeeIngredientGrid::ShiftRows(void)
|
||||
{
|
||||
int32_t last = (rows - 1) * columns;
|
||||
for (uint32_t y = 0; y < rows; y++) {
|
||||
int32_t base = y * columns;
|
||||
if (y < rows - 1) {
|
||||
for (uint32_t x = 0; x < columns; x++) {
|
||||
CoffeeIngredientSlot temp(slots[x + base]);
|
||||
slots[x + base] = slots[x + last];
|
||||
slots[x + last] = temp;
|
||||
}
|
||||
}
|
||||
for (uint32_t x = 0; x < columns; x++) {
|
||||
int32_t index = x + base;
|
||||
if (!slots[index].IsEmpty()) {
|
||||
slots[index].pIngredient->GetDrawSpec().mMatrix[2] = TVec3(GetRelativeSlotPosition(index), 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t x = 0; x < columns; x++) {
|
||||
if (!slots[x].IsEmpty()) {
|
||||
IngredientRef pOld = slots[x].pIngredient;
|
||||
slots[x].contents = "";
|
||||
slots[x].pIngredient.reset();
|
||||
pOld->GetParent()->RemoveChild(pOld);
|
||||
}
|
||||
|
||||
uint32_t pick = RandRange(0, recipe.size() * 2);
|
||||
if (pick < recipe.size()) {
|
||||
slots[x].contents = recipe[pick];
|
||||
slots[x].pIngredient = Ingredient::Create(recipe[pick]);
|
||||
slots[x].pIngredient->GetDrawSpec().mMatrix[2] = TVec3(GetRelativeSlotPosition(x), 1.0f);
|
||||
AddChild(slots[x].pIngredient);
|
||||
}
|
||||
}
|
||||
|
||||
TReal y1 = dy + pSeam1->GetDrawSpec().mMatrix[2].y;
|
||||
TReal height = (TReal)rows * dy;
|
||||
if (height < y1) {
|
||||
y1 = y1 - height;
|
||||
}
|
||||
pSeam1->GetDrawSpec().mMatrix[2].y = y1;
|
||||
|
||||
TReal y2 = dy + pSeam2->GetDrawSpec().mMatrix[2].y;
|
||||
height = (TReal)rows * dy;
|
||||
if (height < y2) {
|
||||
y2 = y2 - height;
|
||||
}
|
||||
pSeam2->GetDrawSpec().mMatrix[2].y = y2;
|
||||
}
|
||||
|
||||
// game @0x00017898
|
||||
IngredientRef CoffeeIngredientGrid::RemoveIngredient(int32_t index)
|
||||
{
|
||||
IngredientRef pResult;
|
||||
if (-1 < index) {
|
||||
if (!slots[index].IsEmpty()) {
|
||||
fillCount = fillCount - 1;
|
||||
slots[index].contents = "";
|
||||
pResult = slots[index].pIngredient;
|
||||
slots[index].pIngredient = IngredientRef();
|
||||
pResult->SetLayer(7);
|
||||
}
|
||||
}
|
||||
return pResult;
|
||||
}
|
||||
|
||||
// game @0x000179d4
|
||||
void CoffeeIngredientGrid::ClearGrid(uint32_t x, uint32_t y, str type, list<IngredientRef>& collect)
|
||||
{
|
||||
int32_t index = y * columns + x;
|
||||
if (slots[index].contents == type) {
|
||||
if (x != 0) {
|
||||
ClearGrid(x - 1, y, type, collect);
|
||||
}
|
||||
if (y != 0) {
|
||||
ClearGrid(x, y - 1, type, collect);
|
||||
}
|
||||
IngredientRef pRemoved = RemoveIngredient(index);
|
||||
if (pRemoved) {
|
||||
collect.push_back(pRemoved);
|
||||
}
|
||||
if (x < columns - 1U) {
|
||||
ClearGrid(x + 1, y, type, collect);
|
||||
}
|
||||
if (y < rows - 1U) {
|
||||
ClearGrid(x, y + 1, type, collect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00017bee
|
||||
void CoffeeIngredientGrid::ClearFrom(int32_t index)
|
||||
{
|
||||
if (!slots[index].IsEmpty()) {
|
||||
CollectedIngredientMessage* pMessage = new CollectedIngredientMessage();
|
||||
uint32_t cols = columns;
|
||||
ClearGrid(index % cols, index / cols, slots[index].contents, pMessage->collect);
|
||||
TWindow* pFactory = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pFactory != NULL) {
|
||||
pFactory = pFactory->GetChildWindow("FactoryGame", -1);
|
||||
if (pFactory != NULL) {
|
||||
pFactory->SendWindowMessage(pMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00017d30
|
||||
bool CoffeeIngredientGrid::AddIngredient(IngredientRef pIngredient, bool allowMatch)
|
||||
{
|
||||
int32_t index = GetSlotIndex(pIngredient);
|
||||
if (-1 < index) {
|
||||
if (slots[index].IsEmpty()) {
|
||||
fillCount = fillCount + 1;
|
||||
slots[index].contents = pIngredient->GetName();
|
||||
slots[index].pIngredient = pIngredient;
|
||||
pIngredient->SetLayer(5);
|
||||
pIngredient->GetDrawSpec().mMatrix[2] = TVec3(GetRelativeSlotPosition(index), 1.0f);
|
||||
pIngredient->GetParent()->RemoveChild(pIngredient);
|
||||
AddChild(pIngredient);
|
||||
if (allowMatch && (CountHorizontal(index) > 2 || CountVertical(index) > 2)) {
|
||||
ClearFrom(index);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
125
port/game/CoffeeGun.cpp
Normal file
125
port/game/CoffeeGun.cpp
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
// Port of the game's CoffeeGun.cpp (Chocolatier 3, Big Splash Games): CoffeeGunTask, the minigame task that owns the
|
||||
// gun sprite of the coffee factory. Fire pops the next ingredient off the conveyor and shoots it at the clicked point
|
||||
// (or at the centre of the grid slot under it, when that slot is empty) as a FlyingIngredient; Animate advances every
|
||||
// flying ingredient and, when one reached the end of its flight, adds it to the ingredient grid (or kills it when the
|
||||
// grid cannot accept it). Ported from the shipped game binary (release build, addresses "game @"); declarations from
|
||||
// the original CoffeeGun.h (port/game/CoffeeGun.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TScalingTask 0x0..0x1c (vptr 0x0), pGun 0x1c, pConveyor 0x24, pGrid 0x2c, gunTime 0x34,
|
||||
// flying (std::list<FlyingIngredientRef>) 0x38. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4, the "flight finished" value of FlyingIngredient::Tick),
|
||||
// 1000.0f (@0x001ab6fc, the length the direction is scaled to when the shot goes to the clicked point, and the
|
||||
// flight distance stored in that case).
|
||||
// - Strings from the game's __cstring: "DoAnim" (@0x001589c8), "launch" (@0x001589d0, the sound message text, event
|
||||
// 0x3ea = kSoundEvent). The layer passed to SetLayer is 8 (INGREDIENT_FLYING_LAYER).
|
||||
// - FlyingIngredient fields written by Fire: startPoint (+8), direction (+0x10), distance (+0x18).
|
||||
// - Fire constructs a default TCurveRef local that is never used (released at the end); kept as in the binary.
|
||||
// - Ingredient vtable slot 0x34 used by Animate is Die.
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in CoffeeGun.h):
|
||||
// ~CoffeeGunTask (implicit): D1 game @0x0016a3bc (list, then the pGrid, pConveyor and pGun shared_ptr releases).
|
||||
// std::list<FlyingIngredientRef> instantiations are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "CoffeeGun.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "CoffeeGrid.h"
|
||||
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x00017f7c
|
||||
CoffeeGunTask::CoffeeGunTask(TAnimatedSpriteRef pGun_, TReal gunTime_, ::shared_ptr<IngredientQueue> pConveyor_, CoffeeIngredientGridRef pGrid_)
|
||||
: TScalingTask(), pGun(pGun_), pConveyor(pConveyor_), pGrid(pGrid_), gunTime(gunTime_), flying()
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x00018018
|
||||
void CoffeeGunTask::Reset(TReal newScale)
|
||||
{
|
||||
TScalingTask::Reset(newScale);
|
||||
|
||||
for (list<FlyingIngredientRef>::iterator it = flying.begin(); it != flying.end(); ++it) {
|
||||
TSprite* pParent = (*it)->pIngredient->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild((*it)->pIngredient);
|
||||
}
|
||||
}
|
||||
flying.clear();
|
||||
|
||||
pGrid->SetTargetImage(pConveyor->PeekConveyor());
|
||||
}
|
||||
|
||||
// game @0x00018470
|
||||
bool CoffeeGunTask::Animate(void)
|
||||
{
|
||||
TReal tElapsed = AnimateDelta(gunTime);
|
||||
|
||||
list<FlyingIngredientRef>::iterator it = flying.begin();
|
||||
while (it != flying.end()) {
|
||||
list<FlyingIngredientRef>::iterator cur = it;
|
||||
++it;
|
||||
|
||||
TReal result = (*cur)->Tick(tElapsed);
|
||||
if (result == 1.0f) {
|
||||
if (pGrid->CanAccept(IngredientRef((*cur)->pIngredient))) {
|
||||
pGrid->AddIngredient(IngredientRef((*cur)->pIngredient), true);
|
||||
} else {
|
||||
(*cur)->pIngredient->Die();
|
||||
}
|
||||
flying.erase(cur);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00018100
|
||||
bool CoffeeGunTask::Fire(TPoint const& point)
|
||||
{
|
||||
IngredientRef pIngredient = pConveyor->PopConveyor();
|
||||
if (!pIngredient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pGrid->SetTargetImage(pConveyor->PeekConveyor());
|
||||
|
||||
pIngredient->SetLayer(INGREDIENT_FLYING_LAYER);
|
||||
|
||||
TVec3 start(pGun->GetDrawSpec().mMatrix[2]);
|
||||
TVec2 direction;
|
||||
TCurveRef pCurve;
|
||||
TReal distance;
|
||||
|
||||
int32_t slot = pGrid->GetSlotIndex((TReal)point.x, (TReal)point.y);
|
||||
if (slot < 0 || !pGrid->IsSlotEmpty(slot)) {
|
||||
direction.x = (TReal)point.x - start.x;
|
||||
direction.y = (TReal)point.y - start.y;
|
||||
TReal length = direction.Length();
|
||||
direction = direction * (1000.0f / length);
|
||||
distance = 1000.0f;
|
||||
} else {
|
||||
direction = pGrid->GetSlotPosition((uint32_t)slot);
|
||||
direction.x = direction.x - start.x;
|
||||
direction.y = direction.y - start.y;
|
||||
distance = direction.Length();
|
||||
}
|
||||
|
||||
FlyingIngredientRef pFlying = FlyingIngredient::Create(IngredientRef(pIngredient));
|
||||
pFlying->startPoint.x = start.x;
|
||||
pFlying->startPoint.y = start.y;
|
||||
pFlying->direction = direction;
|
||||
pFlying->distance = distance;
|
||||
flying.push_back(pFlying);
|
||||
|
||||
pGun->Play("DoAnim");
|
||||
TWindowManager::GetInstance()->PostWindowMessage(new TMessage(kSoundEvent, "launch"));
|
||||
|
||||
return true;
|
||||
}
|
||||
199
port/game/CoffeeHopper.cpp
Normal file
199
port/game/CoffeeHopper.cpp
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
// Port of the game's CoffeeHopper.cpp (Chocolatier 3, Big Splash Games): CoffeeHopper, the coffee factory's machine
|
||||
// sprite that counts the collected ingredients per recipe entry (one meter box per ingredient with a needle), and
|
||||
// HopperCollectionTask, the scaling task that flies collected ingredients to the hopper and adds them when they arrive.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// CoffeeHopper.h (port/game/CoffeeHopper.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): HopperCollectionTask: TScalingTask 0x0..0x1c, flying (std::list<FlyingIngredientRef>) 0x1c,
|
||||
// pHopper 0x24, collectTime 0x2c (set to 250.0f by the constructor). CoffeeHopper: TSprite 0x0..0x80, ingredientCount
|
||||
// [6] 0x80 (not initialised by the constructor), pMeter[6] 0x98, recipe (reference to the caller's vector) 0xc8;
|
||||
// sizeof 0xcc (Create allocates 0xcc bytes). The headers match.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 75.0f (@0x001ab708, the x offset of the flight target), -53.0f
|
||||
// (@0x001ab70c) and 65.0f (@0x001ab710, first y and y step of the three-box layout), 32.0f (@0x001ab714) and 56.5f
|
||||
// (@0x001ab718, the offsets of the four-box layout), 1.0f (@0x001ab6e4, the flight finished value of
|
||||
// FlyingIngredient::Tick); doubles -10.0 (@0x001ab4e8) and 24.0 (@0x001ab4f0, UpdateMeter). The other constants
|
||||
// (-1.5f, -1.0f, 25.5f, 24.0f, -6.5f, -3.5f, 11.0f, 1.0f) are immediates in the code.
|
||||
// - Strings from the game's __cstring: "image/machine_meter", "items/", "image/machine_needle".
|
||||
// - UpdateMeter moves the needle of box i to y = (double)(count < 11 ? count * 0x30 : 0x1e0) / -10.0 + 24.0.
|
||||
// - The constructor keeps a local array of five box sprites (the sprite handles stay alive in the parent); the box
|
||||
// layout loops index it up to 3 (and 4 when the recipe has five entries) whatever the recipe size.
|
||||
// - Layers: box 0, item 1, needle 2; the hopper itself is TSprite(9).
|
||||
// - Ingredient / sprite vtable slot 0x14 is TSprite::RemoveChild, called on the sprite parent (+0xc).
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in the headers):
|
||||
// ~CoffeeHopper (implicit): D1 game @0x0016b994, D0 game @0x0016b930 (the six pMeter releases, then ~TSprite).
|
||||
// ~HopperCollectionTask (implicit): D1 game @0x0016a45c (pHopper release, then the flying list).
|
||||
// std::list<FlyingIngredientRef> instantiations and boost::shared_ptr<CoffeeHopper> template code are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "CoffeeHopper.h"
|
||||
#include "IngredientQueue.h"
|
||||
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
|
||||
|
||||
// game @0x000185bc
|
||||
void CoffeeHopper::UpdateMeter(void)
|
||||
{
|
||||
for (uint32_t i = 0; i < recipe.size(); i++) {
|
||||
int32_t amount;
|
||||
if (ingredientCount[i] < 11) {
|
||||
amount = ingredientCount[i] * 0x30;
|
||||
} else {
|
||||
amount = 0x1e0;
|
||||
}
|
||||
pMeter[i]->GetDrawSpec().mMatrix[2].y = (TReal)((double)amount / -10.0 + 24.0);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00018636
|
||||
bool CoffeeHopper::Release(void)
|
||||
{
|
||||
for (uint32_t i = 0; i < recipe.size(); i++) {
|
||||
if (ingredientCount[i] == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (uint32_t i = 0; i < recipe.size(); i++) {
|
||||
ingredientCount[i] = ingredientCount[i] - 1;
|
||||
}
|
||||
UpdateMeter();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x000186a2
|
||||
void CoffeeHopper::Add(str type)
|
||||
{
|
||||
uint32_t best = recipe.size();
|
||||
int32_t bestCount = 99999;
|
||||
for (uint32_t i = 0; i < recipe.size(); i++) {
|
||||
if (type.compare(recipe[i]) == 0 && ingredientCount[i] <= bestCount) {
|
||||
best = i;
|
||||
bestCount = ingredientCount[i];
|
||||
}
|
||||
}
|
||||
if (best < recipe.size()) {
|
||||
ingredientCount[best] = ingredientCount[best] + 1;
|
||||
}
|
||||
UpdateMeter();
|
||||
}
|
||||
|
||||
// game @0x0001874e
|
||||
void CoffeeHopper::Reset(void)
|
||||
{
|
||||
for (uint32_t i = 0; i < recipe.size(); i++) {
|
||||
ingredientCount[i] = 0;
|
||||
}
|
||||
UpdateMeter();
|
||||
}
|
||||
|
||||
// game @0x0001878e
|
||||
HopperCollectionTask::HopperCollectionTask(CoffeeHopperRef pHopper_)
|
||||
: TScalingTask(), flying(), pHopper(pHopper_), collectTime(250.0f)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x000187ee
|
||||
void HopperCollectionTask::Reset(TReal newScale)
|
||||
{
|
||||
pHopper->Reset();
|
||||
for (list<FlyingIngredientRef>::iterator it = flying.begin(); it != flying.end(); ++it) {
|
||||
TSprite* pParent = (*it)->pIngredient->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild((*it)->pIngredient);
|
||||
}
|
||||
}
|
||||
flying.clear();
|
||||
TScalingTask::Reset(newScale);
|
||||
}
|
||||
|
||||
// game @0x0001889e
|
||||
bool HopperCollectionTask::Animate(void)
|
||||
{
|
||||
TReal tElapsed = AnimateDelta(collectTime);
|
||||
|
||||
list<FlyingIngredientRef>::iterator it = flying.begin();
|
||||
while (it != flying.end()) {
|
||||
list<FlyingIngredientRef>::iterator cur = it;
|
||||
++it;
|
||||
if ((*cur)->Tick(tElapsed) == 1.0f) {
|
||||
IngredientRef pIngredient = (*cur)->pIngredient;
|
||||
pHopper->Add(pIngredient->GetName());
|
||||
TSprite* pParent = pIngredient->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild(pIngredient);
|
||||
}
|
||||
flying.erase(cur);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x000189f6
|
||||
void HopperCollectionTask::Add(IngredientRef pIngredient)
|
||||
{
|
||||
FlyingIngredientRef pFlying = FlyingIngredient::Create(pIngredient);
|
||||
flying.push_back(pFlying);
|
||||
TVec3 position = pHopper->GetDrawSpec().mMatrix[2];
|
||||
position.x = position.x - 75.0f;
|
||||
pFlying->SetTarget(position.x, position.y);
|
||||
}
|
||||
|
||||
// game @0x00018abe
|
||||
void HopperCollectionTask::Add(list<IngredientRef>& collect)
|
||||
{
|
||||
for (list<IngredientRef>::iterator it = collect.begin(); it != collect.end(); ++it) {
|
||||
Add(*it);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00018b28
|
||||
CoffeeHopper::CoffeeHopper(TVec2 const& position, ProductRecipe& recipe_, str appearance)
|
||||
: TSprite(9), recipe(recipe_)
|
||||
{
|
||||
SetTexture(TTexture::Get(appearance, 0));
|
||||
GetDrawSpec().mMatrix[2] = TVec3(position, 1.0f);
|
||||
|
||||
TSpriteRef pBox[5];
|
||||
uint32_t count = recipe.size();
|
||||
for (uint32_t i = 0; (int32_t)i < (int32_t)count; i++) {
|
||||
pBox[i] = TSprite::Create(0, TTexture::Get("image/machine_meter", 0));
|
||||
AddChild(pBox[i]);
|
||||
|
||||
TSpriteRef pItem = TSprite::Create(1, TTexture::Get(str("items/") + recipe[i], 0));
|
||||
pItem->GetDrawSpec().mMatrix[2] = TVec3(-1.5f, -1.0f, 1.0f);
|
||||
pBox[i]->AddChild(pItem);
|
||||
|
||||
pMeter[i] = TSprite::Create(2, TTexture::Get("image/machine_needle", 0));
|
||||
pMeter[i]->GetDrawSpec().mMatrix[2] = TVec3(25.5f, 24.0f, 1.0f);
|
||||
pBox[i]->AddChild(pMeter[i]);
|
||||
}
|
||||
|
||||
if (count == 3) {
|
||||
TReal y = -53.0f;
|
||||
for (int32_t i = 0; i != 3; i++) {
|
||||
pBox[i]->GetDrawSpec().mMatrix[2] = TVec3(-6.5f, y, 1.0f);
|
||||
y = y + 65.0f;
|
||||
}
|
||||
} else {
|
||||
for (uint32_t i = 0; i != 4; i++) {
|
||||
TReal y = (TReal)(((int32_t)i / 2) * 0x51) - 32.0f;
|
||||
TReal x = (TReal)((int32_t)(i & 1) * 0x6a) - 56.5f;
|
||||
pBox[i]->GetDrawSpec().mMatrix[2] = TVec3(x, y, 1.0f);
|
||||
}
|
||||
if (count == 5) {
|
||||
pBox[4]->GetDrawSpec().mMatrix[2] = TVec3(-3.5f, 11.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00019298
|
||||
CoffeeHopperRef CoffeeHopper::Create(TVec2 const& position, ProductRecipe& recipe, str appearance)
|
||||
{
|
||||
return CoffeeHopperRef(new CoffeeHopper(position, recipe, appearance));
|
||||
}
|
||||
151
port/game/CoffeeQueue.cpp
Normal file
151
port/game/CoffeeQueue.cpp
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
// Port of the game's CoffeeQueue.cpp (Chocolatier 3, Big Splash Games): CoffeeProduct (a finished coffee that rides
|
||||
// the factory's product conveyor curve) and CoffeeProductQueueTask (the task that creates the products, one each time
|
||||
// the hopper releases, and moves them along the curve until they reach the end).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// CoffeeQueue.h (port/game/CoffeeQueue.h, unchanged). CustomItems.h (the shipped header, copied unchanged to
|
||||
// port/game) declares BuildItemAppearance, which AddProduct calls.
|
||||
//
|
||||
// Layout (game, i386): CoffeeProduct: TSprite 0x0..0x80, pCurve 0x80, t 0x88; sizeof 0x8c (Create allocates 0x8c
|
||||
// bytes). CoffeeProductQueueTask: TScalingTask 0x0..0x1c, pBase 0x1c, pHopper 0x24, pCurve 0x2c, conveyorTime 0x34,
|
||||
// productSpacing 0x38, appearanceCache 0x3c, appearance 0x48, tints 0x54, products (std::list<CoffeeProductRef>)
|
||||
// 0x60. The headers match.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4), 0.5f (AddProduct's BuildItemAppearance scale, an
|
||||
// immediate); double 0.1 (@0x001ab4c8).
|
||||
// - Strings from the game's __cstring: "FactoryGame" (the factory child window), "" (@0x001581bc) and
|
||||
// "chocolate_counted" (the sound message text; event 0x3ea = kSoundEvent). The count message is event 0x3ef =
|
||||
// kCountProductEvent.
|
||||
// - The constructor divides productSpacing by conveyorTime (the spacing is stored in task time units).
|
||||
// - CoffeeProductQueueTask::Animate walks the list in order and stops as soon as the previous (surviving) product's t
|
||||
// is below 0.1 (the first product tests against an initial 1.0f). A product whose Update returns false is removed
|
||||
// from its sprite parent, the "FactoryGame" child of the top modal window (looked up once and kept, retried while
|
||||
// missing) is sent kCountProductEvent, the sound "chocolate_counted" is posted, and the product is erased. After
|
||||
// the loop a new product is added through the hopper (CoffeeHopper::Release) when the last t exceeds
|
||||
// productSpacing; otherwise, with no products left, the scale is reset to 1.
|
||||
// - CoffeeProductQueueTask::Reset only calls TScalingTask::Reset (it clears nothing).
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in the header):
|
||||
// ~CoffeeProduct (inline in CoffeeQueue.h): D0 game @0x0016bc08, D1 game @0x0016bc5c (releases pCurve, then
|
||||
// ~TSprite).
|
||||
// ~CoffeeProductQueueTask (implicit): D1 game @0x0016a2cc (products, tints, appearance, appearanceCache, pCurve,
|
||||
// pHopper, pBase).
|
||||
// std::list<CoffeeProductRef> instantiations and boost::shared_ptr<CoffeeProduct> template code are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "CoffeeQueue.h"
|
||||
#include "CoffeeHopper.h"
|
||||
#include "CustomItems.h"
|
||||
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/window.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x00019320
|
||||
bool CoffeeProduct::Update(TReal elapsed)
|
||||
{
|
||||
t = elapsed + t;
|
||||
if (1.0f < t) {
|
||||
t = 1.0f;
|
||||
}
|
||||
GetDrawSpec().mMatrix[2] = TVec3(pCurve->GetPoint(t, 0), 1.0f);
|
||||
return t <= 1.0f && 1.0f != t;
|
||||
}
|
||||
|
||||
// game @0x000193be
|
||||
void CoffeeProductQueueTask::Reset(TReal newScale)
|
||||
{
|
||||
TScalingTask::Reset(newScale);
|
||||
}
|
||||
|
||||
// game @0x000193c8
|
||||
CoffeeProduct::CoffeeProduct(TCurveRef pCurve_)
|
||||
: TSprite(2), pCurve(pCurve_), t(0)
|
||||
{
|
||||
GetDrawSpec().mMatrix[2] = TVec3(pCurve->GetStartPoint(), 1.0f);
|
||||
}
|
||||
|
||||
// game @0x0001947c
|
||||
CoffeeProductRef CoffeeProduct::Create(TCurveRef pCurve)
|
||||
{
|
||||
return CoffeeProductRef(new CoffeeProduct(pCurve));
|
||||
}
|
||||
|
||||
// game @0x00019504
|
||||
CoffeeProductQueueTask::CoffeeProductQueueTask(TSpriteRef pBase_, CoffeeHopperRef pHopper_, TCurveRef pCurve_, TReal conveyorTime_, TReal productSpacing_, vector<str> appearance_, vector<TColor> tints_)
|
||||
: TScalingTask(), pBase(pBase_), pHopper(pHopper_), pCurve(pCurve_), conveyorTime(conveyorTime_), productSpacing(productSpacing_), appearanceCache(), appearance(appearance_), tints(tints_), products()
|
||||
{
|
||||
productSpacing = productSpacing / conveyorTime;
|
||||
|
||||
for (int i = 0; i < (int)appearance.size(); i++) {
|
||||
TTextureRef pTexture = TTexture::Get(appearance[i], 0);
|
||||
if (pTexture) {
|
||||
appearanceCache.push_back(pTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001970c
|
||||
void CoffeeProductQueueTask::AddProduct(TSpriteRef pBase_)
|
||||
{
|
||||
CoffeeProductRef pProduct = CoffeeProduct::Create(pCurve);
|
||||
BuildItemAppearance(pProduct, appearance, tints, 0.5f);
|
||||
products.push_back(pProduct);
|
||||
pBase_->AddChild(pProduct);
|
||||
}
|
||||
|
||||
// game @0x00019834
|
||||
bool CoffeeProductQueueTask::Animate(void)
|
||||
{
|
||||
TReal tElapsed = AnimateDelta(conveyorTime);
|
||||
|
||||
TWindow* pFactory = NULL;
|
||||
TReal lastT = 1.0f;
|
||||
list<CoffeeProductRef>::iterator it = products.begin();
|
||||
while (it != products.end() && !((double)lastT < 0.1)) {
|
||||
list<CoffeeProductRef>::iterator cur = it;
|
||||
++it;
|
||||
|
||||
if (!(*cur)->Update(tElapsed)) {
|
||||
TSprite* pParent = (*cur)->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild(*cur);
|
||||
}
|
||||
|
||||
bool send = true;
|
||||
if (pFactory == NULL) {
|
||||
send = false;
|
||||
pFactory = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pFactory != NULL) {
|
||||
pFactory = pFactory->GetChildWindow("FactoryGame", -1);
|
||||
if (pFactory != NULL) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (send) {
|
||||
pFactory->SendWindowMessage(new TMessage(kCountProductEvent, "", pFactory));
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->PostWindowMessage(new TMessage(kSoundEvent, "chocolate_counted", NULL));
|
||||
products.erase(cur);
|
||||
lastT = 1.0f;
|
||||
} else {
|
||||
lastT = (*cur)->GetT();
|
||||
}
|
||||
}
|
||||
|
||||
if (lastT <= productSpacing || !pHopper->Release()) {
|
||||
if (products.empty()) {
|
||||
SetScale(1.0f);
|
||||
}
|
||||
} else {
|
||||
AddProduct(pBase);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
246
port/game/ContentManager.cpp
Normal file
246
port/game/ContentManager.cpp
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
// Port of the game's ContentManager.cpp (Chocolatier 3, Big Splash Games): Content, the singleton that finds the
|
||||
// game's data files (every file whose name ends with a key such as "ports.xml" or "ingredients.xml", anywhere in
|
||||
// the file system, sorted), turns ingredient / product XML records into Lua table constructors passed to the
|
||||
// scripts (CreateIngredient / CreateProductFromXML), and lists the port and quest scripts named in the list files.
|
||||
// Publishes LoadPortFileList, LoadQuestFileList, LoadIngredients and LoadProducts to the window script.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// ContentManager.h (port/game/ContentManager.h; only ::shared_ptr qualified for the host compiler).
|
||||
//
|
||||
// Game notes:
|
||||
// - LoadDataFile tests the KEY (not the listed file) for ".xml" / ".csv" in every iteration: with an ".xml" key each
|
||||
// listed file goes to LoadDataFileXML; with a ".csv" key LoadDataFileCSV is called with the key, and that function
|
||||
// has no code in the game (its inlined body is empty; only the argument copy remains).
|
||||
// - LoadListFile: a list entry "name" (the <name> child's content, or the node's own content) without a trailing
|
||||
// ".lua" is looked up as <list dir>/name/name.lua, then <list dir>/name.lua; existing files are stored in the
|
||||
// table at 1, 2, ... (unsigned counter).
|
||||
// - Content::LoadTexture is declared but has no code in the game. ~Content has no out-of-line code: it is inlined
|
||||
// (TAssetMap destructor) into boost::checked_delete<Content> game @0x0016cd5c.
|
||||
//
|
||||
// LoadAppearanceInternal / LoadAppearance / BuildItemAppearance (game @0x0001f9e4 / @0x0001fcd2 / @0x0001fff4),
|
||||
// listed with ContentManager in choc3/cpp_src, are declared in CustomItems.h and live in their own object
|
||||
// (CustomItems.o, between CurveEditor.o and customtextedit.o in the link order); not part of this file.
|
||||
//
|
||||
// Header-inline code emitted out of line (bodies from ContentManager.h): Content::LoadQuestFileList game
|
||||
// game @0x0016cb9c, LoadPortFileList game @0x0016cc20, LoadProducts game @0x0016ccbc, LoadIngredients game @0x0016cd0c;
|
||||
// lua_pushdirectclosure<Content, void (Content::*)(TLuaTable*)> game @0x0016c0a4 and <Content, void
|
||||
// (Content::*)()> game @0x0016c0f0; LPCD::DirectCallMemberDispatcherHelper<Content, void (Content::*)(TLuaTable*)>
|
||||
// game @0x0016c1b0 (its ReturnSpecialization<void>::Call<Content, TLuaTable*> game @0x0016c160) and <Content, void
|
||||
// (Content::*)()> game @0x0016c99c (pf/luapluscd.h templates). The std::vector<str> / std::sort instantiations are
|
||||
// library code.
|
||||
//
|
||||
// Strings from the game's __cstring: "{", "\"", "=", ",", "}", "LoadPortFileList", "LoadQuestFileList",
|
||||
// "LoadIngredients", "LoadProducts", "", "root", "name", ".lua", "/", "ingredient", "CreateIngredient ", "items/",
|
||||
// "product", "CreateProductFromXML ", ".xml", ".csv"; ContentManager.h: "ports.xml", "port", "quests.xml", "file",
|
||||
// "ingredients.xml", "products.xml".
|
||||
//
|
||||
// Static data: Content::pInstance (boost::shared_ptr<Content>, __common @0x0021fa20). Static initializer:
|
||||
// __static_initialization_and_destruction_0 game @0x001ab93e constructs it (released by ___tcf_0 game
|
||||
// @0x0001ae88); __GLOBAL__I__ZN7Content9pInstanceE game @0x001ab97c jumps to it.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "ContentManager.h"
|
||||
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/simplexml.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
::shared_ptr<Content> Content::pInstance;
|
||||
|
||||
// game @0x00019b08
|
||||
// {name="content",name={...},...} for the children of pNode (a child with children becomes a nested table).
|
||||
str Content::SimpleXmlToLua(TXmlNode* pNode)
|
||||
{
|
||||
str result("{");
|
||||
if (pNode->HasChildren())
|
||||
{
|
||||
pNode->ResetChildren();
|
||||
str name;
|
||||
TXmlNode* pChild;
|
||||
while (pNode->GetNextChild(&name, &pChild))
|
||||
{
|
||||
str value;
|
||||
if (pChild->HasChildren())
|
||||
{
|
||||
value = SimpleXmlToLua(pChild);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = pChild->GetContent();
|
||||
value = str("\"") + value + str("\"");
|
||||
}
|
||||
result = result + name + str("=") + value + str(",");
|
||||
}
|
||||
}
|
||||
result = result + str("}");
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x00019ebe
|
||||
TTextureRef Content::LoadCursor(str assetName)
|
||||
{
|
||||
return TTexture::GetSimple(assetName);
|
||||
}
|
||||
|
||||
// game @0x00019f12
|
||||
Content::Content(void)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "LoadPortFileList", this, Content::LoadPortFileList);
|
||||
ScriptRegisterMemberDirect(script, "LoadQuestFileList", this, Content::LoadQuestFileList);
|
||||
ScriptRegisterMemberDirect(script, "LoadIngredients", this, Content::LoadIngredients);
|
||||
ScriptRegisterMemberDirect(script, "LoadProducts", this, Content::LoadProducts);
|
||||
}
|
||||
|
||||
// no out-of-line code (inlined into boost::checked_delete<Content> game @0x0016cd5c)
|
||||
Content::~Content(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0001a0e2
|
||||
// Every file (all folders, recursively) whose name ends with key, sorted.
|
||||
void Content::BuildFileList(str key, vector<str>& list)
|
||||
{
|
||||
str file;
|
||||
while (TFile::GetNextFile("", &file, true))
|
||||
{
|
||||
int pos = file.find(key, 0, 0);
|
||||
if (pos != -1 && pos == (int)(file.length() - key.length()))
|
||||
{
|
||||
list.push_back(file);
|
||||
}
|
||||
}
|
||||
sort(list.begin(), list.end());
|
||||
}
|
||||
|
||||
// game @0x0001a1fa
|
||||
void Content::LoadListFile(TLuaTable* pTable, str fileNameKey, str nodeKey)
|
||||
{
|
||||
vector<str> files;
|
||||
BuildFileList(fileNameKey, files);
|
||||
|
||||
uint32_t count = 0;
|
||||
for (uint32_t i = 0; i < files.size(); i++)
|
||||
{
|
||||
TXmlNode doc;
|
||||
doc.ParseFile(files[i].c_str());
|
||||
TXmlNode* pRoot = doc.GetChild("root");
|
||||
if (pRoot)
|
||||
{
|
||||
str path = files[i];
|
||||
int slash = path.find('/', str::kReverse, 0);
|
||||
if (slash != -1)
|
||||
{
|
||||
path = path.substr(0, slash + 1);
|
||||
}
|
||||
|
||||
str name;
|
||||
TXmlNode* pChild;
|
||||
pRoot->ResetChildren();
|
||||
while (pRoot->GetNextChild(&name, &pChild))
|
||||
{
|
||||
if (name.compare(nodeKey) == 0)
|
||||
{
|
||||
str file;
|
||||
TXmlNode* pName = pChild->GetChild("name");
|
||||
if (pName)
|
||||
{
|
||||
file = pName->GetContent();
|
||||
}
|
||||
else
|
||||
{
|
||||
file = pChild->GetContent();
|
||||
}
|
||||
|
||||
if (file.length() > 3)
|
||||
{
|
||||
if (file.find(".lua", str::kReverse, 0) == (int)(file.length() - 4))
|
||||
{
|
||||
file = file.substr(0, file.length() - 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (file.length() != 0)
|
||||
{
|
||||
str fullPath = path + file + str("/") + file + str(".lua");
|
||||
if (!TFile::Exists(fullPath))
|
||||
{
|
||||
fullPath = path + file + str(".lua");
|
||||
}
|
||||
if (TFile::Exists(fullPath))
|
||||
{
|
||||
count++;
|
||||
pTable->Assign((lua_Number)count, fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001a8dc
|
||||
void Content::LoadDataFileXML(str fileName)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
TXmlNode doc;
|
||||
doc.ParseFile(fileName.c_str());
|
||||
TXmlNode* pRoot = doc.GetChild("root");
|
||||
if (pRoot)
|
||||
{
|
||||
str name;
|
||||
TXmlNode* pChild;
|
||||
pRoot->ResetChildren();
|
||||
while (pRoot->GetNextChild(&name, &pChild))
|
||||
{
|
||||
if (name == str("ingredient"))
|
||||
{
|
||||
str command = str("CreateIngredient ") + SimpleXmlToLua(pChild);
|
||||
script->DoLuaString(command, -1, 0);
|
||||
str assetName = str("items/") + pChild->GetChildContent("name");
|
||||
ingredientCache.AddAsset(assetName, TAssetRef(), false);
|
||||
}
|
||||
else if (name == str("product"))
|
||||
{
|
||||
str command = str("CreateProductFromXML ") + SimpleXmlToLua(pChild);
|
||||
script->DoLuaString(command, -1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no code in the game (the call in LoadDataFile is inlined to nothing)
|
||||
void Content::LoadDataFileCSV(str fileName)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0001ad04
|
||||
void Content::LoadDataFile(str fileNameKey)
|
||||
{
|
||||
vector<str> files;
|
||||
BuildFileList(fileNameKey, files);
|
||||
for (uint32_t i = 0; i < files.size(); i++)
|
||||
{
|
||||
if (fileNameKey.find(".xml", 0, 0) != -1)
|
||||
{
|
||||
LoadDataFileXML(files[i]);
|
||||
}
|
||||
else if (fileNameKey.find(".csv", 0, 0) != -1)
|
||||
{
|
||||
LoadDataFileCSV(fileNameKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001aea0
|
||||
bool Content::Initialize(void)
|
||||
{
|
||||
if (!pInstance)
|
||||
{
|
||||
pInstance.reset(new Content);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
358
port/game/Curve.cpp
Normal file
358
port/game/Curve.cpp
Normal file
|
|
@ -0,0 +1,358 @@
|
|||
// Port of the game's Curve.cpp (Chocolatier 3, Big Splash Games): TCurve, a piecewise cubic Bezier path that is
|
||||
// subdivided into straight segments and evaluated by normalized path length (GetPoint), plus debug rendering of
|
||||
// the curve, its control hull and its control points.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// Curve.h (port/game/Curve.h, unchanged). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): control (vector<TVec2>) 0x0, length 0xc, division (vector<Subdivision>) 0x10, sizeof 0x1c
|
||||
// (Create allocates 0x1c bytes). Subdivision: tStart 0x0, tEnd 0x4, segmentLength 0x8, totalLength 0xc, start
|
||||
// 0x10, end 0x18 (sizeof 0x20). The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - __ACCEPTABLE_ERROR is a file-level float (__data, game @0x001d80e0, initial value 0.2). Subdivide splits a
|
||||
// cubic (de Casteljau at the middle of its t interval) until the length of its control polygon exceeds its
|
||||
// chord by no more than that error; the leaf records start, end, the control polygon length as the segment
|
||||
// length and a total length of 0. DoSubdivision runs Subdivide(0, 1, ...) for every group of four control points
|
||||
// starting at 0, 3, 6, ... (loop bound size - 3 computed in 32-bit unsigned), then sums segment lengths into
|
||||
// length and the per-segment running totalLength.
|
||||
// - GetLength / RenderCurve are const but build the divisions lazily (when they are empty): the game does it
|
||||
// through the const object, written here with const_cast.
|
||||
// - GetPoint(t): t >= 1 (or NaN) gives the end point, t <= 0 the start point (the game tests t < 1 first and then
|
||||
// 0 < t || NaN); otherwise the point at t * length along the segments, plus the normalized segment direction
|
||||
// in *pTangent when it is not null. Beyond the last segment the result is its end.
|
||||
// - GetEndPoint is the control point at ((size - 1) / 3) * 3 (unsigned), (0, 0) when empty. GetStartPoint reads
|
||||
// control[0] unchecked. GetControlPoint wraps the index modulo the size (unsigned). AddControlPoint returns the
|
||||
// new size (the game tail-calls vector::size).
|
||||
// - RenderCurve / RenderHull / RenderControlPoints: a material whose diffuse, ambient, specular and emit colors are
|
||||
// all the given color (power 0); line strips of TVert arrays (normal (0, 0, 1)) allocated with new[] and freed
|
||||
// with operator delete (the game's __ZdlPv; delete[] here, same operator for trivially destructible TVert).
|
||||
// Points are transformed as scale * p + (x, y). Control points are filled squares of half size radius, clamped to
|
||||
// 0, drawn with FillRect (skipped when the right or bottom edge is negative).
|
||||
// - BuildExportString joins "{%d,%d}," with the truncated x and y of every control point.
|
||||
//
|
||||
// Compiler-generated or header-inline code emitted out of line: ~TCurve D1 game @0x0016d804; Subdivision()
|
||||
// game @0x0016cfc0, Subdivision(Subdivision const&) game @0x0016cfe8, Subdivision::operator= game @0x0016d060;
|
||||
// the std::vector<TVec2> / std::vector<Subdivision> instantiations and boost::shared_ptr<TCurve> (checked_delete
|
||||
// game @0x0016d828, sp_counted_base_impl, shared_ptr<TCurve>(TCurve*) game @0x0016d8d8) are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "Curve.h"
|
||||
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/vertexset.h"
|
||||
|
||||
// game @0x001d80e0 (__data, initial value 0.2f)
|
||||
static TReal __ACCEPTABLE_ERROR = 0.2f;
|
||||
|
||||
// game @0x0001c120
|
||||
TVec2 TCurve::GetStartPoint(void) const
|
||||
{
|
||||
return control[0];
|
||||
}
|
||||
|
||||
// game @0x0001c156
|
||||
uint32_t TCurve::FindControlPoint(TVec2 const& point, TReal radius, uint32_t start) const
|
||||
{
|
||||
uint32_t count = (uint32_t)control.size();
|
||||
if (count <= start) {
|
||||
start = 0;
|
||||
}
|
||||
for (uint32_t i = start; i < (uint32_t)control.size(); i++) {
|
||||
TVec2 delta = point - control[i];
|
||||
TReal distanceSquared = delta.LengthSquared();
|
||||
if (distanceSquared <= radius * radius) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// game @0x0001c1e4
|
||||
TVec2 TCurve::GetEndPoint(void) const
|
||||
{
|
||||
TVec2 result;
|
||||
if (control.size() != 0) {
|
||||
result = control[(((uint32_t)control.size() - 1U) / 3) * 3];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x0001c240
|
||||
TVec2 TCurve::GetControlPoint(uint32_t index)
|
||||
{
|
||||
return control[index % (uint32_t)control.size()];
|
||||
}
|
||||
|
||||
// game @0x0001c286
|
||||
str TCurve::BuildExportString(void)
|
||||
{
|
||||
str result;
|
||||
for (uint32_t i = 0; i < (uint32_t)control.size(); i++) {
|
||||
TVec2 point = GetControlPoint(i);
|
||||
str entry = str::getFormatted("{%d,%d},", (int)point.x, (int)point.y);
|
||||
result = result + entry;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x0001c372
|
||||
void TCurve::RenderHull(TColor const& color, TReal scale, TReal x, TReal y) const
|
||||
{
|
||||
TMaterial material;
|
||||
material.mcDiff = color;
|
||||
material.mcAmb = color;
|
||||
material.mcSpec = color;
|
||||
material.mcEmit = color;
|
||||
material.mfPower = 0;
|
||||
TRenderer::GetInstance()->SetMaterial(&material);
|
||||
uint32_t count = (uint32_t)control.size();
|
||||
TVert* vertices = new TVert[count];
|
||||
for (uint32_t i = 0; i < (uint32_t)control.size(); i++) {
|
||||
TVec2 point = control[i];
|
||||
point.x = scale * point.x + x;
|
||||
point.y = scale * point.y + y;
|
||||
vertices[i].pos = TVec3(point, 0);
|
||||
vertices[i].normal = TVec3(0, 0, 1.0f);
|
||||
}
|
||||
TVertexSet vertexSet(vertices, (uint32_t)control.size());
|
||||
TRenderer::GetInstance()->DrawVertices(TRenderer::kDrawLineStrip, vertexSet);
|
||||
delete[] vertices;
|
||||
}
|
||||
|
||||
// game @0x0001c578
|
||||
TReal TCurve::Subdivide(TReal tStart, TReal tEnd, TVec2 const& c0, TVec2 const& c1, TVec2 const& c2, TVec2 const& c3)
|
||||
{
|
||||
TVec2 chordVector = c3 - c0;
|
||||
TReal chord = chordVector.Length();
|
||||
TVec2 leg0 = c1 - c0;
|
||||
TReal polygon = leg0.Length();
|
||||
TVec2 leg1 = c2 - c1;
|
||||
TReal leg1Length = leg1.Length();
|
||||
TVec2 leg2 = c3 - c2;
|
||||
TReal leg2Length = leg2.Length();
|
||||
polygon = polygon + leg1Length + leg2Length;
|
||||
if (polygon - chord <= __ACCEPTABLE_ERROR) {
|
||||
Subdivision segment;
|
||||
segment.start = c0;
|
||||
segment.end = c3;
|
||||
segment.tStart = tStart;
|
||||
segment.tEnd = tEnd;
|
||||
segment.segmentLength = polygon;
|
||||
segment.totalLength = 0.0f;
|
||||
division.push_back(segment);
|
||||
}
|
||||
else {
|
||||
TVec2 points[4][4];
|
||||
points[0][0] = c0;
|
||||
points[0][1] = c1;
|
||||
points[0][2] = c2;
|
||||
points[0][3] = c3;
|
||||
for (int level = 1; level != 4; level++) {
|
||||
for (int k = 0; k <= 3 - level; k++) {
|
||||
points[level][k] = (0.5f * points[level - 1][k + 1]) + (0.5f * points[level - 1][k]);
|
||||
}
|
||||
}
|
||||
TReal middle = (tStart + tEnd) * 0.5f;
|
||||
polygon = Subdivide(tStart, middle, points[0][0], points[1][0], points[2][0], points[3][0]);
|
||||
polygon = polygon + Subdivide(middle, tEnd, points[3][0], points[2][1], points[1][2], points[0][3]);
|
||||
}
|
||||
return polygon;
|
||||
}
|
||||
|
||||
// game @0x0001c912
|
||||
void TCurve::DoSubdivision()
|
||||
{
|
||||
for (uint32_t i = 0; i < (uint32_t)control.size() - 3U; i += 3) {
|
||||
Subdivide(0, 1.0f, control[i], control[i + 1], control[i + 2], control[i + 3]);
|
||||
}
|
||||
length = 0;
|
||||
for (vector<Subdivision>::iterator it = division.begin(); it != division.end(); ++it) {
|
||||
length = length + it->segmentLength;
|
||||
it->totalLength = length;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001c9e8
|
||||
void TCurve::RenderCurve(TColor const& color, TReal scale, TReal x, TReal y) const
|
||||
{
|
||||
if (control.size() > 3) {
|
||||
if (division.empty()) {
|
||||
const_cast<TCurve*>(this)->DoSubdivision();
|
||||
}
|
||||
TMaterial material;
|
||||
material.mcDiff = color;
|
||||
material.mcAmb = color;
|
||||
material.mcSpec = color;
|
||||
material.mcEmit = color;
|
||||
material.mfPower = 0;
|
||||
TRenderer::GetInstance()->SetMaterial(&material);
|
||||
uint32_t count = (uint32_t)division.size();
|
||||
TVert* vertices = new TVert[count + 1];
|
||||
for (uint32_t i = 0; i < (uint32_t)division.size(); i++) {
|
||||
TVec2 point = division[i].start;
|
||||
point.x = scale * point.x + x;
|
||||
point.y = scale * point.y + y;
|
||||
vertices[i].pos = TVec3(point, 0);
|
||||
vertices[i].normal = TVec3(0, 0, 1.0f);
|
||||
}
|
||||
TVec2 last = division.back().end;
|
||||
last.x = scale * last.x + x;
|
||||
last.y = scale * last.y + y;
|
||||
vertices[division.size()].pos = TVec3(last, 0);
|
||||
vertices[division.size()].normal = TVec3(0, 0, 1.0f);
|
||||
TVertexSet vertexSet(vertices, (uint32_t)division.size() + 1);
|
||||
TRenderer::GetInstance()->DrawVertices(TRenderer::kDrawLineStrip, vertexSet);
|
||||
delete[] vertices;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001cd0e
|
||||
TReal TCurve::GetLength(void) const
|
||||
{
|
||||
if (division.empty()) {
|
||||
if (control.size() > 3) {
|
||||
const_cast<TCurve*>(this)->DoSubdivision();
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
// game @0x0001cd46
|
||||
TVec2 TCurve::GetPoint(TReal normalLength, TVec2* pTangent) const
|
||||
{
|
||||
TVec2 result;
|
||||
if (normalLength < 1.0f) {
|
||||
if (0.0f < normalLength || normalLength != normalLength) {
|
||||
TReal remaining = normalLength * GetLength();
|
||||
for (vector<Subdivision>::const_iterator it = division.begin(); it != division.end(); ++it) {
|
||||
if (remaining <= it->segmentLength) {
|
||||
remaining = remaining / it->segmentLength;
|
||||
TVec2 direction = it->end - it->start;
|
||||
result = (direction * remaining) + it->start;
|
||||
if (pTangent != 0) {
|
||||
*pTangent = it->end - it->start;
|
||||
pTangent->Normalize();
|
||||
}
|
||||
break;
|
||||
}
|
||||
remaining = remaining - it->segmentLength;
|
||||
result = it->end;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return GetStartPoint();
|
||||
}
|
||||
return GetEndPoint();
|
||||
}
|
||||
|
||||
// game @0x0001cef8
|
||||
TCurve::TCurve(void) :
|
||||
length(0)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0001cf30
|
||||
TCurveRef TCurve::Create(void)
|
||||
{
|
||||
return TCurveRef(new TCurve());
|
||||
}
|
||||
|
||||
// game @0x0001cf68
|
||||
void TCurve::RenderControlPoints(TReal radius, TColor const& color, TReal scale, TReal x, TReal y) const
|
||||
{
|
||||
for (uint32_t i = 0; i < (uint32_t)control.size(); i++) {
|
||||
TVec2 point = control[i];
|
||||
point.x = scale * point.x + x;
|
||||
point.y = scale * point.y + y;
|
||||
TReal left = 0.0f;
|
||||
if (0.0f <= point.x - radius) {
|
||||
left = point.x - radius;
|
||||
}
|
||||
TReal top = 0.0f;
|
||||
if (0.0f <= point.y - radius) {
|
||||
top = point.y - radius;
|
||||
}
|
||||
TReal right = point.x + radius;
|
||||
TReal bottom = point.y + radius;
|
||||
if (0.0f <= left && 0.0f <= top && 0.0f <= right && 0.0f <= bottom) {
|
||||
if (bottom <= 0.0f) {
|
||||
bottom = 0.0f;
|
||||
}
|
||||
if (right <= 0.0f) {
|
||||
right = 0.0f;
|
||||
}
|
||||
if (top <= 0.0f) {
|
||||
top = 0.0f;
|
||||
}
|
||||
if (left <= 0.0f) {
|
||||
left = 0.0f;
|
||||
}
|
||||
TURect rect((uint32_t)left, (uint32_t)top, (uint32_t)right, (uint32_t)bottom);
|
||||
TRenderer::GetInstance()->FillRect(rect, color, TTextureRef());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001d1d2
|
||||
uint32_t TCurve::AddControlPoint(TVec2 const& point)
|
||||
{
|
||||
control.push_back(point);
|
||||
division.clear();
|
||||
return (uint32_t)control.size();
|
||||
}
|
||||
|
||||
// game @0x0001d204
|
||||
void TCurve::BuildCurve(TLuaTable& table)
|
||||
{
|
||||
control.clear();
|
||||
division.clear();
|
||||
TLuaObjectWrapper* key = 0;
|
||||
TLuaObjectWrapper* pItem;
|
||||
while ((pItem = table.GetNext(&key)) != 0) {
|
||||
if (pItem->IsTable()) {
|
||||
TLuaTable* pPoint = (TLuaTable*)pItem;
|
||||
lua_Number px = pPoint->GetNumber(1.0, 0.0);
|
||||
lua_Number py = pPoint->GetNumber(2.0, 0.0);
|
||||
TVec2 point((float)px, (float)py);
|
||||
AddControlPoint(point);
|
||||
}
|
||||
delete pItem;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001d2f2
|
||||
TCurveRef TCurve::Create(TLuaTable& table)
|
||||
{
|
||||
TCurveRef pCurve(new TCurve());
|
||||
pCurve->BuildCurve(table);
|
||||
return pCurve;
|
||||
}
|
||||
|
||||
// game @0x0001d356
|
||||
TCurve::TCurve(TVec2 const& p0, TVec2 const& p1, TVec2 const& p2, TVec2 const& p3) :
|
||||
length(0)
|
||||
{
|
||||
AddControlPoint(p0);
|
||||
AddControlPoint(p1);
|
||||
AddControlPoint(p2);
|
||||
AddControlPoint(p3);
|
||||
}
|
||||
|
||||
// game @0x0001d3ea
|
||||
TCurveRef TCurve::Create(TVec2 const& p0, TVec2 const& p1, TVec2 const& p2, TVec2 const& p3)
|
||||
{
|
||||
return TCurveRef(new TCurve(p0, p1, p2, p3));
|
||||
}
|
||||
|
||||
// game @0x0001d452
|
||||
bool TCurve::SetControlPoint(uint32_t index, TVec2 const& p)
|
||||
{
|
||||
uint32_t count = (uint32_t)control.size();
|
||||
if (index < count) {
|
||||
control[index] = p;
|
||||
division.clear();
|
||||
}
|
||||
return index < count;
|
||||
}
|
||||
520
port/game/CurveEditor.cpp
Normal file
520
port/game/CurveEditor.cpp
Normal file
|
|
@ -0,0 +1,520 @@
|
|||
// Port of the game's CurveEditor.cpp (Chocolatier 3, Big Splash Games): TCurveEditor, a developer window that
|
||||
// edits a TCurve over a port background, previews an animated sprite travelling along it and copies a
|
||||
// CreateSprite(...) Lua line to the clipboard.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// CurveEditor.h (port/game/CurveEditor.h, unchanged). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): TCurveEditor : TWindow (0x30) pPortRoot 0x30/0x34, pBackground 0x38/0x3c, mode 0x40,
|
||||
// select 0x44, pCurve 0x48/0x4c, port 0x50, spriteImage 0x54, scale 0x58, xOffset 0x5c, yOffset 0x60, farY 0x64,
|
||||
// nearY 0x68, scaleFar 0x6c, scaleNear 0x70, pathMode 0x74, pSprite 0x78/0x7c, time 0x80, pathTime 0x84.
|
||||
// The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - File-level data: _CONTROL_COLOR (0, 0, 1, 1) game @0x0021ee00, _CURVE_COLOR (0, 1, 0, 1) @0x0021ee10 and
|
||||
// _HULL_COLOR (1, 1, 1, 1) @0x0021ee20 (set by the static initializer game @0x001ab990, reached from
|
||||
// __GLOBAL__I game @0x001ab9ea); __data: _scaleMin 0.01f @0x001d8100, _scaleMax 5.0f @0x001d8104,
|
||||
// _CONTROL_RADIUS 5.0f @0x001d8108, _TICK_TIME 20 @0x001d810c.
|
||||
// - Constructor: mode 0, select -1, scale 0.5, offsets 0, farY 0, nearY 600, scaleFar = scaleNear = 1, pathMode
|
||||
// LOOP (2), pathTime 5000 (time is left unset); creates the curve, the animated sprite (layer 0) and the root
|
||||
// sprite (layer 0, no texture), in that order.
|
||||
// - Init registers the Lua functions SetAnimScale, UpdateAnimTime, UpdateAnimLayer and SetAnimSprite, loads the
|
||||
// "background" texture into a sprite (center (0, 0); its flags are the ROOT sprite's flags | kUseCenter, as in the
|
||||
// game) and adds background and animated sprite to the root sprite.
|
||||
// - CollectBuildingData reads the "name" of the port table into a local only (the member port is never set in the
|
||||
// game), and for each entry of "buildings" creates a sprite from texture "ports/<name>/<building name>" (layer,
|
||||
// scale, x, y). CollectSpriteData: for each entry of "sprites" the image is images[1] or "image"; layer from
|
||||
// "layer" (the game's double to unsigned conversion, clamped to 0 .. 0xffffffff), or behind.layer - 1 (0 when 0)
|
||||
// when a "behind" table exists; entries with a "path" table are skipped (the path table is not released in the
|
||||
// game); others become static sprites.
|
||||
// - SetScale sizes the "background" image to the scaled window size (clamped at 0), centers it and the root
|
||||
// sprite; without a background image only the root sprite is centered.
|
||||
// - OnMessage: slider messages (type 9) from scaleslider / nearslider / farslider; slider value v maps to
|
||||
// _scaleMin + (_scaleMax - _scaleMin) * v for the planes.
|
||||
// - AnimateSprite: path time wraps modulo pathTime; BOUNCE mirrors t = 2 * time / pathTime when > 1. The frame is
|
||||
// chosen from the tangent as in TPathSprite::Update and the remainder angle (radians) becomes the sprite's
|
||||
// rotation; then the matrix is scaled by scale and again by scale (times the far / near interpolation).
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFTYPEDEF_DC: TCurveEditorDynamicCreate game @0x0001e076, ClassId game @0x0001d4a4, GetTypeName game
|
||||
// game @0x0001d4ae, IsKindOf game @0x0016dcd0. ~TCurveEditor: D1 game @0x0001dd46, D0 game @0x0001e0b2.
|
||||
// TWindow::GetCast<TCurveEditor> game @0x00172350, GetChildWindowCast<TCurveEditor> game @0x00172384.
|
||||
// Lua registration instances: lua_pushdirectclosure<TCurveEditor, void (TCurveEditor::*)(float)> game
|
||||
// @0x0016d9ac, <(void)> game @0x0016d9f8, <(str)> game @0x0016da44; LPCD::ReturnSpecialization<void>::Call<
|
||||
// TCurveEditor, float> game @0x0016dbc0, <TCurveEditor, str> game @0x0016dc58; DirectCallMemberDispatcherHelper
|
||||
// <(float)> game @0x0016dc14, <(str)> game @0x0016dcfc, <(void)> game @0x0016dd40.
|
||||
// Pause, Resume, ScreenToCurve and CurveToScreen have no code in the game binary.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "CurveEditor.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/image.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/modalwindow.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/slider.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/textedit.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
PFTYPEIMPL_DC(TCurveEditor);
|
||||
|
||||
// game @0x0021ee00, @0x0021ee10, @0x0021ee20
|
||||
static TColor _CONTROL_COLOR(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
static TColor _CURVE_COLOR(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
static TColor _HULL_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
// game @0x001d8100, @0x001d8104, @0x001d8108, @0x001d810c
|
||||
static float _scaleMin = 0.01f;
|
||||
static float _scaleMax = 5.0f;
|
||||
static float _CONTROL_RADIUS = 5.0f;
|
||||
static int32_t _TICK_TIME = 20;
|
||||
|
||||
// The game's double to unsigned conversion: clamped to 0 .. 4294967295.
|
||||
static uint32_t DoubleToUnsigned(double value)
|
||||
{
|
||||
double clamped = value;
|
||||
if (4294967295.0 <= clamped) {
|
||||
clamped = 4294967295.0;
|
||||
}
|
||||
if (clamped <= 0.0) {
|
||||
clamped = 0.0;
|
||||
}
|
||||
return (uint32_t)clamped;
|
||||
}
|
||||
|
||||
// game @0x0001d4ba
|
||||
bool TCurveEditor::OnMouseUp(TPoint const& point)
|
||||
{
|
||||
bool handled = select >= 0;
|
||||
if (handled) {
|
||||
select = -1;
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
// game @0x0001d4e8
|
||||
bool TCurveEditor::OnKeyUp(char key)
|
||||
{
|
||||
bool reset;
|
||||
if (key == 'A') {
|
||||
reset = mode == ADDPOINT;
|
||||
}
|
||||
else {
|
||||
if (key != 'D') {
|
||||
return false;
|
||||
}
|
||||
reset = mode == DELETEPOINT;
|
||||
}
|
||||
if (reset) {
|
||||
mode = MOVEPOINT;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0001d514
|
||||
void TCurveEditor::SetScalePlanes(TReal near, TReal far)
|
||||
{
|
||||
scaleNear = near;
|
||||
scaleFar = far;
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x0001d538
|
||||
bool TCurveEditor::OnKeyDown(char key, uint32_t flags)
|
||||
{
|
||||
if (key == 'A') {
|
||||
mode = ADDPOINT;
|
||||
}
|
||||
else if (key == 'D') {
|
||||
mode = DELETEPOINT;
|
||||
}
|
||||
else if (key == 'C') {
|
||||
str pathString = pCurve->BuildExportString();
|
||||
TReal nearScale = scaleNear;
|
||||
TReal farScale = scaleFar;
|
||||
int32_t layer = pSprite->GetLayer();
|
||||
str line = str::getFormatted(
|
||||
"CreateSprite(%s, { image='%s', time=%lu, motion='loop', layer=%d, scaleFar=%01.3f, scaleNear=%01.3f, path={%s}, })",
|
||||
port.c_str(), spriteImage.c_str(), (unsigned long)pathTime, layer, (double)farScale, (double)nearScale,
|
||||
pathString.c_str());
|
||||
TPlatform::GetInstance()->StringToClipboard(line);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0001d68e
|
||||
void TCurveEditor::AnimateSprite(void)
|
||||
{
|
||||
TReal t;
|
||||
if (pathMode == BOUNCE) {
|
||||
time = time % pathTime;
|
||||
double timeValue = (double)time;
|
||||
t = (float)((timeValue + timeValue) / (double)pathTime);
|
||||
if (1.0f < t) {
|
||||
t = 2.0f - t;
|
||||
}
|
||||
}
|
||||
else {
|
||||
time = time % pathTime;
|
||||
t = (float)time / (float)pathTime;
|
||||
}
|
||||
TVec2 tangent;
|
||||
TVec2 point = pCurve->GetPoint(t, &tangent);
|
||||
TReal arc = acosf(tangent.y);
|
||||
double angle = ((double)arc * -180.0) / 3.141592653589793 + 180.0;
|
||||
if (tangent.x < 0.0f) {
|
||||
angle = 360.0 - angle;
|
||||
}
|
||||
double step = 360.0 / (double)pSprite->GetNumFrames();
|
||||
uint32_t frames = pSprite->GetNumFrames();
|
||||
uint32_t frame = DoubleToUnsigned(angle / step + 0.5) % frames;
|
||||
pSprite->SetCurrentFrame((int32_t)frame);
|
||||
pSprite->GetDrawSpec().mMatrix = TMat3::GetRotation((float)(((angle - step * (double)frame) * 3.141592653589793) / 180.0));
|
||||
pSprite->GetDrawSpec().mMatrix.Scale(scale, scale);
|
||||
TReal planeScale = scale;
|
||||
if (farY != nearY) {
|
||||
planeScale = planeScale * (scaleFar + ((point.y - farY) / (nearY - farY)) * (scaleNear - scaleFar));
|
||||
}
|
||||
pSprite->GetDrawSpec().mMatrix.Scale(planeScale, planeScale);
|
||||
pSprite->GetDrawSpec().mMatrix[2] = TVec3(point, 1.0f);
|
||||
}
|
||||
|
||||
// game @0x0001da46
|
||||
bool TCurveEditor::OnTaskAnimate(void)
|
||||
{
|
||||
time = time + _TICK_TIME;
|
||||
AnimateSprite();
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0001da7e
|
||||
void TCurveEditor::UpdateTime(void)
|
||||
{
|
||||
TTextEdit* pEdit = GetChildWindowCast<TTextEdit>(GetParent(), "time", -1);
|
||||
if (pEdit != 0) {
|
||||
pathTime = pEdit->GetText().to_int();
|
||||
if (pathTime == 0) {
|
||||
pathTime = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001db1e
|
||||
void TCurveEditor::UpdateLayer(void)
|
||||
{
|
||||
TTextEdit* pEdit = GetChildWindowCast<TTextEdit>(GetParent(), "layer", -1);
|
||||
if (pEdit != 0) {
|
||||
int32_t layer = pEdit->GetText().to_int();
|
||||
if (pSprite) {
|
||||
pSprite->SetLayer(layer);
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001dbca
|
||||
void TCurveEditor::Draw(void)
|
||||
{
|
||||
if (pPortRoot) {
|
||||
TBegin2d begin2d;
|
||||
pPortRoot->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
begin2d.Done();
|
||||
}
|
||||
TBegin2d begin2d;
|
||||
pCurve->RenderHull(_HULL_COLOR, scale, xOffset, yOffset);
|
||||
pCurve->RenderCurve(_CURVE_COLOR, scale, xOffset, yOffset);
|
||||
pCurve->RenderControlPoints(_CONTROL_RADIUS, _CONTROL_COLOR, scale, xOffset, yOffset);
|
||||
begin2d.Done();
|
||||
}
|
||||
|
||||
// game @0x0001dd08
|
||||
void TCurveEditor::SetCurve(TCurveRef pNewCurve)
|
||||
{
|
||||
pCurve = pNewCurve;
|
||||
select = -1;
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x0001de2e
|
||||
TCurveEditor::TCurveEditor(void) :
|
||||
mode(MOVEPOINT),
|
||||
select(-1),
|
||||
scale(0.5f),
|
||||
xOffset(0),
|
||||
yOffset(0),
|
||||
farY(0),
|
||||
nearY(600.0f),
|
||||
scaleFar(1.0f),
|
||||
scaleNear(1.0f),
|
||||
pathMode(LOOP),
|
||||
pathTime(5000)
|
||||
{
|
||||
pCurve = TCurve::Create();
|
||||
pSprite = TAnimatedSprite::Create(0);
|
||||
pPortRoot = TSprite::Create(0, TTextureRef());
|
||||
}
|
||||
|
||||
// game @0x0001dd46 (D1), game @0x0001e0b2 (D0)
|
||||
TCurveEditor::~TCurveEditor(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0001e1a0
|
||||
void TCurveEditor::SetSprite(str name)
|
||||
{
|
||||
spriteImage = str("ports/animations/") + name;
|
||||
TAnimatedTextureRef pTexture = TAnimatedTexture::Get(spriteImage, "", "");
|
||||
if (pTexture && pSprite) {
|
||||
pSprite->SetTexture(pTexture);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001e332
|
||||
void TCurveEditor::SetScale(TReal newScale)
|
||||
{
|
||||
scale = newScale;
|
||||
TReal widthScaled = (TReal)(uint32_t)(GetParentRelativeRect().x2 - GetParentRelativeRect().x1) * newScale;
|
||||
if (widthScaled <= 0.0f) {
|
||||
widthScaled = 0.0f;
|
||||
}
|
||||
uint32_t width = (uint32_t)widthScaled;
|
||||
TReal heightScaled = newScale * (TReal)(uint32_t)(GetParentRelativeRect().y2 - GetParentRelativeRect().y1);
|
||||
if (heightScaled <= 0.0f) {
|
||||
heightScaled = 0.0f;
|
||||
}
|
||||
uint32_t height = (uint32_t)heightScaled;
|
||||
TImage* pImage = GetChildWindowCast<TImage>(GetParent(), "background", -1);
|
||||
if (pImage == 0) {
|
||||
if (pPortRoot) {
|
||||
xOffset = (float)((uint32_t)(GetParentRelativeRect().x2 - GetParentRelativeRect().x1) - width >> 1);
|
||||
yOffset = (float)((uint32_t)(GetParentRelativeRect().y2 - GetParentRelativeRect().y1) - height >> 1);
|
||||
pPortRoot->GetDrawSpec().mMatrix.Identity();
|
||||
pPortRoot->GetDrawSpec().mMatrix[2] = TVec3(xOffset, yOffset, 1.0f);
|
||||
pPortRoot->GetDrawSpec().mMatrix.Scale(scale, scale);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pImage->SetWindowSize(width, height);
|
||||
TTextureRef pTexture = pImage->GetTexture();
|
||||
pImage->SetTexture(pTexture, scale);
|
||||
uint32_t x = (uint32_t)(GetParentRelativeRect().x2 - GetParentRelativeRect().x1) - width >> 1;
|
||||
uint32_t y = (uint32_t)(GetParentRelativeRect().y2 - GetParentRelativeRect().y1) - height >> 1;
|
||||
pImage->SetWindowSize(width, height);
|
||||
pImage->SetWindowPos(x, y);
|
||||
xOffset = (float)x;
|
||||
yOffset = (float)y;
|
||||
if (pPortRoot) {
|
||||
pPortRoot->GetDrawSpec().mMatrix.Identity();
|
||||
pPortRoot->GetDrawSpec().mMatrix.Scale(scale, scale);
|
||||
pPortRoot->GetDrawSpec().mMatrix[2] = TVec3(xOffset, yOffset, 1.0f);
|
||||
}
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x0001e6ee
|
||||
bool TCurveEditor::OnMessage(TMessage* pMessage)
|
||||
{
|
||||
if (pMessage->mType != TMessage::kSliderValChanged) {
|
||||
return false;
|
||||
}
|
||||
str& name = pMessage->mName;
|
||||
TWindow* pWindow = GetChildWindow(name, -1);
|
||||
if (pWindow == 0) {
|
||||
return false;
|
||||
}
|
||||
TSlider* pSlider = pWindow->GetCast<TSlider>();
|
||||
if (pSlider == 0) {
|
||||
return false;
|
||||
}
|
||||
TReal value = (TReal)pSlider->GetValue();
|
||||
if (name == str("scaleslider")) {
|
||||
SetScale(value);
|
||||
}
|
||||
else {
|
||||
TReal nearValue;
|
||||
TReal farValue;
|
||||
if (name == str("nearslider")) {
|
||||
farValue = scaleFar;
|
||||
nearValue = _scaleMin + (_scaleMax - _scaleMin) * value;
|
||||
}
|
||||
else if (name == str("farslider")) {
|
||||
farValue = _scaleMin + (_scaleMax - _scaleMin) * value;
|
||||
nearValue = scaleNear;
|
||||
}
|
||||
else {
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return false;
|
||||
}
|
||||
SetScalePlanes(nearValue, farValue);
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0001e89c
|
||||
void TCurveEditor::CollectBuildingData(TLuaTable* pPort)
|
||||
{
|
||||
str portName = pPort->GetString("name", "");
|
||||
str prefix = (str("ports/") + portName) + str("/");
|
||||
TLuaTable* pBuildings = pPort->GetTable("buildings");
|
||||
if (pBuildings != 0) {
|
||||
TLuaObjectWrapper* key = 0;
|
||||
TLuaTable* pItem = (TLuaTable*)pBuildings->GetNext(&key);
|
||||
while (pItem != 0) {
|
||||
str buildingName = pItem->GetString("name", "");
|
||||
lua_Number layer = pItem->GetNumber("layer", 0.0);
|
||||
str textureName = prefix + buildingName;
|
||||
TTextureRef pTexture = TTexture::Get(textureName, 0);
|
||||
TSpriteRef pBuilding = TSprite::Create((int)layer, pTexture);
|
||||
lua_Number buildingScale = pItem->GetNumber("scale", 1.0);
|
||||
pBuilding->GetDrawSpec().mMatrix.Scale((float)buildingScale, (float)buildingScale);
|
||||
float x = (float)pItem->GetNumber("x", 0.0);
|
||||
float y = (float)pItem->GetNumber("y", 0.0);
|
||||
pBuilding->GetDrawSpec().mMatrix[2] = TVec3(x, y, 1.0f);
|
||||
pPortRoot->AddChild(pBuilding);
|
||||
delete pItem;
|
||||
pItem = (TLuaTable*)pBuildings->GetNext(&key);
|
||||
}
|
||||
delete pBuildings;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001ed18
|
||||
void TCurveEditor::Init(TWindowStyle& style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "SetAnimScale", this, TCurveEditor::SetScale);
|
||||
ScriptRegisterMemberDirect(script, "UpdateAnimTime", this, TCurveEditor::UpdateTime);
|
||||
ScriptRegisterMemberDirect(script, "UpdateAnimLayer", this, TCurveEditor::UpdateLayer);
|
||||
ScriptRegisterMemberDirect(script, "SetAnimSprite", this, TCurveEditor::SetSprite);
|
||||
str backgroundName = style.GetString("background", "");
|
||||
TTextureRef pTexture = TTexture::Get(backgroundName, 0);
|
||||
pBackground = TSprite::Create(0, pTexture);
|
||||
pBackground->GetDrawSpec().mCenter = TVec2(0, 0);
|
||||
pBackground->GetDrawSpec().mFlags = pPortRoot->GetDrawSpec().mFlags | 8;
|
||||
pPortRoot->AddChild(pBackground);
|
||||
pPortRoot->AddChild(pSprite);
|
||||
}
|
||||
|
||||
// game @0x0001f122
|
||||
void TCurveEditor::CollectSpriteData(TLuaTable* pPort)
|
||||
{
|
||||
TLuaTable* pSprites = pPort->GetTable("sprites");
|
||||
if (pSprites != 0) {
|
||||
TLuaObjectWrapper* key = 0;
|
||||
TLuaTable* pItem = (TLuaTable*)pSprites->GetNext(&key);
|
||||
while (pItem != 0) {
|
||||
str imageName;
|
||||
TLuaTable* pImages = pItem->GetTable("images");
|
||||
if (pImages != 0) {
|
||||
imageName = pImages->GetString(1.0, "");
|
||||
delete pImages;
|
||||
}
|
||||
if (imageName.length() == 0) {
|
||||
imageName = pItem->GetString("image", "");
|
||||
}
|
||||
int32_t layer = (int32_t)DoubleToUnsigned(pItem->GetNumber("layer", 0.0));
|
||||
TLuaTable* pBehind = pItem->GetTable("behind");
|
||||
if (pBehind != 0) {
|
||||
uint32_t behind = DoubleToUnsigned(pBehind->GetNumber("layer", 0.0));
|
||||
layer = (int32_t)(behind - 1 + (uint32_t)(behind == 0));
|
||||
delete pBehind;
|
||||
}
|
||||
TLuaTable* pPath = pItem->GetTable("path");
|
||||
if (pPath == 0) {
|
||||
TTextureRef pTexture = TTexture::Get(imageName, 0);
|
||||
TSpriteRef pStatic = TSprite::Create(layer, pTexture);
|
||||
lua_Number spriteScale = pItem->GetNumber("scale", 1.0);
|
||||
pStatic->GetDrawSpec().mMatrix.Scale((float)spriteScale, (float)spriteScale);
|
||||
float x = (float)pItem->GetNumber("x", 0.0);
|
||||
float y = (float)pItem->GetNumber("y", 0.0);
|
||||
pStatic->GetDrawSpec().mMatrix[2] = TVec3(x, y, 1.0f);
|
||||
pPortRoot->AddChild(pStatic);
|
||||
}
|
||||
delete pItem;
|
||||
pItem = (TLuaTable*)pSprites->GetNext(&key);
|
||||
}
|
||||
delete pSprites;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001f676
|
||||
void TCurveEditor::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
FindParentModal()->SetDefaultFocus(this);
|
||||
TLuaTable* pPort = style.GetTable("port");
|
||||
CollectBuildingData(pPort);
|
||||
CollectSpriteData(pPort);
|
||||
if (pPort != 0) {
|
||||
delete pPort;
|
||||
}
|
||||
TSlider* pSlider = GetChildWindowCast<TSlider>(this, "scaleslider", -1);
|
||||
if (pSlider != 0) {
|
||||
pSlider->SetValue(scale, false);
|
||||
}
|
||||
pSlider = GetChildWindowCast<TSlider>(this, "farslider", -1);
|
||||
if (pSlider != 0) {
|
||||
pSlider->SetValue((scaleFar - _scaleMin) / (_scaleMax - _scaleMin), false);
|
||||
}
|
||||
pSlider = GetChildWindowCast<TSlider>(this, "nearslider", -1);
|
||||
if (pSlider != 0) {
|
||||
pSlider->SetValue((scaleNear - _scaleMin) / (_scaleMax - _scaleMin), false);
|
||||
}
|
||||
StartWindowAnimation(_TICK_TIME, true, true, false);
|
||||
}
|
||||
|
||||
// game @0x0001f870
|
||||
bool TCurveEditor::OnMouseDown(TPoint const& point)
|
||||
{
|
||||
TVec2 curvePoint((float)point.x, (float)point.y);
|
||||
curvePoint.x = (curvePoint.x - xOffset) / scale;
|
||||
curvePoint.y = (curvePoint.y - yOffset) / scale;
|
||||
if (mode == ADDPOINT) {
|
||||
uint32_t count = pCurve->AddControlPoint(curvePoint);
|
||||
select = (int32_t)count - 1;
|
||||
}
|
||||
else {
|
||||
if (mode == DELETEPOINT) {
|
||||
return true;
|
||||
}
|
||||
uint32_t found = pCurve->FindControlPoint(curvePoint, _CONTROL_RADIUS, 0);
|
||||
uint32_t count = pCurve->GetPointCount();
|
||||
if (found < count) {
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
select = (int32_t)found;
|
||||
return true;
|
||||
}
|
||||
if (select < 0) {
|
||||
return true;
|
||||
}
|
||||
select = -1;
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0001f954
|
||||
bool TCurveEditor::OnMouseMove(TPoint const& point)
|
||||
{
|
||||
bool handled = select >= 0;
|
||||
if (handled) {
|
||||
TVec2 curvePoint((float)point.x, (float)point.y);
|
||||
curvePoint.x = (curvePoint.x - xOffset) / scale;
|
||||
curvePoint.y = (curvePoint.y - yOffset) / scale;
|
||||
pCurve->SetControlPoint((uint32_t)select, curvePoint);
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
103
port/game/CustomItems.cpp
Normal file
103
port/game/CustomItems.cpp
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
// Port of the game's custom item helpers (Chocolatier 3, Big Splash Games): LoadAppearance (product table ->
|
||||
// layer texture names + tints) and BuildItemAppearance (layer textures -> child sprites). Declarations from the
|
||||
// shipped CustomItems.h (port/game/CustomItems.h, unchanged). Ported from the shipped game binary (release build,
|
||||
// addresses "game @"); the three functions are free functions with no DWARF, so the control flow is read from the
|
||||
// decompile plus the disassembly (string literals read from __cstring).
|
||||
//
|
||||
// Strings from the game's __cstring: "appearance", "" (default of the string reads), "code", "name", "_big",
|
||||
// "items/", "custom/", "_highlight".
|
||||
// - LoadAppearanceInternal (static in the original source, a global symbol in the binary; regparm: table in eax,
|
||||
// appearance in edx, tints in ecx) walks a table of layers: a string entry is "custom/" + the string with the tint
|
||||
// (1,1,1,1); a table entry is "custom/" + entry[1] (string) with the tint (entry[2], entry[3], entry[4], 1.0)
|
||||
// (numbers read with default 0). Each wrapper returned by GetNext is deleted (vtable slot 1 = deleting dtor).
|
||||
// The wrapper is used as a TLuaTable for the table entries (the game calls TLuaTable::GetString/GetNumber on it).
|
||||
// - LoadAppearance: "appearance" sub table -> Internal and delete it; else "code" -> "items/" + code + "_big";
|
||||
// else "name" -> "items/" + name + "_big"; else Internal on the product table itself. The simple forms use the
|
||||
// tint (1,1,1,1).
|
||||
// - BuildItemAppearance: for every layer a sprite with the layer texture on layer n (tinted), then the optional
|
||||
// texture "<layer>_highlight" on layer n+1 (only when it exists); the layer counter advances by 1 or 2. The
|
||||
// second overload declared in the header (TLuaTable*) is not in the shipped binary.
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "CustomItems.h"
|
||||
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/luatable.h"
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
using namespace std;
|
||||
|
||||
// game @0x0001f9e4
|
||||
void LoadAppearanceInternal(TLuaTable& table, vector<str>& appearance, vector<TColor>& tints);
|
||||
|
||||
// game @0x0001f9e4
|
||||
void LoadAppearanceInternal(TLuaTable& table, vector<str>& appearance, vector<TColor>& tints)
|
||||
{
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaObjectWrapper* pEntry;
|
||||
while ((pEntry = table.GetNext(&key)) != NULL) {
|
||||
if (pEntry->IsString()) {
|
||||
appearance.push_back(str("custom/") + pEntry->AsString());
|
||||
tints.push_back(TColor(1, 1, 1, 1));
|
||||
} else if (pEntry->IsTable()) {
|
||||
TLuaTable* pTable = static_cast<TLuaTable*>(pEntry);
|
||||
str name = str("custom/") + pTable->GetString((lua_Number)1, str(""));
|
||||
float r = (float)pTable->GetNumber((lua_Number)2, 0);
|
||||
float g = (float)pTable->GetNumber((lua_Number)3, 0);
|
||||
float b = (float)pTable->GetNumber((lua_Number)4, 0);
|
||||
appearance.push_back(name);
|
||||
tints.push_back(TColor(r, g, b, 1));
|
||||
}
|
||||
delete pEntry;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001fcd2
|
||||
void LoadAppearance(TLuaTable& productTable, vector<str>& appearance, vector<TColor>& tints)
|
||||
{
|
||||
TLuaTable* pAppearance = productTable.GetTable("appearance");
|
||||
if (pAppearance != NULL) {
|
||||
LoadAppearanceInternal(*pAppearance, appearance, tints);
|
||||
delete pAppearance;
|
||||
} else {
|
||||
str code = productTable.GetString("code", str(""));
|
||||
if (code.length() != 0) {
|
||||
appearance.push_back(str("items/") + code + str("_big"));
|
||||
tints.push_back(TColor(1, 1, 1, 1));
|
||||
} else {
|
||||
str name = productTable.GetString("name", str(""));
|
||||
if (name.length() != 0) {
|
||||
appearance.push_back(str("items/") + name + str("_big"));
|
||||
tints.push_back(TColor(1, 1, 1, 1));
|
||||
} else {
|
||||
LoadAppearanceInternal(productTable, appearance, tints);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0001fff4
|
||||
void BuildItemAppearance(TSpriteRef pBase, vector<str> const& appearance, vector<TColor> const& tints, TReal scale)
|
||||
{
|
||||
pBase->RemoveChildren();
|
||||
if (scale != 1.0f) {
|
||||
pBase->GetDrawSpec().mMatrix.Scale(scale, scale);
|
||||
}
|
||||
int layer = 0;
|
||||
for (int i = 0; i < (int)appearance.size(); i++) {
|
||||
TTextureRef pTexture = TTexture::Get(appearance[i], 0);
|
||||
TSpriteRef pSprite = TSprite::Create(layer, pTexture);
|
||||
pSprite->GetDrawSpec().mTint = tints[i];
|
||||
pBase->AddChild(pSprite);
|
||||
int nextLayer = layer + 1;
|
||||
TTextureRef pHighlight = TTexture::Get(appearance[i] + str("_highlight"), 0);
|
||||
if (pHighlight) {
|
||||
TSpriteRef pHighlightSprite = TSprite::Create(nextLayer, pHighlight);
|
||||
pBase->AddChild(pHighlightSprite);
|
||||
nextLayer = layer + 2;
|
||||
}
|
||||
layer = nextLayer;
|
||||
}
|
||||
}
|
||||
348
port/game/DookieDropper.cpp
Normal file
348
port/game/DookieDropper.cpp
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
// Port of the game's DookieDropper.cpp (Chocolatier 3, Big Splash Games): DookieDropper, the factory icon of the
|
||||
// ledger window (a Rollover window that shows a factory's current product, its ingredient supply bars and a timer
|
||||
// face), and DookieCollector, the small TWindowSpider the LedgerWindow uses to collect the DookieDropper children
|
||||
// into a list. Ported from the shipped game binary (release build, addresses "game @"); declarations from the
|
||||
// original DookieDropper.h (port/game/DookieDropper.h, unchanged). DookieCollector is not in that header (it is
|
||||
// defined in this .cpp in the game); the ledger window declares the same interface locally.
|
||||
//
|
||||
// Layout (game, i386): Rollover/TWindow base 0x0..0x54, currentCode 0x54, pProduct 0x58, ingredientCount 0x60,
|
||||
// production 0x64, stalled 0x68, ingredientY 0x6c, barHeight 0x70, ingredientName[6] 0x74, ingredientImage[6] 0x8c,
|
||||
// pIdleFactory 0xbc, colorFull 0xc4, colorMedium 0xd4, colorTrouble 0xe4, playerRank 0xf4, time 0xf8, pTimer 0xfc,
|
||||
// pTimerHand 0x104; sizeof 0x10c (DynamicCreate allocates 0x10c bytes). The header matches. TWindow: mRect 0x10
|
||||
// (x1 0x10, x2 0x18), mName 0x20. DookieCollector: TWindowSpider vptr 0x0, the list reference 0x4.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float/double constants read from the binary: 1.0f (@0x001ab6e4), 1000.0f (@0x001ab6fc), 2000.0f (@0x001ab704),
|
||||
// 666.0f (@0x001ab720), 500.0f (@0x001ab724), 0.25f (@0x001ab728), 0.03125f (@0x001ab72c), 0.75f (@0x001ab730),
|
||||
// 0.5f (@0x001ab6ec), 3.0f (@0x001ab6f4), 4.0f (@0x001ab734); doubles pi (@0x001ab4a8), 6.0 (@0x001ab518),
|
||||
// -0.5 (@0x001ab490), 2.5 (@0x001ab520), 0.5 (@0x001ab488). The weeksPerColumn table (float array of 7 plus the 0.0f the game reads for rank 7, indexed by
|
||||
// the player rank) is at 0x00192b40 in the game's __const: 4, 6, 8, 8, 8, 10, 10.
|
||||
// - Strings from the game's __cstring: "Player" (@0x001593a4), "factories" (@0x001593ac), "_AllProducts"
|
||||
// (@0x001593c0), "counts" (@0x001593d0), "current", "" (@0x001581bc), "count", "production", "stall", "rank",
|
||||
// "%lu", "items/", "supply", "itemx", "itemy", "ingredienty", "barHeight", "countx", "county",
|
||||
// "image/timer_face_small", "image/timer_hand_small", "image/factory_idle_help".
|
||||
// - PostChildrenInit defaults (doubles from the high words of the immediates): itemx 18, itemy 86, ingredienty 58,
|
||||
// barHeight 42, countx 57, county 86.
|
||||
// - Double and float to unsigned conversions are the game's SSE sequences (sseconv.h; FloatToUInt below is the float
|
||||
// form of the same sequence, cvttss2si with the 2^31 / 2^32 range handling). The window width is
|
||||
// (double)(uint32_t)(x2 - x1) as the game converts it.
|
||||
// - The constructor leaves ingredientCount, ingredientY and barHeight uninitialised, as the game does.
|
||||
// - Draw ends with the TBegin2d destructor (inlined Done).
|
||||
//
|
||||
// Macro-generated in the game: ClassId / GetTypeName / DynamicCreate / IsKindOf (PFTYPEIMPL_DC below).
|
||||
// std::list<DookieDropper*> instantiations (push_back @0x0017030c, _M_insert @0x001702e0, _M_create_node @0x00170298,
|
||||
// _M_clear @0x00170394 and the rest) are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "DookieDropper.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "CustomItems.h"
|
||||
#include "sseconv.h"
|
||||
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/mat.h"
|
||||
#include "pf/pflua.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/text.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/window.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
|
||||
// game @0x00020ad2 (GetTypeName, "DookieDropper")
|
||||
// game @0x00020ac8 (ClassId: the DynamicCreate function address)
|
||||
// game @0x00021e90 (DookieDropperDynamicCreate: new DookieDropper, sizeof 0x10c)
|
||||
// game @0x0016e278 (IsKindOf)
|
||||
PFTYPEIMPL_DC(DookieDropper);
|
||||
|
||||
// Indexed by the player rank (1..7 in the game's scripts), so rank 7 reads the float after the seven values: the binary
|
||||
// holds 0.0f there (@0x00192b5c, padding before the next 16-byte aligned constant), so the table has 8 entries.
|
||||
static float const weeksPerColumn[8] = { 4.0f, 6.0f, 8.0f, 8.0f, 8.0f, 10.0f, 10.0f, 0.0f };
|
||||
|
||||
// float -> uint32_t as the game codes it (SSE): x >= 2^31 has 2^31 subtracted before cvttss2si and added back as
|
||||
// bit 31; x >= 2^32 ORs in 0xFFFFFFFF.
|
||||
static uint32_t FloatToUInt(float x)
|
||||
{
|
||||
bool big = (2147483648.0f <= x);
|
||||
float y = x - (big ? 2147483648.0f : 0.0f);
|
||||
uint32_t r = (uint32_t)SseDoubleToInt32((double)y) + (big ? 0x80000000u : 0u);
|
||||
if (4294967296.0f <= x) {
|
||||
r |= 0xFFFFFFFFu;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// game @0x000218f4
|
||||
DookieDropper::DookieDropper(void)
|
||||
: Rollover(), currentCode(), pProduct(), production(0), stalled(false), time(2000), pTimer(), pTimerHand()
|
||||
{
|
||||
pProduct = TSprite::Create(0, TTextureRef());
|
||||
playerRank = 1;
|
||||
colorFull.Init(0x32, 0xcd, 0x1e, 0xff);
|
||||
colorMedium.Init(0xff, 0xfc, 0xf, 0xff);
|
||||
colorTrouble.Init(0xff, 0xe, 0xe, 0xff);
|
||||
pTimer = TSprite::Create(0, TTexture::Get(str("image/timer_face_small"), 0));
|
||||
pTimerHand = TSprite::Create(0, TTexture::Get(str("image/timer_hand_small"), 0));
|
||||
pTimer->AddChild(pTimerHand);
|
||||
pIdleFactory = TTexture::Get(str("image/factory_idle_help"), 0);
|
||||
}
|
||||
|
||||
// game @0x00020ee8 (D0) game @0x0002106e (D1)
|
||||
DookieDropper::~DookieDropper()
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x00020aee
|
||||
void DookieDropper::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
Rollover::PostChildrenInit(style);
|
||||
|
||||
TReal itemX = (TReal)style.GetNumber(str("itemx"), 18.0);
|
||||
TReal itemY = (TReal)style.GetNumber(str("itemy"), 86.0);
|
||||
pProduct->GetDrawSpec().mMatrix[2] = TVec3(itemX, itemY, 1.0f);
|
||||
ingredientY = (TReal)style.GetNumber(str("ingredienty"), 58.0);
|
||||
barHeight = (TReal)style.GetNumber(str("barHeight"), 42.0);
|
||||
TReal countX = (TReal)style.GetNumber(str("countx"), 57.0);
|
||||
TReal countY = (TReal)style.GetNumber(str("county"), 86.0);
|
||||
pTimer->GetDrawSpec().mMatrix[2] = TVec3(countX, countY, 1.0f);
|
||||
}
|
||||
|
||||
// game @0x00020adc
|
||||
void DookieDropper::StartAnimation(void)
|
||||
{
|
||||
time = 0;
|
||||
}
|
||||
|
||||
// game @0x00020d40
|
||||
void DookieDropper::Animate(void)
|
||||
{
|
||||
if (time < 2000) {
|
||||
uint32_t next = time + 0x32;
|
||||
uint32_t limit = 2000;
|
||||
if (next < 0x7d1) {
|
||||
limit = next;
|
||||
}
|
||||
time = limit;
|
||||
|
||||
if (!stalled && production != 0) {
|
||||
if (pTimerHand) {
|
||||
TReal angle = (TReal)((double)((TReal)time / 2000.0f + (TReal)time / 2000.0f) * 3.141592653589793);
|
||||
pTimerHand->GetDrawSpec().mMatrix = TMat3::GetRotation(angle);
|
||||
}
|
||||
|
||||
if (pProduct) {
|
||||
uint32_t divisor;
|
||||
TReal divisorF;
|
||||
if (production < 10) {
|
||||
divisor = 2000;
|
||||
divisorF = 2000.0f;
|
||||
} else if (production < 0x1e) {
|
||||
divisor = 1000;
|
||||
divisorF = 1000.0f;
|
||||
} else if (production < 0x32) {
|
||||
divisor = 0x29a;
|
||||
divisorF = 666.0f;
|
||||
} else {
|
||||
divisor = 500;
|
||||
divisorF = 500.0f;
|
||||
}
|
||||
TReal scale = ((TReal)(time % divisor + 1) * 0.25f) / divisorF;
|
||||
if (time == 2000) {
|
||||
scale = 0.25f;
|
||||
}
|
||||
TVec3 pos(pProduct->GetDrawSpec().mMatrix[2]);
|
||||
pProduct->GetDrawSpec().mMatrix.Identity();
|
||||
pProduct->GetDrawSpec().mMatrix.Scale(scale, scale);
|
||||
pProduct->GetDrawSpec().mMatrix[2] = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000211ee
|
||||
void DookieDropper::Update(void)
|
||||
{
|
||||
TLuaTable* pPlayer = TWindowManager::GetInstance()->GetScript()->GetGlobalTable(str("Player"));
|
||||
TLuaTable* pFactories = pPlayer->GetTable("factories");
|
||||
TLuaTable* pFactory;
|
||||
{
|
||||
str factoryName(GetName());
|
||||
pFactory = pFactories->GetTable(factoryName.c_str());
|
||||
}
|
||||
|
||||
str current = pFactory->GetString("current", str(""));
|
||||
if (current.compare(currentCode) != 0) {
|
||||
currentCode = current;
|
||||
|
||||
TLuaTable* pAllProducts = TWindowManager::GetInstance()->GetScript()->GetGlobalTable(str("_AllProducts"));
|
||||
TLuaTable* pProductTable = pAllProducts->GetTable(current.c_str());
|
||||
if (pProductTable != NULL) {
|
||||
vector<str> appearance;
|
||||
vector<TColor> tints;
|
||||
LoadAppearance(*pProductTable, appearance, tints);
|
||||
|
||||
TVec3 pos(pProduct->GetDrawSpec().mMatrix[2]);
|
||||
pProduct->GetDrawSpec().mMatrix.Identity();
|
||||
BuildItemAppearance(TSpriteRef(pProduct), appearance, tints, 0.25f);
|
||||
pProduct->GetDrawSpec().mMatrix[2] = pos;
|
||||
|
||||
TLuaTable* pCounts = pProductTable->GetTable("counts");
|
||||
ingredientCount = 0;
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaObjectWrapper* value;
|
||||
while ((value = pCounts->GetNext(&key)) != NULL) {
|
||||
ingredientName[ingredientCount] = key->AsString();
|
||||
ingredientImage[ingredientCount] = TTexture::Get(str("items/") + ingredientName[ingredientCount], 0);
|
||||
ingredientCount++;
|
||||
delete value;
|
||||
}
|
||||
if (pCounts != NULL) {
|
||||
delete pCounts;
|
||||
}
|
||||
delete pProductTable;
|
||||
}
|
||||
if (pAllProducts != NULL) {
|
||||
delete pAllProducts;
|
||||
}
|
||||
}
|
||||
|
||||
TWindow* pCount = GetChildWindow(str("count"), -1);
|
||||
if (pCount != NULL) {
|
||||
TText* pText = pCount->GetCast<TText>();
|
||||
if (pText != NULL) {
|
||||
production = SseDoubleToUInt32(pFactory->GetNumber("production", 0.0));
|
||||
pText->SetText(str::getFormatted("%lu", (unsigned long)production));
|
||||
}
|
||||
}
|
||||
|
||||
stalled = pFactory->GetBoolean("stall", false);
|
||||
playerRank = SseDoubleToUInt32(pPlayer->GetNumber("rank", 1.0));
|
||||
|
||||
if (pFactory != NULL) {
|
||||
delete pFactory;
|
||||
}
|
||||
if (pFactories != NULL) {
|
||||
delete pFactories;
|
||||
}
|
||||
if (pPlayer != NULL) {
|
||||
delete pPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00021ecc
|
||||
void DookieDropper::Draw(void)
|
||||
{
|
||||
TWindow::Draw();
|
||||
TBegin2d begin2d;
|
||||
|
||||
if (pProduct) {
|
||||
pProduct->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
}
|
||||
if (pTimer) {
|
||||
pTimer->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
}
|
||||
|
||||
TLuaTable* pPlayer = TWindowManager::GetInstance()->GetScript()->GetGlobalTable(str("Player"));
|
||||
TLuaTable* pSupply = pPlayer->GetTable("supply");
|
||||
|
||||
float weeks = weeksPerColumn[playerRank];
|
||||
uint32_t width = (uint32_t)(GetParentRelativeRect().x2 - GetParentRelativeRect().x1);
|
||||
TReal columnW = (TReal)((double)width / 6.0);
|
||||
TReal imageScale = columnW * 0.03125f;
|
||||
TReal x = (columnW + ((TReal)width - (TReal)ingredientCount * columnW)) * 0.5f;
|
||||
double halfColumn = (double)columnW * -0.5;
|
||||
|
||||
for (uint8_t i = 0; i < ingredientCount; i++) {
|
||||
TReal fraction = (TReal)pSupply->GetNumber(ingredientName[i].c_str(), 0.0) / weeks;
|
||||
TReal h = barHeight;
|
||||
if (fraction * h <= h) {
|
||||
h = fraction * h;
|
||||
}
|
||||
|
||||
TColor color = colorTrouble;
|
||||
if (fraction < 0.75f) {
|
||||
if (0.5f <= fraction) {
|
||||
color = colorMedium;
|
||||
}
|
||||
} else {
|
||||
color = colorFull;
|
||||
}
|
||||
|
||||
double left = (double)x + halfColumn + 2.5;
|
||||
uint32_t rectX = SseDoubleToUInt32(left);
|
||||
TReal top = (ingredientY - h) - 3.0f;
|
||||
if (top <= 0.0f) {
|
||||
top = 0.0f;
|
||||
}
|
||||
uint32_t rectY = FloatToUInt(top);
|
||||
TTextureRef noTexture;
|
||||
TReal bottom = h + (TReal)rectY;
|
||||
if (bottom <= 0.0f) {
|
||||
bottom = 0.0f;
|
||||
}
|
||||
TReal right = ((TReal)rectX + columnW) - 4.0f;
|
||||
if (right <= 0.0f) {
|
||||
right = 0.0f;
|
||||
}
|
||||
TURect rect(rectX, rectY, FloatToUInt(right), FloatToUInt(bottom));
|
||||
TRenderer::GetInstance()->FillRect(rect, color, noTexture);
|
||||
|
||||
ingredientImage[i]->DrawSprite(x, ingredientY, 1.0f, imageScale, 0, 0);
|
||||
x = x + columnW;
|
||||
}
|
||||
|
||||
if ((stalled || production == 0) && pIdleFactory) {
|
||||
uint32_t w = (uint32_t)(GetParentRelativeRect().x2 - GetParentRelativeRect().x1);
|
||||
double halfWidth = (double)w * 0.5;
|
||||
TReal y0 = ingredientY;
|
||||
TReal barH = barHeight;
|
||||
uint32_t imageH = pIdleFactory->GetHeight();
|
||||
pIdleFactory->DrawSprite((TReal)halfWidth, (TReal)(0.5 * (double)imageH + (double)(y0 - barH)), 0.75f, 1.0f, 0, 0);
|
||||
}
|
||||
|
||||
if (pSupply != NULL) {
|
||||
delete pSupply;
|
||||
}
|
||||
if (pPlayer != NULL) {
|
||||
delete pPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
// DookieCollector: a TWindowSpider that appends every DookieDropper found below the window it is run on to a list.
|
||||
class DookieCollector : public TWindowSpider
|
||||
{
|
||||
public:
|
||||
DookieCollector(list<DookieDropper*>& droppers_);
|
||||
virtual ~DookieCollector();
|
||||
virtual bool Process(TWindow* window);
|
||||
protected:
|
||||
list<DookieDropper*>& droppers;
|
||||
};
|
||||
|
||||
// game @0x0016fe90
|
||||
DookieCollector::DookieCollector(list<DookieDropper*>& droppers_)
|
||||
: droppers(droppers_)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0016fee8 (D1) game @0x0016ff04 (D0)
|
||||
DookieCollector::~DookieCollector()
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0017032c
|
||||
bool DookieCollector::Process(TWindow* window)
|
||||
{
|
||||
if (!window->IsKindOf(DookieDropper::ClassId())) {
|
||||
window->ForEachChild(this, false);
|
||||
} else {
|
||||
DookieDropper* pDropper = window->GetCast<DookieDropper>();
|
||||
droppers.push_back(pDropper);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
74
port/game/FactoryTypes.cpp
Normal file
74
port/game/FactoryTypes.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
// Port of the game's FactoryTypes.cpp (Chocolatier 3, Big Splash Games): FlyingIngredient, the small record the
|
||||
// factory guns keep for an ingredient in flight (start point, direction and flight time), and the two message
|
||||
// classes MissedIngredientMessage and CollectedIngredientMessage.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// FactoryTypes.h (port/game/FactoryTypes.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): FlyingIngredient: pIngredient 0x0 (shared_ptr, 8 bytes), startPoint 0x8, direction 0x10,
|
||||
// distance 0x18, t 0x1c; sizeof 0x20 (Create allocates 0x20 bytes). MissedIngredientMessage: TMessage 0x0..0x10,
|
||||
// pIngredient 0x10. CollectedIngredientMessage: TMessage 0x0..0x10, collect (std::list<IngredientRef>) 0x10. The
|
||||
// header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4), 0.0f (@0x001ab6e8); double 1000.0 (@0x001ab528).
|
||||
// - FlyingIngredient::Tick advances t by the elapsed time (clamped to 1.0f) and returns the flight progress: t
|
||||
// itself when distance is not positive, otherwise (double)t * 1000.0 / distance converted to float and clamped to
|
||||
// 1.0f. The ingredient sprite is moved to startPoint + direction * progress (z = 1.0f). ChocolateGunTask treats a
|
||||
// progress of exactly 1.0f as the end of the flight.
|
||||
// - FlyingIngredient::SetTarget stores (x, y) in direction and then subtracts startPoint (direction is the vector
|
||||
// from the start to the target); it does not touch distance.
|
||||
//
|
||||
// Header-inline code emitted out of line (bodies from FactoryTypes.h; they are defined there and not repeated):
|
||||
// FlyingIngredient::Create game @0x00167fe8.
|
||||
// MissedIngredientMessage constructor game @0x0016fd14 (TMessage(kMissedIngredientEvent = 0x3eb, "", NULL),
|
||||
// pIngredient), D0 game @0x0016f868, D1 game @0x0016f8b8 (release pIngredient, then ~TMessage).
|
||||
// CollectedIngredientMessage constructor game @0x0016abb4 (TMessage(kCollectedIngredientEvent = 0x3f2, "",
|
||||
// NULL), empty list), D1 game @0x0016ac30, D0 game @0x0016ac74 (list, then ~TMessage).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "FactoryTypes.h"
|
||||
#include "IngredientQueue.h"
|
||||
|
||||
|
||||
// game @0x00022648
|
||||
void FlyingIngredient::SetTarget(TReal x, TReal y)
|
||||
{
|
||||
direction.x = x;
|
||||
direction.y = y;
|
||||
direction = direction - startPoint;
|
||||
}
|
||||
|
||||
// game @0x0002268e
|
||||
TReal FlyingIngredient::Tick(TReal tElapsed)
|
||||
{
|
||||
TReal oldT = t;
|
||||
t = tElapsed + oldT;
|
||||
if (1.0f < tElapsed + oldT) {
|
||||
t = 1.0f;
|
||||
}
|
||||
|
||||
TReal progress = t;
|
||||
if (0.0f < distance) {
|
||||
TReal ratio = (TReal)(((double)t * 1000.0) / (double)distance);
|
||||
progress = 1.0f;
|
||||
if (ratio <= 1.0f) {
|
||||
progress = ratio;
|
||||
}
|
||||
}
|
||||
|
||||
TVec2 position = startPoint + direction * progress;
|
||||
pIngredient->GetDrawSpec().mMatrix[2] = TVec3(position, 1.0f);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
// game @0x0002276c
|
||||
FlyingIngredient::FlyingIngredient(IngredientRef pIngredient_)
|
||||
: pIngredient(pIngredient_), startPoint(), direction(), distance(0), t(0)
|
||||
{
|
||||
TVec3 position(pIngredient->GetDrawSpec().mMatrix[2]);
|
||||
startPoint.x = position.x;
|
||||
startPoint.y = position.y;
|
||||
}
|
||||
198
port/game/Fireworks.cpp
Normal file
198
port/game/Fireworks.cpp
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
// Port of the game's Fireworks.cpp (Chocolatier 3, Big Splash Games): TFireworksWindow, a window that shows nine
|
||||
// game-end fireworks (particle systems), and TFirework, one firework with a delay / fire / explode cycle.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// Fireworks.h (port/game/Fireworks.h, unchanged). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): TFireworksWindow : TWindow (0x30) fireworkList (std::list<TFirework*>) 0x30. TFirework:
|
||||
// posX 0x0, posY 0x4, delay 0x8 (never set), time 0xc, pParticle 0x10, particleColorStart 0x14 (color at 0x1c),
|
||||
// state 0x2c, sizeof 0x30 (StartFireworks allocates 0x30 bytes). The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - File-level data: _FireworkColors, six colors (r g b a), game @0x0021ee60..0x0021eebf (set by the static
|
||||
// initializer game @0x001abaea from the immediates below, reached from __GLOBAL__I game @0x001abbca...); the
|
||||
// particleOptions array of 5 texture names is function-static data of the TFirework constructor (__data game
|
||||
// @0x001d8240): "firework_blue", "firework_red", "firework_yellow", "firework_green" and a null fifth pointer
|
||||
// (the game picks rand() % 5, so index 4 reads the null pointer; kept as shipped).
|
||||
// - TFirework constructor: state DELAY, time = rand() % 1000, position (200, 100), color (1, 0, 0, 1), a new
|
||||
// TLuaParticleSystem (no renderer) with the data source "gSparkleColorStart" and the script global
|
||||
// gSparkleTexture = particleOptions[rand() % 5], initialized from the given script.
|
||||
// - Update: DELAY counts time down by 40 (to FIRE when it is <= 40); FIRE picks a color (rand() % 6), plays the sound
|
||||
// "firework<rand() % 5 + 1>", resets time, picks a position (x = rand() % 250 + 50, y = rand() % 200 + 100),
|
||||
// sets gSparkleTime = 0.1 and enters EXPLODE; EXPLODE updates the particles by 40 ms per call until time reaches
|
||||
// 1100, then returns to DELAY with time = rand() % 500 + 250. Draw only draws while exploding.
|
||||
// - StartFireworks creates nine fireworks of "glitz/firework.lua" when the list is empty and starts the window
|
||||
// animation (40 ms, repeating, reset time, no forced frequency). The destructor deletes every firework.
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFTYPEDEF_DC: TFireworksWindowDynamicCreate game @0x0003e8e6, ClassId game @0x0003ded4, GetTypeName game
|
||||
// game @0x0003dede, IsKindOf game @0x00175d2c. ~TFireworksWindow: D1 game @0x0003e922, D0 game @0x0003e73c.
|
||||
// Lua registration instances: lua_pushdirectclosure<TFireworksWindow, void (TFireworksWindow::*)()> game
|
||||
// @0x00175b5c, DirectCallMemberDispatcherHelper<(void)> game @0x00175ba8. The std::list<TFirework*>
|
||||
// instantiations (game @0x00175be0..0x00175d20) are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "Fireworks.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "BSGSound.h"
|
||||
#include "pf/luaparticlesystem.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
PFTYPEIMPL_DC(TFireworksWindow);
|
||||
|
||||
static float FloatFromBits(uint32_t bits)
|
||||
{
|
||||
float value;
|
||||
memcpy(&value, &bits, sizeof(value));
|
||||
return value;
|
||||
}
|
||||
|
||||
// game @0x0021ee60 (static initializer game @0x001abaea)
|
||||
static TColor _FireworkColors[6] = {
|
||||
TColor(FloatFromBits(0x3f48c8c9), FloatFromBits(0x3efcfcfd), 0.0f, 1.0f),
|
||||
TColor(FloatFromBits(0x3f48c8c9), FloatFromBits(0x3e48c8c9), FloatFromBits(0x3e48c8c9), 1.0f),
|
||||
TColor(FloatFromBits(0x3e48c8c9), FloatFromBits(0x3ec8c8c9), FloatFromBits(0x3f5cdcdd), 1.0f),
|
||||
TColor(FloatFromBits(0x3f70f0f1), FloatFromBits(0x3f66e6e7), FloatFromBits(0x3df0f0f1), 1.0f),
|
||||
TColor(FloatFromBits(0x3e48c8c9), FloatFromBits(0x3f61e1e2), FloatFromBits(0x3df0f0f1), 1.0f),
|
||||
TColor(FloatFromBits(0x3f0c8c8d), FloatFromBits(0x3db0b0b1), FloatFromBits(0x3f43c3c4), 1.0f)
|
||||
};
|
||||
|
||||
// game @0x001d8240 (__data; the fifth entry is a null pointer in the binary)
|
||||
static const char* particleOptions[5] = { "firework_blue", "firework_red", "firework_yellow", "firework_green", 0 };
|
||||
|
||||
// game @0x0003dee8
|
||||
void TFireworksWindow::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
}
|
||||
|
||||
// game @0x0003def2
|
||||
void TFireworksWindow::StopFireworks(void)
|
||||
{
|
||||
StopWindowAnimation();
|
||||
}
|
||||
|
||||
// game @0x0003defc
|
||||
TFireworksWindow::TFirework::~TFirework(void)
|
||||
{
|
||||
if (pParticle != 0) {
|
||||
delete pParticle;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003df40
|
||||
void TFireworksWindow::TFirework::Update(void)
|
||||
{
|
||||
if (state == DELAY) {
|
||||
if (time < 0x29) {
|
||||
time = 0;
|
||||
state = FIRE;
|
||||
return;
|
||||
}
|
||||
time = time - 0x28;
|
||||
}
|
||||
else {
|
||||
if (state == FIRE) {
|
||||
uint32_t colorIndex = (uint32_t)rand() % 6;
|
||||
particleColorStart.color = _FireworkColors[colorIndex];
|
||||
int32_t soundIndex = rand();
|
||||
str soundName = str::getFormatted("firework%d", soundIndex % 5 + 1);
|
||||
BSGSoundEvent(soundName);
|
||||
time = 0;
|
||||
state = EXPLODE;
|
||||
posX = rand() % 0xfa + 0x32;
|
||||
posY = rand() % 200 + 100;
|
||||
pParticle->GetScript()->SetGlobalNumber("gSparkleTime", 0.1);
|
||||
return;
|
||||
}
|
||||
if (time < 0x44c) {
|
||||
time = time + 0x28;
|
||||
pParticle->Update(0x28);
|
||||
return;
|
||||
}
|
||||
state = DELAY;
|
||||
time = rand() % 500 + 0xfa;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003e14a
|
||||
void TFireworksWindow::TFirework::Draw(void)
|
||||
{
|
||||
if (state != FIRE && state == EXPLODE) {
|
||||
pParticle->Draw(TVec3((float)posX, (float)posY, 0));
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003e1a0
|
||||
TFireworksWindow::TFirework::TFirework(str type)
|
||||
{
|
||||
state = DELAY;
|
||||
time = rand() % 1000;
|
||||
posX = 200;
|
||||
posY = 100;
|
||||
particleColorStart.color.a = 1.0f;
|
||||
particleColorStart.color.b = 0.0f;
|
||||
particleColorStart.color.g = 0.0f;
|
||||
particleColorStart.color.r = 1.0f;
|
||||
pParticle = new TLuaParticleSystem(0);
|
||||
pParticle->RegisterDataSource("gSparkleColorStart", &particleColorStart);
|
||||
pParticle->GetScript()->SetGlobalString("gSparkleTexture", particleOptions[rand() % 5]);
|
||||
pParticle->Init(type);
|
||||
}
|
||||
|
||||
// game @0x0003e350
|
||||
bool TFireworksWindow::OnTaskAnimate(void)
|
||||
{
|
||||
for (list<TFirework*>::iterator it = fireworkList.begin(); it != fireworkList.end(); ++it) {
|
||||
(*it)->Update();
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0003e38e
|
||||
void TFireworksWindow::Draw(void)
|
||||
{
|
||||
TWindow::Draw();
|
||||
TBegin2d begin2d;
|
||||
for (list<TFirework*>::iterator it = fireworkList.begin(); it != fireworkList.end(); ++it) {
|
||||
(*it)->Draw();
|
||||
}
|
||||
begin2d.Done();
|
||||
}
|
||||
|
||||
// game @0x0003e3ea
|
||||
void TFireworksWindow::StartFireworks(void)
|
||||
{
|
||||
if (fireworkList.empty()) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
TFirework* pFirework = new TFirework("glitz/firework.lua");
|
||||
fireworkList.push_back(pFirework);
|
||||
}
|
||||
}
|
||||
StartWindowAnimation(0x28, true, true, false);
|
||||
}
|
||||
|
||||
// game @0x0003e922 (D1), game @0x0003e73c (D0)
|
||||
TFireworksWindow::~TFireworksWindow(void)
|
||||
{
|
||||
for (list<TFirework*>::iterator it = fireworkList.begin(); it != fireworkList.end(); ++it) {
|
||||
if (*it != 0) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
fireworkList.clear();
|
||||
}
|
||||
|
||||
// game @0x0003e7c2
|
||||
TFireworksWindow::TFireworksWindow(void)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "StartFireworks", this, TFireworksWindow::StartFireworks);
|
||||
ScriptRegisterMemberDirect(script, "StopFireworks", this, TFireworksWindow::StopFireworks);
|
||||
}
|
||||
132
port/game/FlyingRing.cpp
Normal file
132
port/game/FlyingRing.cpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
// Port of the game's FlyingRing.cpp (Chocolatier 3, Big Splash Games): FlyingRing (a coloured ring sprite that flies
|
||||
// along a curve from a tray slot to a point), FlyingRingTask (moves the rings and reports each arrival to the
|
||||
// factory window) and FlyingRingStartMessage (the colour-match message that starts one ring per slot of a tray).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// FlyingRing.h (port/game/FlyingRing.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): FlyingRing: TSprite 0x0..0x80, pCurve 0x80, t 0x88; sizeof 0x8c (Create allocates 0x8c
|
||||
// bytes). FlyingRingTask: TScalingTask 0x0..0x1c, flyTime 0x1c, rings (std::set<FlyingRingRef>) 0x20 (tree header
|
||||
// 0x24, leftmost node 0x2c). FlyingRingStartMessage: TMessage 0x0..0x10, pTray 0x10, color 0x18. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4).
|
||||
// - Strings from the game's __cstring: "image/item_ring", "FactoryGame" (the factory child window), "".
|
||||
// - FlyingRing::Update is the same code as ChocolateProduct::Update (t advances, is clamped to 1.0f, the position is
|
||||
// the curve point; true while t < 1.0f).
|
||||
// - The ring tint is kFactoryColors[color] (16 bytes per entry) written to the TDrawSpec mTint (+0x4c); the curve
|
||||
// runs through TCurve::Create(start, start, end, end).
|
||||
// - FlyingRingTask::Animate removes each ring whose Update returned false from its sprite parent (TSprite vtable
|
||||
// slot 0x14, RemoveChild), sends kCountBonusProductEvent (event 0x3ee, text "") to the "FactoryGame" child of the
|
||||
// top modal window (looked up once and kept, retried while missing), and erases the ring from the set. The ring
|
||||
// set is advanced before Update, so erasing the current node is safe.
|
||||
// - FlyingRingTask::Reset only calls TScalingTask::Reset (it clears nothing).
|
||||
// - FlyingRingStartMessage::Initiate does nothing unless the tray has a sprite parent; then it creates a ring of the
|
||||
// tray's colour (+0xa8) for every global slot position of the tray, parents it to the tray's parent and adds it to
|
||||
// the task (AddRing, inline).
|
||||
//
|
||||
// Compiler-generated or header-inline code emitted out of line (bodies from FlyingRing.h): FlyingRingTask
|
||||
// constructor game @0x00167848 (TScalingTask(), flyTime, empty set); FlyingRingStartMessage constructor game
|
||||
// game @0x001695ac (TMessage(kColorMatchEvent = 0x3f1, "", NULL), pTray, color); ~FlyingRingStartMessage: D0 game
|
||||
// game @0x00168dcc, D1 game @0x00168e1c (release pTray, then ~TMessage); The std::set /
|
||||
// boost::shared_ptr<FlyingRing> instantiations are not ported. ~FlyingRing (inline in FlyingRing.h): D0 game
|
||||
// game @0x0016e51c, D1 game @0x0016e570 (release pCurve, then ~TSprite).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "FlyingRing.h"
|
||||
#include "IngredientQueue.h"
|
||||
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/window.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x000227e4
|
||||
bool FlyingRing::Update(TReal elapsed)
|
||||
{
|
||||
t = elapsed + t;
|
||||
if (1.0f < t) {
|
||||
t = 1.0f;
|
||||
}
|
||||
GetDrawSpec().mMatrix[2] = TVec3(pCurve->GetPoint(t, 0), 1.0f);
|
||||
return t <= 1.0f && 1.0f != t;
|
||||
}
|
||||
|
||||
// game @0x00022882
|
||||
void FlyingRingTask::Reset(TReal newScale)
|
||||
{
|
||||
TScalingTask::Reset(newScale);
|
||||
}
|
||||
|
||||
// game @0x0002288c
|
||||
bool FlyingRingTask::Animate(void)
|
||||
{
|
||||
TReal tElapsed = AnimateDelta(flyTime);
|
||||
|
||||
TWindow* pFactory = NULL;
|
||||
set<FlyingRingRef>::iterator it = rings.begin();
|
||||
while (it != rings.end()) {
|
||||
set<FlyingRingRef>::iterator cur = it;
|
||||
++it;
|
||||
|
||||
if ((*cur)->Update(tElapsed)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TSprite* pParent = (*cur)->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild(*cur);
|
||||
}
|
||||
|
||||
bool send = true;
|
||||
if (pFactory == NULL) {
|
||||
send = false;
|
||||
pFactory = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pFactory != NULL) {
|
||||
pFactory = pFactory->GetChildWindow("FactoryGame", -1);
|
||||
if (pFactory != NULL) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (send) {
|
||||
pFactory->SendWindowMessage(new TMessage(kCountBonusProductEvent, "", pFactory));
|
||||
}
|
||||
|
||||
rings.erase(cur);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00022a48
|
||||
FlyingRing::FlyingRing(uint8_t color, TVec2 const& startPoint, TVec2 const& endPoint)
|
||||
: TSprite(15), pCurve(), t(0)
|
||||
{
|
||||
SetTexture(TTexture::Get("image/item_ring", 0));
|
||||
GetDrawSpec().mTint = kFactoryColors[color];
|
||||
pCurve = TCurve::Create(startPoint, startPoint, endPoint, endPoint);
|
||||
}
|
||||
|
||||
// game @0x00022bc0
|
||||
FlyingRingRef FlyingRing::Create(uint8_t color, TVec2 const& startPoint, TVec2 const& endPoint)
|
||||
{
|
||||
return FlyingRingRef(new FlyingRing(color, startPoint, endPoint));
|
||||
}
|
||||
|
||||
// game @0x00022c28
|
||||
void FlyingRingStartMessage::Initiate(FlyingRingTask* pTask, TVec2 const& endPoint)
|
||||
{
|
||||
TSprite* pParent = pTray->GetParent();
|
||||
if (pParent != NULL) {
|
||||
vector<TVec2> positions;
|
||||
pTray->GetGlobalSlotPositions(positions);
|
||||
for (vector<TVec2>::iterator it = positions.begin(); it != positions.end(); ++it) {
|
||||
FlyingRingRef pRing = FlyingRing::Create(pTray->GetColor(), *it, endPoint);
|
||||
pParent->AddChild(pRing);
|
||||
pTask->AddRing(pRing);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
port/game/Glitz.cpp
Normal file
18
port/game/Glitz.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Port of the game's Glitz.cpp (Chocolatier 3, Big Splash Games): ParticleColor, a particle function that pushes
|
||||
// its color onto the particle machine stack. The whole class is defined in Glitz.h (port/game/Glitz.h, unchanged);
|
||||
// the game emits its members out of line from the header inline bodies.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): ParticleColor : TParticleFunction (0x8) color 0x8 (r g b a, 4 floats zeroed by the
|
||||
// constructor), sizeof 0x18.
|
||||
//
|
||||
// Header-inline members emitted out of line (bodies match Glitz.h):
|
||||
// ParticleColor() game @0x0017559c (TParticleFunction(), color = 0,0,0,0); ~ParticleColor D1 game @0x001755d0,
|
||||
// D0 game @0x00175b08 (also deletes); GetReturnSize game @0x00175ab4 (returns 4); Process game @0x00175ac0 (pushes
|
||||
// the color as 4 floats r, g, b, a with TParticleMachineState::Push and returns true).
|
||||
// PFTYPEDEF_DC: ParticleColorDynamicCreate game @0x0003de8e, GetTypeName game @0x0003deca, IsKindOf game
|
||||
// game @0x00175b30.
|
||||
|
||||
#include "Glitz.h"
|
||||
|
||||
PFTYPEIMPL_DC(ParticleColor);
|
||||
76
port/game/IngredientPowerups.cpp
Normal file
76
port/game/IngredientPowerups.cpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// Port of the game's IngredientPowerups.cpp (Chocolatier 3, Big Splash Games): the three ingredient powerups
|
||||
// ChainIngredient (when it hits a tray it is replaced by a plain ingredient of the same name that also hits the
|
||||
// tray, and it never counts as missed once chained), EnlargeIngredient (scales the tray up by 1.1) and
|
||||
// SuperColorIngredient (gives the tray its colour and shows a rainbow ring until it hits).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// IngredientPowerups.h (port/game/IngredientPowerups.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): each subclass adds one bool at 0x90 after Ingredient:
|
||||
// ChainIngredient::chained, SuperColorIngredient::hit. Ingredient vtable slots used: HitTray 0x2c.
|
||||
// Strings from the game's __cstring: "image/item_supercolor", "image/item_ring". Float: 1.1f (an immediate).
|
||||
//
|
||||
// Not defined, because the game has no code for them: ChainIngredient / EnlargeIngredient / SuperColorIngredient
|
||||
// ::Create (declared only) and the ChainIngredient / EnlargeIngredient constructors (declared only; nothing
|
||||
// constructs them).
|
||||
//
|
||||
// Compiler-generated or header-inline code emitted out of line:
|
||||
// ChainIngredient::SetColor (empty inline body) game @0x0016ec04.
|
||||
// SuperColorIngredient constructor (inline: Ingredient(name), hit(false)) game @0x0016f098.
|
||||
// ~SuperColorIngredient: D0 game @0x0016efd8, D1 game @0x0016f000; ~EnlargeIngredient: D0 game @0x0016f018, D1
|
||||
// game @0x0016f040; ~ChainIngredient: D0 game @0x0016f058, D1 game @0x0016f080 (each is the vptr store and
|
||||
// ~Ingredient, D0 also deletes).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "IngredientPowerups.h"
|
||||
#include "ChocolateTray.h"
|
||||
|
||||
#include "pf/texture.h"
|
||||
|
||||
// game @0x00025914
|
||||
bool ChainIngredient::Die(void)
|
||||
{
|
||||
if (!chained) {
|
||||
Ingredient::Die();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00025936
|
||||
void SuperColorIngredient::SetColor(uint8_t color_)
|
||||
{
|
||||
Ingredient::SetColor(color_);
|
||||
if (!hit && pColorRing && color_ != 0) {
|
||||
pColorRing->SetTexture(TTexture::Get("image/item_supercolor", 0));
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00025a0e
|
||||
bool EnlargeIngredient::HitTray(ChocolateTrayRef pTray)
|
||||
{
|
||||
pTray->Scale(1.1f);
|
||||
return Ingredient::HitTray(pTray);
|
||||
}
|
||||
|
||||
// game @0x00025a7e
|
||||
bool ChainIngredient::HitTray(ChocolateTrayRef pTray)
|
||||
{
|
||||
if (!chained) {
|
||||
chained = true;
|
||||
}
|
||||
IngredientRef pIngredient = Ingredient::Create(name);
|
||||
pIngredient->HitTray(pTray);
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00025b50
|
||||
bool SuperColorIngredient::HitTray(ChocolateTrayRef pTray)
|
||||
{
|
||||
hit = true;
|
||||
if (color != 0) {
|
||||
pTray->SetColor(color);
|
||||
pColorRing->SetTexture(TTexture::Get("image/item_ring", 0));
|
||||
}
|
||||
return Ingredient::HitTray(pTray);
|
||||
}
|
||||
317
port/game/IngredientQueue.cpp
Normal file
317
port/game/IngredientQueue.cpp
Normal file
|
|
@ -0,0 +1,317 @@
|
|||
// Port of the game's IngredientQueue.cpp (Chocolatier 3, Big Splash Games): Ingredient (a sprite for one ingredient
|
||||
// item with an optional colour ring), IngredientPiston (the two-section arm and two fingers that push an item along
|
||||
// the conveyor), IngredientQueue (the shuffled supply of ingredients that rides the conveyor curve) and
|
||||
// IngredientQueueTask (the task that advances the queue).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// IngredientQueue.h (port/game/IngredientQueue.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): Ingredient: TSprite 0x0..0x80, name (str) 0x80, color 0x84 (byte), pColorRing 0x88
|
||||
// (TSpriteRef), sizeof 0x90 (Create allocates 0x90 bytes; the powerup subclasses add a bool at 0x90).
|
||||
// IngredientPiston: pBase 0x0, pSection2 0x8; sizeof 0x10. IngredientQueue: vptr 0x0, pBaseSprite 0x4, recipe
|
||||
// (reference) 0xc, allowRainbow 0x10, colorCount 0x11, pCurve 0x14, queue (vector) 0x1c, conveyor (list) 0x28,
|
||||
// pistons (vector) 0x30, headPosition 0x3c, spacing 0x40, countdown 0x44. IngredientQueueTask: TScalingTask
|
||||
// 0x0..0x1c, pQueue 0x1c, queueTime 0x24. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4), 0.0f (@0x001ab6e8), 600.0f (@0x001ab738); doubles 0.5
|
||||
// (@0x001ab488), 16.0 (@0x001ab538). The arm centre x is (double)width * 0.5 (the width is converted as an
|
||||
// unsigned int, the 0x45300000 / 0x43300000 constants at 0x00192c20..0x00192c38 are that conversion).
|
||||
// - Strings from the game's __cstring: "items/", "image/item_ring", "image/item_ring_rainbow",
|
||||
// "image/ingredient_arm_1", "image/ingredient_arm_2", "image/ingredient_finger_1", "image/ingredient_finger_2",
|
||||
// "FactoryGame".
|
||||
// - kFactoryColors (5 TColor, one per COLOR_* value) is zero-initialized (__common @0x0021fa40) and filled by the
|
||||
// file's static initializer, __static_initialization_and_destruction_0 game @0x001ab9fe (called from
|
||||
// __GLOBAL__I_Ingredient::ClassId game @0x001abaa6): white, (235, 14, 14), (45, 56, 197), (255, 209, 23) and white
|
||||
// again, each over 255, alpha 1. The values are written here as the exact float bit patterns the binary stores
|
||||
// (0x3f6bebec 0x3d60e0e1 0x3e34b4b5 0x3e60e0e1 0x3f45c5c6 0x3f51d1d2 0x3db8b8b9).
|
||||
// - The IngredientQueue constructor does not initialize allowRainbow (byte 0x10 is never written in the game).
|
||||
// - Ingredient vtable slots used: SetColor 0x28. TSprite slot 0x14 is RemoveChild (the ingredient is removed from its
|
||||
// parent sprite on Reset).
|
||||
// - IngredientQueue::Update: headPosition = min(headPosition + dt, 1.0f), the ingredients on the conveyor are placed
|
||||
// along the curve one spacing apart behind the head, new ones are taken from the back of the (refilled by
|
||||
// FillQueue(5) when empty) queue until the position passes 0.0f, and one piston per conveyor ingredient is created
|
||||
// (added to pBaseSprite without a null check) and moved to its ingredient.
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFSHAREDTYPEDEF / PFTYPEIMPL: Ingredient::ClassId game @0x00025c64, GetTypeName game @0x00025c6e ("Ingredient"),
|
||||
// IsKindOf game @0x0016ebd4 (the Ingredient class id, else TSprite::IsKindOf), GetRef game @0x0016fe28 (header
|
||||
// inline: shared_from_this()->GetCast<Ingredient>()), GetPosition game @0x00167cbc (header inline, returns the
|
||||
// matrix translation at +0x38).
|
||||
// ~Ingredient (declared by the compiler; releases pColorRing and name, then ~TSprite): D1 game @0x0016ef6c,
|
||||
// D2 game @0x0016f6a8, D0 game @0x0016f390.
|
||||
// ~IngredientPiston (releases pSection2, pBase) game @0x0016f710.
|
||||
// ~IngredientQueue (virtual; releases pistons, conveyor, queue, pCurve, pBaseSprite): D1 game @0x00025d10, D0
|
||||
// game @0x000260b0.
|
||||
// IngredientQueueTask constructor (header inline): TScalingTask(), pQueue, queueTime, game @0x001678a0.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "BSGHelpers.h"
|
||||
#include "IngredientQueue.h"
|
||||
#include "Recycler.h"
|
||||
#include "ChocolateTray.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/window.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
PFTYPEIMPL(Ingredient);
|
||||
|
||||
// game @0x001ab9fe (static initializer; values are the stored float bit patterns, see the notes)
|
||||
TColor const kFactoryColors[COLOR_WHITE + 1] = {
|
||||
TColor(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
TColor(0x1.d7d7d8p-1f, 0x1.c1c1c2p-5f, 0x1.c1c1c2p-5f, 1.0f),
|
||||
TColor(0x1.69696ap-3f, 0x1.c1c1c2p-3f, 0x1.8b8b8cp-1f, 1.0f),
|
||||
TColor(1.0f, 0x1.a3a3a4p-1f, 0x1.717172p-4f, 1.0f),
|
||||
TColor(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
};
|
||||
|
||||
// game @0x00025dc0 (C2) and game @0x00025f74 (C1)
|
||||
Ingredient::Ingredient(str name_) :
|
||||
TSprite(4),
|
||||
name(name_),
|
||||
color(0),
|
||||
pColorRing()
|
||||
{
|
||||
TSprite::SetTexture(TTexture::Get(str("items/") + name, 0));
|
||||
}
|
||||
|
||||
// game @0x00025efc
|
||||
IngredientRef Ingredient::Create(str name)
|
||||
{
|
||||
return IngredientRef(new Ingredient(name));
|
||||
}
|
||||
|
||||
// game @0x00025c78
|
||||
void Ingredient::SetPosition(TVec2 const& pos)
|
||||
{
|
||||
GetDrawSpec().mMatrix[2] = TVec3(pos, 1.0f);
|
||||
}
|
||||
|
||||
// game @0x00026930
|
||||
void Ingredient::SetColor(uint8_t newColor)
|
||||
{
|
||||
if (!pColorRing) {
|
||||
pColorRing = TSprite::Create(-1, TTexture::Get("image/item_ring", 0));
|
||||
AddChild(pColorRing);
|
||||
}
|
||||
|
||||
TTextureRef pTexture;
|
||||
if (newColor == 0) {
|
||||
pTexture = TTexture::Get("image/item_ring_rainbow", 0);
|
||||
} else if (color == 0) {
|
||||
pTexture = TTexture::Get("image/item_ring", 0);
|
||||
}
|
||||
color = newColor;
|
||||
if (pTexture) {
|
||||
pColorRing->SetTexture(pTexture);
|
||||
}
|
||||
pColorRing->GetDrawSpec().mTint = kFactoryColors[color];
|
||||
}
|
||||
|
||||
// game @0x0002730a
|
||||
bool Ingredient::Die(void)
|
||||
{
|
||||
TWindow* pTop = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pTop != NULL) {
|
||||
TWindow* pFactory = pTop->GetChildWindow("FactoryGame", -1);
|
||||
if (pFactory != NULL) {
|
||||
pFactory->SendWindowMessage(new MissedIngredientMessage(GetRef()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x000273ee
|
||||
bool Ingredient::HitRecycler(RecyclerRef pRecycler)
|
||||
{
|
||||
pRecycler->AddIngredient(GetRef());
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00027450
|
||||
bool Ingredient::HitTray(ChocolateTrayRef pTray)
|
||||
{
|
||||
pTray->AddIngredient(GetRef());
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0002623c
|
||||
IngredientPiston::IngredientPiston(void) :
|
||||
pBase(),
|
||||
pSection2()
|
||||
{
|
||||
TTextureRef pTexture = TTexture::Get("image/ingredient_arm_2", 0);
|
||||
pBase = TSprite::Create(-100, pTexture);
|
||||
pBase->GetDrawSpec().mFlags |= TDrawSpec::kUseCenter;
|
||||
pBase->GetDrawSpec().mCenter = TVec2((TReal)((double)pTexture->GetWidth() * 0.5), -16.0f);
|
||||
|
||||
pTexture = TTexture::Get("image/ingredient_arm_1", 0);
|
||||
pSection2 = TSprite::Create(0, pTexture);
|
||||
pSection2->GetDrawSpec().mFlags |= TDrawSpec::kUseCenter;
|
||||
pSection2->GetDrawSpec().mCenter = TVec2((TReal)((double)pTexture->GetWidth() * 0.5), 0.0f);
|
||||
pSection2->GetDrawSpec().mMatrix[2] = TVec3(0.0f, 120.0f, 1.0f);
|
||||
pBase->AddChild(pSection2);
|
||||
|
||||
pTexture = TTexture::Get("image/ingredient_finger_1", 0);
|
||||
TSpriteRef pFinger1 = TSprite::Create(2, pTexture);
|
||||
pFinger1->GetDrawSpec().mMatrix[2] = TVec3(-6.0f, 0.0f, 1.0f);
|
||||
pBase->AddChild(pFinger1);
|
||||
|
||||
pTexture = TTexture::Get("image/ingredient_finger_2", 0);
|
||||
TSpriteRef pFinger2 = TSprite::Create(2, pTexture);
|
||||
pFinger2->GetDrawSpec().mMatrix[2] = TVec3(6.0f, 0.0f, 1.0f);
|
||||
pBase->AddChild(pFinger2);
|
||||
}
|
||||
|
||||
// game @0x00025cb2
|
||||
void IngredientPiston::SetPosition(TVec3 const& pos)
|
||||
{
|
||||
pBase->GetDrawSpec().mMatrix[2] = pos;
|
||||
if (pSection2) {
|
||||
pSection2->GetDrawSpec().mMatrix[2].y = (TReal)((double)(600.0f - pos.y) * 0.5 + 16.0);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00026160
|
||||
IngredientQueue::IngredientQueue(ProductRecipe& recipe_, uint8_t colorCount_, TCurveRef pCurve_, uint32_t count,
|
||||
TSpriteRef pBaseSprite_) :
|
||||
pBaseSprite(pBaseSprite_),
|
||||
recipe(recipe_),
|
||||
colorCount(colorCount_),
|
||||
pCurve(pCurve_),
|
||||
queue(),
|
||||
conveyor(),
|
||||
pistons()
|
||||
{
|
||||
headPosition = 0;
|
||||
spacing = 0;
|
||||
countdown = 0;
|
||||
spacing = 1.0f / (TReal)count;
|
||||
}
|
||||
|
||||
// game @0x00025d10 (D1), game @0x000260b0 (D0)
|
||||
IngredientQueue::~IngredientQueue(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x00026c2a
|
||||
void IngredientQueue::FillQueue(uint32_t recipeCount)
|
||||
{
|
||||
for (uint32_t i = 0; i < (uint32_t)recipe.size() * recipeCount; i++) {
|
||||
str name = recipe[i % (uint32_t)recipe.size()];
|
||||
IngredientRef pIngredient = Ingredient::Create(name);
|
||||
if (1 < colorCount) {
|
||||
uint32_t newColor = RandRange((uint32_t)(allowRainbow == false), (uint32_t)colorCount);
|
||||
pIngredient->SetColor((uint8_t)newColor);
|
||||
}
|
||||
queue.push_back(pIngredient);
|
||||
}
|
||||
|
||||
uint32_t count = (uint32_t)queue.size();
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
uint32_t j = RandRange(0, count - 1);
|
||||
IngredientRef pTemp = queue[i];
|
||||
queue[i] = queue[j];
|
||||
queue[j] = pTemp;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00026e4a
|
||||
void IngredientQueue::Reset(void)
|
||||
{
|
||||
for (list<IngredientRef>::iterator it = conveyor.begin(); it != conveyor.end(); ++it) {
|
||||
TSprite* pParent = (*it)->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild(*it);
|
||||
}
|
||||
}
|
||||
queue.clear();
|
||||
conveyor.clear();
|
||||
countdown = 0;
|
||||
headPosition = 0;
|
||||
}
|
||||
|
||||
// game @0x00026f1a
|
||||
void IngredientQueue::Update(TReal tElapsed)
|
||||
{
|
||||
if (headPosition < 1.0f) {
|
||||
TReal sum = headPosition + tElapsed;
|
||||
headPosition = (sum < 1.0f) ? sum : 1.0f;
|
||||
TReal t = headPosition;
|
||||
|
||||
for (list<IngredientRef>::iterator it = conveyor.begin(); it != conveyor.end(); ++it) {
|
||||
(*it)->SetPosition(pCurve->GetPoint(t, 0));
|
||||
t = t - spacing;
|
||||
}
|
||||
|
||||
while (0.0f < t) {
|
||||
if (queue.empty()) {
|
||||
FillQueue(5);
|
||||
}
|
||||
IngredientRef pIngredient = queue.back();
|
||||
queue.pop_back();
|
||||
conveyor.push_back(pIngredient);
|
||||
if (pBaseSprite) {
|
||||
pBaseSprite->AddChild(pIngredient);
|
||||
}
|
||||
pIngredient->SetPosition(pCurve->GetPoint(t, 0));
|
||||
t = t - spacing;
|
||||
}
|
||||
|
||||
while ((uint32_t)conveyor.size() > (uint32_t)pistons.size()) {
|
||||
IngredientPistonRef pPiston(new IngredientPiston());
|
||||
pistons.push_back(pPiston);
|
||||
pBaseSprite->AddChild(pPiston->pBase);
|
||||
}
|
||||
|
||||
uint32_t i = 0;
|
||||
for (list<IngredientRef>::iterator it = conveyor.begin(); it != conveyor.end(); ++it) {
|
||||
pistons[i]->SetPosition((*it)->GetDrawSpec().mMatrix[2]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002721c
|
||||
IngredientRef IngredientQueue::PopConveyor(void)
|
||||
{
|
||||
IngredientRef pIngredient;
|
||||
if (headPosition == 1.0f) {
|
||||
pIngredient = conveyor.front();
|
||||
conveyor.pop_front();
|
||||
headPosition = headPosition - spacing;
|
||||
}
|
||||
return pIngredient;
|
||||
}
|
||||
|
||||
// game @0x000272a8
|
||||
IngredientRef IngredientQueue::PeekConveyor(void)
|
||||
{
|
||||
IngredientRef pIngredient;
|
||||
if (!conveyor.empty()) {
|
||||
pIngredient = conveyor.front();
|
||||
}
|
||||
return pIngredient;
|
||||
}
|
||||
|
||||
// game @0x00026ef0
|
||||
void IngredientQueueTask::Reset(TReal newScale)
|
||||
{
|
||||
pQueue->Reset();
|
||||
TScalingTask::Reset(newScale);
|
||||
}
|
||||
|
||||
// game @0x000271de
|
||||
bool IngredientQueueTask::Animate(void)
|
||||
{
|
||||
TReal delta = AnimateDelta(queueTime);
|
||||
if (pQueue) {
|
||||
pQueue->Update(delta);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
386
port/game/LedgerWindow.cpp
Normal file
386
port/game/LedgerWindow.cpp
Normal file
|
|
@ -0,0 +1,386 @@
|
|||
// Port of the game's LedgerWindow.cpp (Chocolatier 3, Big Splash Games): the ledger overlay (money, day, rank,
|
||||
// score, quest indicator, factory production droppers) and its animation task.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// LedgerWindow.h (port/game/LedgerWindow.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TBSGWindow 0x50; pMoneyWindow 0x50, displayMoney 0x54, targetMoney 0x5c, deltaMoney 0x64,
|
||||
// pQuestWindow 0x6c, droppers 0x70 (std::list head), flashQuest 0x78, flashTimer 0x7c, pTask 0x80; sizeof 0x84
|
||||
// (Grab allocates 0x84). TLedgerAnimTask : TAnimTask, sizeof 0x18. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - UpdateMoney wraps Dollars(displayMoney) in a <font size='N'> tag by magnitude: >= 1e11 size 20, >= 1e9 size 22,
|
||||
// >= 1e8 size 25, smaller values are left unwrapped (doubles at 0x001ab540 / 0x001ab548 / 0x001ab550).
|
||||
// - UpdateLedger: "all" and "newplayer" refresh every part. "time" sets the day text (Date) and the "GameWeeks"
|
||||
// state; "money" sets targetMoney and deltaMoney = (float)((target - display) / 20.0) (double @0x001ab558 = 20.0),
|
||||
// and for "newplayer" also calls UpdateMoney; "rank" sets the rank text from the string table key "rank_%lu",
|
||||
// hides the score window when the rank equals 1.0 (double @0x001ab470) and stores "Rank"; "quest" / "newplayer"
|
||||
// set the questText text from data; "factory" / "factories" updates the droppers from the Player.factories table;
|
||||
// "portview" / "mapview" swap the map_port / port_map children; "time"/"money"/"all"/"newplayer" recompute the
|
||||
// score = (uint)floor(money / time) (0 when time <= 0) through the "score_format" platform string.
|
||||
// Doubles are converted to uint32 clamped to [0, 4294967295.0] (constants @0x00192c70 / @0x00192c60 and the SSE
|
||||
// conversion sequence).
|
||||
// - The Player table returned by GetGlobalTable and the factories table are released with the table's deleting
|
||||
// destructor (vtable slot 1) in the game code.
|
||||
// - TLedgerAnimTask has no declared constructor/destructor: compiler-generated TLedgerAnimTask C1 game @0x0016ff94,
|
||||
// D1 game @0x00170248, D0 game @0x00170260 (the vptr is the only addition to TAnimTask(NULL)).
|
||||
// - DookieCollector (a TWindowSpider that collects DookieDropper children into the list) is defined in the
|
||||
// game's DookieDropper.cpp, not in a header; it is declared here for PrepareInstance only (C1 game @0x0016fe90,
|
||||
// D1 game @0x0016fee8).
|
||||
//
|
||||
// Header-inline code emitted out of line in the game (pf/luapluscd.h templates, driven by the registration code in
|
||||
// the constructor below): lua_pushdirectclosure<LedgerWindow, F> for F = void (str, str) game @0x0016ffbc,
|
||||
// void (str) game @0x00170008, void () game @0x00170054;
|
||||
// LPCD::DirectCallMemberDispatcherHelper<LedgerWindow, F>::DirectCallMemberDispatcher for F = void (str, str)
|
||||
// game @0x00170154 (ReturnSpecialization<void>::Call<LedgerWindow, str, str> game @0x001700a0), void (str)
|
||||
// game @0x0017041c (Call<LedgerWindow, str> game @0x00170198), void () game @0x001703d4.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "LedgerWindow.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGSound.h"
|
||||
#include "BSGStringTable.h"
|
||||
|
||||
#include "pf/animtask.h"
|
||||
#include "pf/gamestate.h"
|
||||
#include "pf/image.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/stringtable.h"
|
||||
#include "pf/text.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
LedgerWindow* LedgerWindow::pInstance = NULL;
|
||||
|
||||
// DookieCollector: defined in the game's DookieDropper.cpp; only the interface PrepareInstance needs.
|
||||
class DookieCollector : public TWindowSpider
|
||||
{
|
||||
public:
|
||||
DookieCollector(list<DookieDropper*>& droppers);
|
||||
virtual ~DookieCollector();
|
||||
virtual bool Process(TWindow* window);
|
||||
protected:
|
||||
list<DookieDropper*>& droppers; // +4 (same layout as the definition in DookieDropper.cpp; stack object here)
|
||||
};
|
||||
|
||||
// game @0x000274b2 (GetTypeName, "LedgerWindow")
|
||||
// game @0x0002915e (LedgerWindowDynamicCreate: new LedgerWindow, sizeof 0x84)
|
||||
// game @0x00170460 (IsKindOf)
|
||||
PFTYPEIMPL_DC(LedgerWindow);
|
||||
|
||||
// double -> uint32_t as the game does it: clamp to [0, 4294967295.0] (DAT_00192c70) and convert
|
||||
static uint32_t ClampToUInt(double v)
|
||||
{
|
||||
if (v >= 4294967295.0)
|
||||
v = 4294967295.0;
|
||||
if (v <= 0.0)
|
||||
v = 0.0;
|
||||
return (uint32_t)v;
|
||||
}
|
||||
|
||||
// game @0x000274bc
|
||||
void LedgerWindow::ToggleForeground(void)
|
||||
{
|
||||
if (pInstance != NULL && pInstance->pTask != NULL)
|
||||
{
|
||||
if (!TPlatform::GetInstance()->IsForeground())
|
||||
pInstance->pTask->Pause();
|
||||
else
|
||||
pInstance->pTask->SetDelay(50, true, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00027530
|
||||
void LedgerWindow::UpdateMoney(void)
|
||||
{
|
||||
str text = Dollars(displayMoney);
|
||||
if (displayMoney >= 100000000000.0)
|
||||
text = str("<font size='20'>") + text + str("</font>");
|
||||
else if (displayMoney >= 1000000000.0)
|
||||
text = str("<font size='22'>") + text + str("</font>");
|
||||
else if (displayMoney >= 100000000.0)
|
||||
text = str("<font size='25'>") + text + str("</font>");
|
||||
if (pMoneyWindow != NULL)
|
||||
pMoneyWindow->SetText(text);
|
||||
}
|
||||
|
||||
// game @0x00027842
|
||||
void LedgerWindow::Draw(void)
|
||||
{
|
||||
TBSGWindow::Draw();
|
||||
}
|
||||
|
||||
// game @0x0002784e
|
||||
void LedgerWindow::Release(void)
|
||||
{
|
||||
if (pInstance != NULL && pInstance->GetParent() != NULL)
|
||||
pInstance->GetParent()->OrphanChild(pInstance);
|
||||
}
|
||||
|
||||
// game @0x00027874
|
||||
void LedgerWindow::AnimateProduction(void)
|
||||
{
|
||||
for (list<DookieDropper*>::iterator i = droppers.begin(); i != droppers.end(); ++i)
|
||||
(*i)->StartAnimation();
|
||||
}
|
||||
|
||||
// game @0x000278a0
|
||||
void LedgerWindow::UpdateLedger(str action, str data)
|
||||
{
|
||||
TLuaTable* pPlayer = TWindowManager::GetInstance()->GetScript()->GetGlobalTable(str("Player"));
|
||||
TReal rank = (TReal)(float)pPlayer->GetNumber("rank", 1.0);
|
||||
|
||||
bool newPlayer = (action == str("newplayer"));
|
||||
bool all = newPlayer ? true : (action == str("all"));
|
||||
|
||||
if (all || action == str("time"))
|
||||
{
|
||||
lua_Number time = pPlayer->GetNumber("time", 0.0);
|
||||
TText* pDay = GetChildWindowCast<TText>(str("day"), -1);
|
||||
if (pDay != NULL)
|
||||
pDay->SetText(Date(time));
|
||||
TGameState::GetInstance()->SetState(str("GameWeeks"), (int32_t)ClampToUInt(time));
|
||||
}
|
||||
|
||||
if (all || action == str("money"))
|
||||
{
|
||||
lua_Number money = (double)(float)pPlayer->GetNumber("money", 0.0);
|
||||
if (money != targetMoney)
|
||||
{
|
||||
targetMoney = money;
|
||||
deltaMoney = (double)(float)((money - displayMoney) / 20.0);
|
||||
}
|
||||
if (newPlayer)
|
||||
UpdateMoney();
|
||||
}
|
||||
|
||||
if (all || action == str("rank"))
|
||||
{
|
||||
TText* pRank = GetChildWindowCast<TText>(str("rank"), -1);
|
||||
uint32_t rankNumber = ClampToUInt(rank);
|
||||
str key = str::getFormatted("rank_%lu", rankNumber);
|
||||
key = BSGStringTable::GetInstance()->GetString(str(key));
|
||||
if (pRank != NULL)
|
||||
pRank->SetText(str(key));
|
||||
TText* pScore = GetChildWindowCast<TText>(str("score"), -1);
|
||||
if (pScore != NULL)
|
||||
{
|
||||
if (rank != 1.0)
|
||||
BSGShowWindow(pScore);
|
||||
else
|
||||
BSGHideWindow(pScore);
|
||||
}
|
||||
TGameState::GetInstance()->SetState(str("Rank"), (int32_t)rankNumber);
|
||||
}
|
||||
|
||||
if (newPlayer || action == str("quest"))
|
||||
{
|
||||
TText* pQuestText = GetChildWindowCast<TText>(str("questText"), -1);
|
||||
if (pQuestText != NULL)
|
||||
pQuestText->SetText(str(data));
|
||||
}
|
||||
|
||||
if (all || action == str("factory"))
|
||||
{
|
||||
TLuaTable* pFactories = pPlayer->GetTable("factories");
|
||||
for (list<DookieDropper*>::iterator i = droppers.begin(); i != droppers.end(); ++i)
|
||||
{
|
||||
TLuaTable* pFactory = pFactories->GetTable(str((*i)->GetName()).c_str());
|
||||
if (pFactory == NULL)
|
||||
{
|
||||
BSGHideWindow(*i);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pFactory;
|
||||
BSGShowWindow(*i);
|
||||
(*i)->Update();
|
||||
}
|
||||
}
|
||||
delete pFactories;
|
||||
}
|
||||
|
||||
if (action == str("portview"))
|
||||
{
|
||||
BSGHideWindow(GetChildWindow(str("map_port"), -1));
|
||||
BSGShowWindow(GetChildWindow(str("port_map"), -1));
|
||||
}
|
||||
else if (action == str("mapview"))
|
||||
{
|
||||
BSGShowWindow(GetChildWindow(str("map_port"), -1));
|
||||
BSGHideWindow(GetChildWindow(str("port_map"), -1));
|
||||
}
|
||||
|
||||
if (all || action == str("time") || action == str("money"))
|
||||
{
|
||||
lua_Number money = (double)(float)pPlayer->GetNumber("money", 0.0);
|
||||
lua_Number time = pPlayer->GetNumber("time", 0.0);
|
||||
double score = 0.0;
|
||||
if (time > 0.0)
|
||||
score = (double)ClampToUInt(floor(money / time));
|
||||
str dollars = Dollars(score);
|
||||
str result = TPlatform::GetInstance()->GetStringTable()->GetString(str("score_format"), str(dollars), str(), str(), str(), str());
|
||||
TText* pScoreText = GetChildWindowCast<TText>(str("score"), -1);
|
||||
if (pScoreText != NULL)
|
||||
pScoreText->SetText(str(result));
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
delete pPlayer;
|
||||
}
|
||||
|
||||
// game @0x000286c0
|
||||
void LedgerWindow::PrepareInstance(void)
|
||||
{
|
||||
TLuaTable* pPlayer = TWindowManager::GetInstance()->GetScript()->GetGlobalTable(str("Player"));
|
||||
targetMoney = displayMoney = (double)(float)pPlayer->GetNumber("money", 0.0);
|
||||
delete pPlayer;
|
||||
|
||||
pMoneyWindow = GetChildWindowCast<TText>(str("money"), -1);
|
||||
pQuestWindow = GetChildWindow(str("quest"), -1);
|
||||
|
||||
DookieCollector collector(droppers);
|
||||
ForEachChild(&collector, false);
|
||||
|
||||
UpdateLedger(str("all"), str(""));
|
||||
}
|
||||
|
||||
// game @0x0002887c
|
||||
void LedgerWindow::SetQuestIndicator(str mode)
|
||||
{
|
||||
TImage* pImage = GetChildWindowCast<TImage>(str("ledger_questgoals"), -1);
|
||||
if (pImage == NULL)
|
||||
return;
|
||||
|
||||
if (mode == str("on"))
|
||||
{
|
||||
pImage->SetTexture(TTexture::Get(str("image/badge_button_indicator_complete"), 0), 1.0f);
|
||||
}
|
||||
else if (mode == str("flash"))
|
||||
{
|
||||
pImage->SetTexture(TTexture::Get(str("image/badge_button_indicator_complete"), 0), 1.0f);
|
||||
if (!flashQuest)
|
||||
{
|
||||
flashQuest = true;
|
||||
flashTimer = 1500;
|
||||
BSGSoundEvent(str("quest_requirements_met"));
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
pImage->SetTexture(TTexture::Get(str("image/badge_button_indicator_incomplete"), 0), 1.0f);
|
||||
}
|
||||
flashQuest = false;
|
||||
flashTimer = 0;
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x00028afe
|
||||
void LedgerWindow::Animate(void)
|
||||
{
|
||||
bool moneyChanged;
|
||||
|
||||
if (displayMoney == targetMoney)
|
||||
{
|
||||
moneyChanged = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
displayMoney = displayMoney + deltaMoney;
|
||||
if ((deltaMoney < 0.0 && displayMoney < targetMoney) ||
|
||||
(deltaMoney > 0.0 && displayMoney > targetMoney) || deltaMoney == 0.0)
|
||||
displayMoney = targetMoney;
|
||||
UpdateMoney();
|
||||
moneyChanged = true;
|
||||
}
|
||||
|
||||
if (flashQuest)
|
||||
{
|
||||
if (flashTimer < 0x33)
|
||||
flashTimer = 0;
|
||||
else
|
||||
flashTimer -= 50;
|
||||
|
||||
TImage* pImage = GetChildWindowCast<TImage>(str("ledger_questgoals"), -1);
|
||||
if (pImage != NULL)
|
||||
{
|
||||
if (flashTimer % 500 < 250)
|
||||
pImage->SetTexture(TTexture::Get(str("image/badge_button_indicator_complete"), 0), 1.0f);
|
||||
else
|
||||
pImage->SetTexture(TTexture::Get(str("image/badge_button_indicator_incomplete"), 0), 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
for (list<DookieDropper*>::iterator i = droppers.begin(); i != droppers.end(); ++i)
|
||||
(*i)->Animate();
|
||||
|
||||
if (moneyChanged)
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x00028d36
|
||||
bool LedgerWindow::TLedgerAnimTask::Animate(void)
|
||||
{
|
||||
bool alive = (pInstance != NULL);
|
||||
if (alive)
|
||||
pInstance->Animate();
|
||||
return alive;
|
||||
}
|
||||
|
||||
// game @0x00028e54 (C1; the base-class and member initialisation is compiler-generated)
|
||||
LedgerWindow::LedgerWindow(void)
|
||||
{
|
||||
pMoneyWindow = NULL;
|
||||
displayMoney = 0;
|
||||
targetMoney = 0;
|
||||
deltaMoney = 0;
|
||||
pQuestWindow = NULL;
|
||||
flashQuest = true;
|
||||
flashTimer = 0;
|
||||
pTask = NULL;
|
||||
pInstance = this;
|
||||
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "RealUpdateLedger", this, LedgerWindow::UpdateLedger);
|
||||
ScriptRegisterMemberDirect(script, "SetLedgerQuestIndicator", this, LedgerWindow::SetQuestIndicator);
|
||||
ScriptRegisterMemberDirect(script, "AnimateProduction", this, LedgerWindow::AnimateProduction);
|
||||
}
|
||||
|
||||
// game @0x0002919c (D1), game @0x00028d54 (D0)
|
||||
LedgerWindow::~LedgerWindow(void)
|
||||
{
|
||||
pInstance = NULL;
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptUnregisterFunction(script, "RealUpdateLedger");
|
||||
ScriptUnregisterFunction(script, "SetLedgerQuestIndicator");
|
||||
ScriptUnregisterFunction(script, "AnimateProduction");
|
||||
}
|
||||
|
||||
// game @0x0002901a
|
||||
void LedgerWindow::Grab(void)
|
||||
{
|
||||
if (pInstance == NULL)
|
||||
{
|
||||
pInstance = new LedgerWindow;
|
||||
TWindowManager::GetInstance()->RunScript(pInstance, "ui/ledger.lua");
|
||||
pInstance->FitToChildren();
|
||||
pInstance->PrepareInstance();
|
||||
pInstance->pTask = new TLedgerAnimTask;
|
||||
pInstance->pTask->SetDelay(50, true, true, false);
|
||||
TPlatform::GetInstance()->AdoptTask(pInstance->pTask);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pInstance->GetParent() != NULL)
|
||||
pInstance->GetParent()->OrphanChild(pInstance);
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->GetTopModalWindow()->AdoptChild(pInstance, true);
|
||||
pInstance->SetWindowDepth(TWindow::kFrontMost);
|
||||
}
|
||||
620
port/game/MapWindow.cpp
Normal file
620
port/game/MapWindow.cpp
Normal file
|
|
@ -0,0 +1,620 @@
|
|||
// Port of the game's MapWindow.cpp (Chocolatier 3, Big Splash Games): MapWindow, the world map window (port
|
||||
// markers, hover popups, clouds, the travel animation) and TravelTask, the scaled-time task that moves the
|
||||
// travelling sprite along a curve. TravelTask has no shipped header: the game's MapWindow.cpp declares it (the
|
||||
// original MapWindow.h only forward-declares it), so its declaration is written here from the binary.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// MapWindow.h (port/game/MapWindow.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): MapWindow : TWindow 0x30; pPortRoot 0x30, pCurrentPort 0x38, pClouds 0x40, cloudTime 0x48,
|
||||
// cloudTargetTime 0x4c, farY 0x50, nearY 0x54, farScale 0x58, nearScale 0x5c, ports 0x60, travelPaused 0x68,
|
||||
// pTravelTask 0x6c; sizeof 0x70 (MapWindowDynamicCreate allocates 0x70). PortData: name 0x0, pSprite 0x4 (ptr)
|
||||
// and 0x8 (count), 12 bytes. The header matches.
|
||||
// TravelTask : TOldScalingTask (0x28 bytes): pSprite 0x28, pCurve 0x30, fullTime 0x38, farY 0x3c, nearY 0x40,
|
||||
// farScale 0x44, nearScale 0x48, types 0x4c (std::list), typeIter 0x54, events 0x58 (std::list), eventIter 0x60;
|
||||
// sizeof 0x64 (InitiateTravel allocates 100). MapWindow::InitiateTravel writes farY..nearScale straight into the
|
||||
// task, so those fields are public here. TravelType (node data at +8): time 0x0, mode 0x4. TravelEvent: time 0x0,
|
||||
// action 0x4 (a TLuaFunction*, never freed), 8 bytes.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The sprite members of the original code are reached through TSprite::GetDrawSpec(): position = mMatrix[2]
|
||||
// (+0x38/+0x3c), centre = mCenter (+0x44), alpha = mAlpha (+0x5c), flags = mFlags (+0x70, kUseCenter = 8).
|
||||
// - Every float to unsigned conversion in the game goes through the compiler's saturating sequence (min with
|
||||
// 4294967295.0, max with 0, the 2^31 split); the plain C++ cast is used.
|
||||
// - CollectPortData adds the "port_current" marker sprite inside the loop (once per port, after the first port that
|
||||
// is the current one), exactly as the binary does. The label text goes left of the marker when x >= 748 or the
|
||||
// port's "align" is "left" (NaN counts as left), else right.
|
||||
// - TravelTask::Animate: after SetCurrentFrame the matrix of the sprite is rebuilt from the rotation, and if
|
||||
// farY != nearY it is reset with Identity() and only scaled, so the rotation is dropped (the binary does this).
|
||||
//
|
||||
// Strings from the game's __cstring: "InitiateTravel", "PauseTravel", "ResumeTravel", "background", "cloudY",
|
||||
// "image/worldmap_clouds", "cloudTime", "yFar", "yNear", "farScale", "nearScale", "path", "dest", "mapx", "mapy",
|
||||
// "type", "events", "time", "action", "Player", "portsAvailable", "portName", "_AllPorts", "name", "hidden",
|
||||
// "open", "new", "factory", "factory_stall", "shop", "align", "left", "popupX", "popupY", "image/port_visited",
|
||||
// "image/port_new.xml", "image/factory.xml", "image/factory_idle.xml", "image/icon_shop", "image/port_locked.xml",
|
||||
// "DoAnim", "fonts/fertigo.mvec", ":MapRolloverPopup()", ":OnClick()", "image/port_current", "image/traveldot",
|
||||
// "image/", ".xml", "travel_air", "MapWindow", "if not gUIPaused then DoModal('ui/ui_pause.lua') end".
|
||||
//
|
||||
// Static data: MapWindow::pInstance (__bss, NULL).
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in MapWindow.h):
|
||||
// - PFTYPEDEF_DC IsKindOf: game @0x001709e8 (compares the id against &MapWindowDynamicCreate, else calls
|
||||
// TWindow::ClassId and compares).
|
||||
// - MapWindow::PortData: PortData() game @0x00170a14, ~PortData() game @0x00170a38, PortData(const PortData&)
|
||||
// game @0x00170e78.
|
||||
// - TravelTask::TravelType: TravelType() game @0x001704e4, TravelType(const TravelType&) game @0x00170680.
|
||||
// - ~TravelTask (implicit): D1 game @0x00170d20, D0 game @0x00170dc8.
|
||||
// - std::list<MapWindow::PortData>: _List_base ctor game @0x00170754, _M_clear game @0x00170a74, ~_List_base
|
||||
// game @0x00170ab4, list(const list&) game @0x00170ad4, _M_create_node game @0x00170ee8, _M_insert game
|
||||
// @0x00170f58, push_back game @0x00170f84, new_allocator::allocate game @0x001706e8, construct game @0x00170ec0.
|
||||
// - std::list<TravelTask::TravelType>: _List_base ctor game @0x00170774, _M_clear game @0x00170878, ~_List_base
|
||||
// game @0x001708b8, list(const list&) game @0x001708d8, _M_create_node game @0x001708e4, _M_insert game
|
||||
// @0x00170954, push_back game @0x00170980, new_allocator::allocate game @0x001706a0, construct game @0x0017072c.
|
||||
// - std::list<boost::shared_ptr<TravelEvent>>: _List_base ctor game @0x00170764, _M_clear game @0x00170cb0,
|
||||
// ~_List_base game @0x00170cf4, list(const list&) game @0x00170d14, _M_create_node game @0x00170b2c, _M_insert
|
||||
// game @0x00170b9c, push_back game @0x00170bc8, new_allocator::allocate game @0x001706c4, construct game
|
||||
// @0x00170b04.
|
||||
// - boost::shared_ptr<TravelEvent>: shared_ptr(const shared_ptr&) game @0x00170ae0, shared_ptr(TravelEvent*) game
|
||||
// @0x00170be8, shared_count(TravelEvent*, checked_deleter) game @0x001707c0, checked_delete<TravelEvent> game
|
||||
// @0x001705bc, sp_counted_base_impl<TravelEvent*, checked_deleter>: ctor game @0x00170798, dispose game
|
||||
// @0x00170784, get_deleter game @0x0017070c, D1 game @0x0017085c, D0 game @0x00170830.
|
||||
// - Header-inline code emitted out of line (pf/luapluscd.h templates): lua_pushdirectclosure<MapWindow, void
|
||||
// (TLuaTable*)> game @0x00170524, <MapWindow, void ()> game @0x00170570;
|
||||
// LPCD::DirectCallMemberDispatcherHelper<MapWindow, void (TLuaTable*)> game @0x0017063c (its
|
||||
// ReturnSpecialization<void>::Call<MapWindow, TLuaTable*> game @0x001705ec), <MapWindow, void ()> game
|
||||
// game @0x001709a0.
|
||||
// The game also lists undecodable exception-handling clones (.eh) of these functions (0x001ba82c ..); they are not
|
||||
// source functions.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "MapWindow.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "Curve.h"
|
||||
#include "Rollover.h"
|
||||
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/modalwindow.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/stringtable.h"
|
||||
#include "pf/textsprite.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// TravelTask (declared by the game's MapWindow.cpp)
|
||||
|
||||
class TravelTask : public TOldScalingTask
|
||||
{
|
||||
public:
|
||||
TravelTask(TAnimatedSpriteRef sprite, TCurveRef curve, TLuaTable* pTypes);
|
||||
virtual ~TravelTask(void) {}
|
||||
|
||||
virtual bool Animate(void);
|
||||
|
||||
void AddEvent(TReal eventTime, TLuaFunction* action);
|
||||
void SetMode(str mode);
|
||||
|
||||
TAnimatedSpriteRef pSprite;
|
||||
TCurveRef pCurve;
|
||||
TReal fullTime;
|
||||
TReal farY, nearY;
|
||||
TReal farScale, nearScale;
|
||||
|
||||
struct TravelType
|
||||
{
|
||||
TReal time;
|
||||
str mode;
|
||||
};
|
||||
list<TravelType> types;
|
||||
list<TravelType>::iterator typeIter;
|
||||
|
||||
struct TravelEvent
|
||||
{
|
||||
TReal time;
|
||||
TLuaFunction* action;
|
||||
void Trigger(void);
|
||||
};
|
||||
list< ::shared_ptr<TravelEvent> > events;
|
||||
list< ::shared_ptr<TravelEvent> >::iterator eventIter;
|
||||
};
|
||||
|
||||
MapWindow* MapWindow::pInstance = NULL;
|
||||
|
||||
// game @0x0002a37c (ClassId: returns &MapWindowDynamicCreate)
|
||||
// game @0x0002a386 (GetTypeName, "MapWindow")
|
||||
// game @0x0002ab2a (MapWindowDynamicCreate: new MapWindow, sizeof 0x70)
|
||||
PFTYPEIMPL_DC(MapWindow);
|
||||
|
||||
// game @0x0002a390
|
||||
void MapWindow::ResumeTravel(void)
|
||||
{
|
||||
if (pTravelTask != NULL)
|
||||
{
|
||||
pTravelTask->Restart(30);
|
||||
travelPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002a3bc
|
||||
bool MapWindow::OnKeyDown(char key, uint32_t flags)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0002a3c4
|
||||
void MapWindow::PauseTravel(void)
|
||||
{
|
||||
if (pTravelTask != NULL)
|
||||
{
|
||||
pTravelTask->Pause();
|
||||
travelPaused = true;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002a3e8
|
||||
void MapWindow::Draw(void)
|
||||
{
|
||||
TBegin2d begin2d;
|
||||
if (pPortRoot)
|
||||
{
|
||||
pPortRoot->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
}
|
||||
TWindow::Draw();
|
||||
begin2d.Done();
|
||||
}
|
||||
|
||||
// game @0x0002a490
|
||||
void MapWindow::UpdateClouds(void)
|
||||
{
|
||||
uint32_t t = cloudTime;
|
||||
cloudTime = t % cloudTargetTime;
|
||||
pClouds->GetDrawSpec().mMatrix[2].x =
|
||||
((TReal)(uint32_t)(t % cloudTargetTime) / (TReal)cloudTargetTime) * (TReal)GetWindowWidth();
|
||||
}
|
||||
|
||||
// game @0x0002a512
|
||||
bool MapWindow::OnTaskAnimate(void)
|
||||
{
|
||||
cloudTime += 30;
|
||||
UpdateClouds();
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0002a53c
|
||||
void MapWindow::WindowToggleForeground(void)
|
||||
{
|
||||
if (!TPlatform::GetInstance()->IsForeground())
|
||||
{
|
||||
TModalWindow* pTop = TPlatform::GetInstance()->GetWindowManager()->GetTopModalWindow();
|
||||
StopWindowAnimation();
|
||||
if (!travelPaused && (TWindow*)pTop == (TWindow*)this)
|
||||
{
|
||||
TWindowManager::GetInstance()->DoLuaString(this, "if not gUIPaused then DoModal('ui/ui_pause.lua') end");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StartWindowAnimation(30, true, true, false);
|
||||
if (!travelPaused && pTravelTask != NULL)
|
||||
{
|
||||
pTravelTask->Restart(30);
|
||||
travelPaused = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002a622
|
||||
void MapWindow::ToggleForeground(void)
|
||||
{
|
||||
if (pInstance != NULL)
|
||||
{
|
||||
pInstance->WindowToggleForeground();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002a63c (D0), game @0x0002a7ac (D1)
|
||||
MapWindow::~MapWindow(void)
|
||||
{
|
||||
pInstance = NULL;
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptUnregisterFunction(script, "InitiateTravel");
|
||||
ScriptUnregisterFunction(script, "PauseTravel");
|
||||
ScriptUnregisterFunction(script, "ResumeTravel");
|
||||
}
|
||||
|
||||
// game @0x0002a914
|
||||
MapWindow::MapWindow(void) :
|
||||
cloudTime(0),
|
||||
travelPaused(false),
|
||||
pTravelTask(NULL)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "InitiateTravel", this, MapWindow::InitiateTravel);
|
||||
ScriptRegisterMemberDirect(script, "PauseTravel", this, MapWindow::PauseTravel);
|
||||
ScriptRegisterMemberDirect(script, "ResumeTravel", this, MapWindow::ResumeTravel);
|
||||
pInstance = this;
|
||||
}
|
||||
|
||||
// game @0x0002ab68
|
||||
void MapWindow::Init(TWindowStyle& style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
FindParentModal()->SetDefaultFocus(this);
|
||||
|
||||
str background = style.GetString("background", "");
|
||||
pPortRoot = TSprite::Create(0, TTexture::Get(background, 0));
|
||||
pPortRoot->GetDrawSpec().mCenter = TVec2(0, 0);
|
||||
pPortRoot->GetDrawSpec().mFlags |= TDrawSpec::kUseCenter;
|
||||
|
||||
double cloudY = style.GetNumber("cloudY", 360.0);
|
||||
TTextureRef cloudTexture = TTexture::Get("image/worldmap_clouds", 0);
|
||||
pClouds = TSprite::Create(11, cloudTexture);
|
||||
pClouds->GetDrawSpec().mMatrix[2].y = (TReal)cloudY;
|
||||
|
||||
TSpriteRef cloud = TSprite::Create(0, cloudTexture);
|
||||
cloud->GetDrawSpec().mMatrix[2].x = (TReal)cloudTexture->GetWidth();
|
||||
pClouds->AddChild(cloud);
|
||||
|
||||
cloud = TSprite::Create(0, cloudTexture);
|
||||
cloud->GetDrawSpec().mMatrix[2].x = -(TReal)cloudTexture->GetWidth();
|
||||
pClouds->AddChild(cloud);
|
||||
|
||||
pPortRoot->AddChild(pClouds);
|
||||
|
||||
cloudTargetTime = (uint32_t)style.GetNumber("cloudTime", 20000.0);
|
||||
cloudTime = RandRange(0, cloudTargetTime);
|
||||
UpdateClouds();
|
||||
|
||||
farY = (TReal)style.GetNumber("yFar", 0.0);
|
||||
nearY = (TReal)style.GetNumber("yNear", 800.0);
|
||||
farScale = (TReal)style.GetNumber("farScale", 1.0);
|
||||
nearScale = (TReal)style.GetNumber("nearScale", 1.0);
|
||||
}
|
||||
|
||||
// game @0x0002b31c
|
||||
void MapWindow::InitiateTravel(TLuaTable* pTravelData)
|
||||
{
|
||||
if (pTravelTask == NULL)
|
||||
{
|
||||
TCurveRef curve;
|
||||
TLuaTable* pPath = pTravelData->GetTable("path");
|
||||
if (pPath == NULL)
|
||||
{
|
||||
TLuaTable* pDest = pTravelData->GetTable("dest");
|
||||
TVec2 from;
|
||||
TVec2 to;
|
||||
to.x = (TReal)pDest->GetNumber("mapx", 0.0);
|
||||
to.y = (TReal)pDest->GetNumber("mapy", 0.0);
|
||||
from.x = pCurrentPort->GetDrawSpec().mMatrix[2].x;
|
||||
from.y = pCurrentPort->GetDrawSpec().mMatrix[2].y;
|
||||
delete pDest;
|
||||
curve = TCurve::Create(from, from, to, to);
|
||||
}
|
||||
else
|
||||
{
|
||||
curve = TCurve::Create(*pPath);
|
||||
delete pPath;
|
||||
}
|
||||
|
||||
TAnimatedSpriteRef pSprite = TAnimatedSprite::Create(10);
|
||||
pPortRoot->AddChild(pSprite);
|
||||
pSprite->GetDrawSpec().mMatrix[2] = pCurrentPort->GetDrawSpec().mMatrix[2];
|
||||
|
||||
TLuaTable* pType = pTravelData->GetTable("type");
|
||||
pTravelTask = new TravelTask(pSprite, curve, pType);
|
||||
delete pType;
|
||||
pTravelTask->farY = farY;
|
||||
pTravelTask->nearY = nearY;
|
||||
pTravelTask->farScale = farScale;
|
||||
pTravelTask->nearScale = nearScale;
|
||||
|
||||
TLuaTable* pEvents = pTravelData->GetTable("events");
|
||||
if (pEvents != NULL)
|
||||
{
|
||||
lua_Number index = 1.0;
|
||||
TLuaTable* pEvent = pEvents->GetTable(index);
|
||||
while (pEvent != NULL)
|
||||
{
|
||||
TReal eventTime = (TReal)pEvent->GetNumber("time", 0.0);
|
||||
TLuaFunction* action = pEvent->GetFunction("action");
|
||||
pTravelTask->AddEvent(eventTime, action);
|
||||
delete pEvent;
|
||||
index = index + 1.0;
|
||||
pEvent = pEvents->GetTable(index);
|
||||
}
|
||||
delete pEvents;
|
||||
}
|
||||
|
||||
TPlatform::GetInstance()->AdoptTask(pTravelTask);
|
||||
pTravelTask->SetDelay(30, true, true, false);
|
||||
travelPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002b77e
|
||||
void MapWindow::CollectPortData(void)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
TLuaTable* pPlayer = script->GetGlobalTable("Player");
|
||||
TLuaTable* pPortsAvailable = pPlayer->GetTable("portsAvailable");
|
||||
str currentPort = pPlayer->GetString("portName", "");
|
||||
TLuaTable* pAllPorts = script->GetGlobalTable("_AllPorts");
|
||||
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaTable* pPort = (TLuaTable*)pAllPorts->GetNext(&key);
|
||||
while (pPort != NULL)
|
||||
{
|
||||
str name = pPort->GetString("name", "");
|
||||
str status = pPortsAvailable->GetString(name.c_str(), "");
|
||||
if (status != "hidden")
|
||||
{
|
||||
PortData data;
|
||||
data.name = name;
|
||||
data.pSprite = TAnimatedSprite::Create(2);
|
||||
lua_Number mapx = pPort->GetNumber("mapx", 0.0);
|
||||
TReal x = (TReal)mapx;
|
||||
lua_Number mapy = pPort->GetNumber("mapy", 0.0);
|
||||
TReal y = (TReal)mapy;
|
||||
data.pSprite->GetDrawSpec().mMatrix[2] = TVec3(x, y, 0);
|
||||
if (currentPort == name)
|
||||
{
|
||||
pCurrentPort = data.pSprite;
|
||||
}
|
||||
|
||||
if (status == "open")
|
||||
{
|
||||
data.pSprite->SetTexture(TTexture::Get("image/port_visited", 0));
|
||||
}
|
||||
else if (status == "new")
|
||||
{
|
||||
data.pSprite->SetTexture(TAnimatedTexture::Get("image/port_new.xml", "", ""));
|
||||
data.pSprite->Play("DoAnim");
|
||||
}
|
||||
else if (status == "factory")
|
||||
{
|
||||
data.pSprite->SetTexture(TAnimatedTexture::Get("image/factory.xml", "", ""));
|
||||
data.pSprite->Play("DoAnim");
|
||||
}
|
||||
else if (status == "factory_stall")
|
||||
{
|
||||
data.pSprite->SetTexture(TAnimatedTexture::Get("image/factory_idle.xml", "", ""));
|
||||
data.pSprite->Play("DoAnim");
|
||||
}
|
||||
else if (status == "shop")
|
||||
{
|
||||
data.pSprite->SetTexture(TTexture::Get("image/icon_shop", 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
data.pSprite->SetTexture(TAnimatedTexture::Get("image/port_locked.xml", "", ""));
|
||||
}
|
||||
|
||||
pPortRoot->AddChild(data.pSprite);
|
||||
ports.push_back(data);
|
||||
|
||||
str align = pPort->GetString("align", "");
|
||||
TTextSpriteRef pShadow;
|
||||
TTextSpriteRef pText;
|
||||
TReal textX;
|
||||
if (!(x < 750.0f) || align == "left")
|
||||
{
|
||||
textX = x - 10.0f;
|
||||
pShadow = TTextSprite::Create(200, 20, 6, "fonts/fertigo.mvec", 20, TColor(0, 0, 0, 1), 3);
|
||||
pText = TTextSprite::Create(200, 20, 6, "fonts/fertigo.mvec", 20, TColor(1, 1, 1, 1), -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
textX = x + 10.0f;
|
||||
pShadow = TTextSprite::Create(200, 20, 4, "fonts/fertigo.mvec", 20, TColor(0, 0, 0, 1), 3);
|
||||
pText = TTextSprite::Create(200, 20, 4, "fonts/fertigo.mvec", 20, TColor(1, 1, 1, 1), -1);
|
||||
}
|
||||
|
||||
pShadow->SetText(TPlatform::GetInstance()->GetStringTable()->GetString(name));
|
||||
pText->SetText(TPlatform::GetInstance()->GetStringTable()->GetString(name));
|
||||
|
||||
pShadow->GetDrawSpec().mMatrix[2] = TVec3(textX, y, 0);
|
||||
pShadow->AddChild(pText);
|
||||
pText->GetDrawSpec().mMatrix[2] = TVec3(2.0f + textX, y + 2.0f, 0);
|
||||
pText->GetDrawSpec().mAlpha = 0.75f;
|
||||
pPortRoot->AddChild(pShadow);
|
||||
|
||||
lua_Number popupX = pPort->GetNumber("popupX", (double)((int)x + 10));
|
||||
lua_Number popupY = pPort->GetNumber("popupY", (double)((int)y + -48));
|
||||
TRect area((int)(x - 17.0f), (int)(y - 17.0f), (int)(x + 17.0f), (int)(17.0f + y));
|
||||
Rollover* pRollover = new Rollover(area, name + ":MapRolloverPopup()", name + ":OnClick()");
|
||||
if (pRollover != NULL)
|
||||
{
|
||||
pRollover->SetPopupPosition((int)popupX, (int)popupY);
|
||||
AdoptChild(pRollover, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (pCurrentPort)
|
||||
{
|
||||
TSpriteRef pCurrent = TSprite::Create(0, TTexture::Get("image/port_current", 0));
|
||||
pCurrent->GetDrawSpec().mMatrix[2] = pCurrentPort->GetDrawSpec().mMatrix[2];
|
||||
pPortRoot->AddChild(pCurrent);
|
||||
}
|
||||
|
||||
delete pPort;
|
||||
pPort = (TLuaTable*)pAllPorts->GetNext(&key);
|
||||
}
|
||||
|
||||
delete pAllPorts;
|
||||
delete pPortsAvailable;
|
||||
delete pPlayer;
|
||||
}
|
||||
|
||||
// game @0x0002d12c
|
||||
void MapWindow::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
CollectPortData();
|
||||
StartWindowAnimation(30, true, true, false);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// TravelTask
|
||||
|
||||
// game @0x001704f4
|
||||
void TravelTask::TravelEvent::Trigger(void)
|
||||
{
|
||||
if (action != NULL)
|
||||
{
|
||||
action->Push();
|
||||
TWindowManager::GetInstance()->GetScript()->InjectFunction();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00170c24
|
||||
void TravelTask::AddEvent(TReal eventTime, TLuaFunction* action)
|
||||
{
|
||||
if (fullTime < eventTime)
|
||||
{
|
||||
fullTime = eventTime;
|
||||
}
|
||||
|
||||
TravelEvent* pEvent = new TravelEvent;
|
||||
pEvent->time = eventTime;
|
||||
pEvent->action = action;
|
||||
events.push_back(::shared_ptr<TravelEvent>(pEvent));
|
||||
eventIter = events.begin();
|
||||
}
|
||||
|
||||
// game @0x00170fa4
|
||||
void TravelTask::SetMode(str mode)
|
||||
{
|
||||
str texture(mode);
|
||||
if (texture.find('/', 0, 0) == str::npos)
|
||||
{
|
||||
texture = str("image/") + texture;
|
||||
}
|
||||
if (texture.find('.', 0, 0) == str::npos)
|
||||
{
|
||||
texture = texture + str(".xml");
|
||||
}
|
||||
pSprite->SetTexture(TAnimatedTexture::Get(texture, "", ""));
|
||||
}
|
||||
|
||||
// game @0x00171214
|
||||
TravelTask::TravelTask(TAnimatedSpriteRef sprite, TCurveRef curve, TLuaTable* pTypes) :
|
||||
pSprite(sprite),
|
||||
pCurve(curve),
|
||||
fullTime(0),
|
||||
farY(0),
|
||||
nearY(0),
|
||||
farScale(1.0f),
|
||||
nearScale(1.0f)
|
||||
{
|
||||
pSprite->SetVisible(false);
|
||||
eventIter = events.begin();
|
||||
|
||||
if (pTypes != NULL)
|
||||
{
|
||||
for (uint32_t i = 1; i <= pTypes->GetSize(); i++)
|
||||
{
|
||||
TLuaTable* pEntry = pTypes->GetTable((lua_Number)i);
|
||||
if (pEntry != NULL)
|
||||
{
|
||||
TravelType type;
|
||||
type.time = (TReal)pEntry->GetNumber(1.0, 0.0);
|
||||
type.mode = pEntry->GetString(2.0, "travel_air");
|
||||
types.push_back(type);
|
||||
delete pEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typeIter = types.begin();
|
||||
if (typeIter == types.end())
|
||||
{
|
||||
SetMode("travel_air");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetMode(typeIter->mode);
|
||||
++typeIter;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00171544
|
||||
bool TravelTask::Animate(void)
|
||||
{
|
||||
TReal oldT = GetT(fullTime);
|
||||
TOldScalingTask::Animate();
|
||||
TReal newT = GetT(fullTime);
|
||||
TReal t = (time < fullTime) ? newT : 1.0f;
|
||||
|
||||
// Drop a dot on the path for every 12 units of path length travelled since the last tick.
|
||||
uint32_t dot = (uint32_t)(oldT * pCurve->GetLength()) / 12;
|
||||
TReal end = pCurve->GetLength() * t;
|
||||
uint32_t length = dot * 12;
|
||||
while (dot < (uint32_t)end / 12)
|
||||
{
|
||||
TVec2 at = pCurve->GetPoint((TReal)length / pCurve->GetLength(), NULL);
|
||||
TSpriteRef pDot = TSprite::Create(1, TTexture::Get("image/traveldot", 0));
|
||||
pDot->GetDrawSpec().mMatrix[2] = TVec3(at, 1.0f);
|
||||
TSprite* pParent = pSprite->GetParent();
|
||||
if (pParent != NULL)
|
||||
{
|
||||
pParent->AddChild(pDot);
|
||||
}
|
||||
dot++;
|
||||
length += 12;
|
||||
}
|
||||
|
||||
while (typeIter != types.end() && typeIter->time <= t)
|
||||
{
|
||||
SetMode(typeIter->mode);
|
||||
++typeIter;
|
||||
}
|
||||
|
||||
TVec2 tangent;
|
||||
TVec2 point = pCurve->GetPoint(t, &tangent);
|
||||
double degrees = ((double)acosf(tangent.y) * -180.0) / 3.141592653589793 + 180.0;
|
||||
if (tangent.x < 0.0f)
|
||||
{
|
||||
degrees = 360.0 - degrees;
|
||||
}
|
||||
|
||||
double frameStep = 360.0 / (double)pSprite->GetNumFrames();
|
||||
uint32_t numFrames = pSprite->GetNumFrames();
|
||||
uint32_t frame = (uint32_t)(degrees / frameStep + 0.5);
|
||||
frame = frame % numFrames;
|
||||
pSprite->SetCurrentFrame(frame);
|
||||
pSprite->GetDrawSpec().mMatrix =
|
||||
TMat3::GetRotation((TReal)(((degrees - frameStep * (double)frame) * 3.141592653589793) / 180.0));
|
||||
|
||||
if (farY != nearY)
|
||||
{
|
||||
TReal scale = ((point.y - farY) / (nearY - farY)) * (nearScale - farScale) + farScale;
|
||||
pSprite->GetDrawSpec().mMatrix.Identity().Scale(scale, scale);
|
||||
}
|
||||
pSprite->GetDrawSpec().mMatrix[2] = TVec3(point, 1.0f);
|
||||
|
||||
TReal rawTime = time;
|
||||
while (eventIter != events.end())
|
||||
{
|
||||
if (rawTime < (*eventIter)->time)
|
||||
{
|
||||
if (t != 1.0f)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
(*eventIter)->Trigger();
|
||||
++eventIter;
|
||||
}
|
||||
|
||||
pSprite->SetVisible(true);
|
||||
return t < 1.0f;
|
||||
}
|
||||
163
port/game/PathSprite.cpp
Normal file
163
port/game/PathSprite.cpp
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
// Port of the game's PathSprite.cpp (Chocolatier 3, Big Splash Games): TPathSprite, an animated sprite that follows a
|
||||
// TCurve over a duration (one way, pause at the end, loop or bounce), optionally scaling and speeding up with its
|
||||
// y position, and picking its animation frame from the direction of travel.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// PathSprite.h (port/game/PathSprite.h, unchanged). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): TPathSprite : TAnimatedSprite (0x84) pCurve 0x84/0x88, time 0x8c, duration 0x90, offset 0x94,
|
||||
// scale 0x98, mode 0x9c, pMask 0xa0/0xa4, scaleType 0xa8, far 0xac, near 0xb4, scaleFar 0xbc, scaleNear 0xc0,
|
||||
// speedFar 0xc4, speedNear 0xc8, sizeof 0xcc (Create allocates 0xcc bytes). The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The constructor sets time = duration = offset = 0, scale = 1, mode = ONEWAY, scaleType = SCALE_NONE, far = near =
|
||||
// (0, 0) and scaleFar = scaleNear = speedFar = speedNear = 1.
|
||||
// - SetScaling sets scaleType = SCALE_Y (1), far = (0, yFar), near = (0, yNear), the two scales, and recomputes
|
||||
// scale from the sprite's current y (draw matrix row 2, y at 0x3c).
|
||||
// - Update: time advances by delta (speedFar == speedNear) or by delta times the speed interpolated by y between
|
||||
// speedFar and speedNear. ONEWAY / PAUSE past the duration: the sprite sits at the curve's end (GetPoint(1)) and,
|
||||
// for ONEWAY with a parent sprite (TSprite parent at 0xc), is removed from that parent (RemoveChild, TSprite
|
||||
// slot 0x14) - the rest of the update (scale, frame, matrix) is still executed. Otherwise the curve parameter is
|
||||
// fmod(time / duration + offset, 1) (BOUNCE: fmod(..., 2), mirrored to 2 - t when >= 1) and the tangent comes
|
||||
// from GetPoint. The scale is 1 (SCALE_NONE) or scaleFar + (y - far.y) / (near.y - far.y) * (scaleNear -
|
||||
// scaleFar). With more than one animation frame the frame is chosen from the tangent direction: angle =
|
||||
// acosf(tangent.y) * -180 / pi + 180 (360 - angle when tangent.x < 0), frame = (unsigned)(angle / (360 /
|
||||
// frames) + 0.5) % frames, set on the sprite and on the mask sprite when there is one. The draw matrix becomes
|
||||
// the identity scaled by (scale, scale) with the position (point, 1).
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFSHAREDTYPEDEF / PFTYPEIMPL: GetTypeName game @0x0002dd36 ("TPathSprite"), IsKindOf game @0x00171da0.
|
||||
// ~TPathSprite (releases pMask and pCurve, then ~TAnimatedSprite): D1 game @0x0002de62, D0 game @0x0002dfca.
|
||||
// TSprite::GetCast<TPathSprite> game @0x00171f2c, shared_ptr<TPathSprite> / list<shared_ptr<TPathSprite>>
|
||||
// instantiations (game @0x00171dcc..0x00172828) are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "PathSprite.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
PFTYPEIMPL(TPathSprite);
|
||||
|
||||
// game @0x0002dd40
|
||||
void TPathSprite::SetSpeed(TReal speedFar_, TReal speedNear_)
|
||||
{
|
||||
speedFar = speedFar_;
|
||||
speedNear = speedNear_;
|
||||
}
|
||||
|
||||
// game @0x0002dd5a
|
||||
void TPathSprite::SetScaling(TReal yFar, TReal yNear, TReal scaleFar_, TReal scaleNear_)
|
||||
{
|
||||
scaleType = SCALE_Y;
|
||||
far = TVec2(0, yFar);
|
||||
near = TVec2(0, yNear);
|
||||
scaleFar = scaleFar_;
|
||||
scaleNear = scaleNear_;
|
||||
scale = ((GetDrawSpec().mMatrix[2].y - far.y) / (near.y - far.y)) * (scaleNear_ - scaleFar_) + scaleFar_;
|
||||
}
|
||||
|
||||
// game @0x0002de20
|
||||
void TPathSprite::SetCurve(TCurveRef pCurve_, TReal duration_, PathMode mode_)
|
||||
{
|
||||
pCurve = pCurve_;
|
||||
duration = duration_;
|
||||
mode = mode_;
|
||||
}
|
||||
|
||||
// game @0x0002ded2
|
||||
TPathSprite::TPathSprite(int32_t layer) :
|
||||
TAnimatedSprite(layer),
|
||||
time(0),
|
||||
duration(0),
|
||||
offset(0),
|
||||
scale(1.0f),
|
||||
mode(ONEWAY),
|
||||
scaleType(SCALE_NONE),
|
||||
far(0, 0),
|
||||
near(0, 0),
|
||||
scaleFar(1.0f),
|
||||
scaleNear(1.0f),
|
||||
speedFar(1.0f),
|
||||
speedNear(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0002de62 (D1), game @0x0002dfca (D0)
|
||||
TPathSprite::~TPathSprite(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0002e042
|
||||
TPathSpriteRef TPathSprite::GetRef(void)
|
||||
{
|
||||
return shared_from_this()->GetCast<TPathSprite>();
|
||||
}
|
||||
|
||||
// game @0x0002e0aa
|
||||
TPathSpriteRef TPathSprite::Create(int32_t layer)
|
||||
{
|
||||
return TPathSpriteRef(new TPathSprite(layer));
|
||||
}
|
||||
|
||||
// game @0x0002e0fe
|
||||
void TPathSprite::Update(uint32_t delta)
|
||||
{
|
||||
if (speedNear == speedFar) {
|
||||
time = (TReal)delta + time;
|
||||
}
|
||||
else {
|
||||
time = (((GetDrawSpec().mMatrix[2].y - far.y) / (near.y - far.y)) * (speedNear - speedFar) + speedFar) *
|
||||
(TReal)delta + time;
|
||||
}
|
||||
|
||||
TVec2 point;
|
||||
TVec2 tangent;
|
||||
bool atEnd = false;
|
||||
if ((uint32_t)mode < 2) {
|
||||
if (duration <= time) {
|
||||
point = pCurve->GetPoint(1.0f, 0);
|
||||
if (mode == ONEWAY) {
|
||||
TSprite* pParent = GetParent();
|
||||
if (pParent != 0) {
|
||||
pParent->RemoveChild(GetRef());
|
||||
}
|
||||
}
|
||||
atEnd = true;
|
||||
}
|
||||
}
|
||||
if (!atEnd) {
|
||||
TReal t;
|
||||
if (mode == BOUNCE) {
|
||||
t = (TReal)fmod((double)(time / duration + offset), 2.0);
|
||||
if (1.0f <= t) {
|
||||
t = 2.0f - t;
|
||||
}
|
||||
}
|
||||
else {
|
||||
t = (TReal)fmod((double)(time / duration + offset), 1.0);
|
||||
}
|
||||
point = pCurve->GetPoint(t, &tangent);
|
||||
}
|
||||
|
||||
scale = 1.0f;
|
||||
if (scaleType == SCALE_Y) {
|
||||
scale = scaleFar + ((point.y - far.y) / (near.y - far.y)) * (scaleNear - scaleFar);
|
||||
}
|
||||
if (GetNumFrames() > 1) {
|
||||
TReal arc = acosf(tangent.y);
|
||||
double angle = ((double)arc * -180.0) / 3.141592653589793 + 180.0;
|
||||
if (tangent.x < 0.0f) {
|
||||
angle = 360.0 - angle;
|
||||
}
|
||||
uint32_t frames = GetNumFrames();
|
||||
double frameValue = angle / (360.0 / (double)GetNumFrames()) + 0.5;
|
||||
uint32_t frame = (uint32_t)frameValue % frames;
|
||||
SetCurrentFrame((int32_t)frame);
|
||||
if (pMask) {
|
||||
pMask->SetCurrentFrame((int32_t)frame);
|
||||
}
|
||||
}
|
||||
GetDrawSpec().mMatrix.Identity();
|
||||
GetDrawSpec().mMatrix.Scale(scale, scale);
|
||||
GetDrawSpec().mMatrix[2] = TVec3(point, 1.0f);
|
||||
}
|
||||
148
port/game/Popup.cpp
Normal file
148
port/game/Popup.cpp
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
// Port of the game's Popup.cpp (Chocolatier 3, Big Splash Games): PopupWindow, a TBSGWindow that is shown while a
|
||||
// TPopupTest (here a TPopupTestRect) says the mouse is still over its trigger area, plus the popup test classes.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original Popup.h
|
||||
// (port/game/Popup.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): PopupWindow : TBSGWindow (0x50) clickString 0x50, pClickFunction 0x54/0x58, pCloseTester
|
||||
// 0x5c/0x60, pTransitionActive 0x64/0x68, clickActive 0x6c; sizeof 0x70 (Rollover allocates 0x70). The constructor
|
||||
// also clears the TBSGWindow member at 0x38 (fill). TPopupTest: vptr 0x0; TPopupTestRect: hotRect 0x4..0x10, sizeof
|
||||
// 0x14. The headers match.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Reposition keeps the window inside the screen minus a 4 pixel margin: if the right edge passes the margin the
|
||||
// window is shifted left by the overshoot and moved down 0x20 (32); if the bottom passes it, only shifted up.
|
||||
// - SetContents runs the Lua string for this window, fits to children, sets alpha 0 (propagating) and starts a
|
||||
// FadeInTransition(this, 1.0f, 125, no end function) whose "active" flag is kept in pTransitionActive.
|
||||
// - Kill removes the mouse listener, orphans the window from its parent, hides it and destroys it safely.
|
||||
// - OnMouseUp kills the popup; then, if the click was pressed here (clickActive), runs pClickFunction (Push +
|
||||
// TScript::InjectFunction) or, without a function, the click string via TScript::DoLuaString(str, -1, 0).
|
||||
//
|
||||
// Compiler-generated in the game / header-inline code emitted out of line (bodies match Popup.h):
|
||||
// - PFTYPEDEF IsKindOf: game @0x00172178 (compares the id against &PopupWindow::ClassId, else calls
|
||||
// TBSGWindow::IsKindOf). ClassId returns its own address.
|
||||
// - TPopupTest::KeepVisible game @0x00173110 (returns false), ~TPopupTest D1 game @0x00173118, D0 game @0x0017312c.
|
||||
// - TPopupTestRect::TPopupTestRect(TRect const&) game @0x00173148; KeepVisible game @0x00173180 (hotRect.Contains:
|
||||
// x1 <= x < x2 and y1 <= y < y2); ~TPopupTestRect D1 game @0x00173490, D0 game @0x001734b0.
|
||||
// - boost::shared_ptr<TPopupTest>(TPopupTest*) game @0x001721bc with shared_count (game @0x001720bc), the
|
||||
// sp_counted_base_impl<TPopupTest*, checked_deleter<TPopupTest>> constructor (game @0x00172094), dispose
|
||||
// (game @0x00172078, deletes the object through its virtual destructor), get_deleter (game @0x00172058) and
|
||||
// destructors D0 game @0x00172130 / D1 game @0x0017215c.
|
||||
// - ~PopupWindow: D1 game @0x0002e8f6, D0 game @0x0002ea3a (also deletes); the body clears *pTransitionActive and
|
||||
// the members (pTransitionActive, pCloseTester, pClickFunction, clickString) are released by the compiler.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "Popup.h"
|
||||
#include "BSGHelpers.h"
|
||||
#include "Transitions.h"
|
||||
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/screen.h"
|
||||
#include "pf/modalwindow.h"
|
||||
|
||||
// game @0x0002e59a (GetTypeName, "PopupWindow")
|
||||
PFTYPEIMPL(PopupWindow);
|
||||
|
||||
// game @0x0002e5a4
|
||||
void PopupWindow::Reposition(int32_t x, int32_t y)
|
||||
{
|
||||
TRect rect(0, 0, 0, 0);
|
||||
GetClientRect(&rect);
|
||||
rect.x1 += x;
|
||||
rect.x2 += x;
|
||||
rect.y1 += y;
|
||||
rect.y2 += y;
|
||||
|
||||
TScreen* pScreen = TWindowManager::GetInstance()->GetScreen();
|
||||
TRect const& screen = pScreen->GetParentRelativeRect();
|
||||
int32_t maxX = (screen.x2 - screen.x1) - 4;
|
||||
int32_t maxY = (screen.y2 - screen.y1) - 4;
|
||||
|
||||
if (maxX < rect.x2) {
|
||||
rect.x1 -= rect.x2 - maxX;
|
||||
rect.y1 += 0x20;
|
||||
rect.y2 += 0x20;
|
||||
}
|
||||
if (maxY < rect.y2) {
|
||||
rect.y1 -= rect.y2 - maxY;
|
||||
}
|
||||
SetWindowPos(rect.x1, rect.y1);
|
||||
}
|
||||
|
||||
// game @0x0002e65e
|
||||
void PopupWindow::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TBSGWindow::PostChildrenInit(style);
|
||||
FitToChildren();
|
||||
}
|
||||
|
||||
// game @0x0002e684
|
||||
bool PopupWindow::OnMouseDown(TPoint const& point)
|
||||
{
|
||||
clickActive = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0002e696
|
||||
void PopupWindow::Kill(void)
|
||||
{
|
||||
TWindowManager::GetInstance()->RemoveMouseListener(this);
|
||||
GetParent()->OrphanChild(this);
|
||||
BSGHideWindow(this);
|
||||
TWindowManager::GetInstance()->SafeDestroyWindow(this);
|
||||
}
|
||||
|
||||
// game @0x0002e6e0
|
||||
bool PopupWindow::OnMouseUp(TPoint const& point)
|
||||
{
|
||||
Kill();
|
||||
if (!pClickFunction || !clickActive) {
|
||||
if (clickString.length() != 0 && clickActive) {
|
||||
TWindowManager::GetInstance()->GetScript()->DoLuaString(clickString, -1, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pClickFunction->Push();
|
||||
TWindowManager::GetInstance()->GetScript()->InjectFunction();
|
||||
}
|
||||
clickActive = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0002e7a0
|
||||
bool PopupWindow::OnMouseMove(TPoint const& point)
|
||||
{
|
||||
TPoint screenMouse = point;
|
||||
ClientToScreen(&screenMouse);
|
||||
bool keep = pCloseTester->KeepVisible(screenMouse);
|
||||
if (!keep) {
|
||||
Kill();
|
||||
}
|
||||
return keep;
|
||||
}
|
||||
|
||||
// game @0x0002e7f2
|
||||
void PopupWindow::SetContents(str luaCommand)
|
||||
{
|
||||
TWindowManager::GetInstance()->DoLuaString(this, luaCommand);
|
||||
FitToChildren();
|
||||
SetAlpha(0, true);
|
||||
pTransitionActive = StartTransition(new FadeInTransition(this, 1.0f, 125, 0));
|
||||
}
|
||||
|
||||
// game @0x0002e8f6 (D1), game @0x0002ea3a (D0)
|
||||
PopupWindow::~PopupWindow(void)
|
||||
{
|
||||
if (pTransitionActive) {
|
||||
*pTransitionActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002e9aa
|
||||
PopupWindow::PopupWindow(TPopupTest* pTest)
|
||||
: pCloseTester(pTest)
|
||||
{
|
||||
fill = false;
|
||||
clickActive = false;
|
||||
}
|
||||
700
port/game/PortWindow.cpp
Normal file
700
port/game/PortWindow.cpp
Normal file
|
|
@ -0,0 +1,700 @@
|
|||
// Port of the game's PortWindow.cpp (Chocolatier 3, Big Splash Games): PortWindow, the harbour screen that shows one
|
||||
// port. It builds the sprite scene from the window style's "port" table (the buildings with their rollover
|
||||
// highlights and name labels, and the animated or static decoration sprites with optional masks, tints and tiling),
|
||||
// fades the window in, runs the highlight pulse and the ambient music timer from a free-running PortAnimTask (so the
|
||||
// port keeps animating while the window is in the background), and turns a click on a building into
|
||||
// "<building>:OnClick()" in the window script.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// PortWindow.h (port/game/PortWindow.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TWindow 0x0..0x30; explicitPause 0x30, pAnimTask 0x34, startTime 0x38, lastTime 0x3c,
|
||||
// rolloverTime 0x40, pPortRoot 0x44 (TSpriteRef), musicTime 0x4c, music 0x50, buildings 0x54 (std::list head),
|
||||
// targetBuilding 0x5c, mouseDown 0x60, masks 0x64, sprites 0x6c; sizeof 0x74 (PortWindowDynamicCreate allocates
|
||||
// 0x74 bytes). The header matches. BuildingInfo (list node data at +8): name 0x0, pSprite 0x4, pRollover 0xc, pLabel
|
||||
// 0x14, rolloverScale 0x18; sizeof 0x1c.
|
||||
// PortAnimTask has no header: it is declared here (pflib layer, game @0x001721f8..0x00172260): TAnimTask (0x18 bytes)
|
||||
// plus the PortWindow pointer at 0x18; sizeof 0x1c.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants read from the binary: 1.0f (@0x001ab6e4), 50.0f (@0x001ab700), 2.0f (@0x001ab71c), 500.0f
|
||||
// (@0x001ab724), 1500.0f (@0x001ab748), 0.8f (@0x001ab74c), -2.0f (@0x001ab750), 100.0f (@0x001ab754), 20.0f
|
||||
// (@0x001ab758), 1.2f (@0x001ab75c); 0.0f (@0x001ab6e8); doubles 0.25 (@0x001ab4d8), 0.5 (@0x001ab488), -0.5
|
||||
// (@0x001ab490), 1.0 (@0x001ab470), 0.4 (@0x001ab578), 0.75 (@0x001ab560), 2000.0 (@0x001ab568), -2.0
|
||||
// (@0x001ab570).
|
||||
// - The game's double -> uint32_t conversion is an inline clamp to [0, 4294967295] followed by the usual
|
||||
// subtract-2^31 conversion (constants @0x00192de0/@0x00192df0, @0x00192e70/@0x00192e80); a float -> uint32_t
|
||||
// one clamps to [0, 4294967296) (@0x00192e20/@0x00192e30). ClampToUInt32 below reproduces both.
|
||||
// - TLuaTable::GetNext hands back plain TLuaObjectWrapper values; the game uses them as tables, so they are
|
||||
// cast to TLuaTable.
|
||||
// - Texture virtual slots 0x24 / 0x28 in CollectBuildingData are GetWidth / GetHeight (declaration order of
|
||||
// TTexture); TSprite::mDrawSpec sits at 0x20, so +0x38 is mMatrix[2], +0x44 mCenter, +0x4c mTint, +0x70 mFlags.
|
||||
//
|
||||
// Strings from the game's __cstring: "PortWindow", "background", "curve_editor", "port", "musicDelay",
|
||||
// "port_music%lu", "Stop_Music", "if not gUIPaused then DoModal('ui/ui_pause.lua') end", "gCurrentBuilding=nil;",
|
||||
// ":OnClick()", "PausePortAnimations", "buildings", "sprites", "name", "x", "y", "layer", "labelx", "labely",
|
||||
// "ports/", "/", "ports/temp_building", "yFar", "yNear", "scaleFar", "scaleNear", "frequency", "images", "masks",
|
||||
// "image", "mask", "behind", "path", "time", "motion", "loop", "oneway", "bounce", "random", "scale", "speedFar",
|
||||
// "speedNear", "htile", ".xml", "DoAnim", "tints", "tint".
|
||||
//
|
||||
// Compiler-generated or header-inline code emitted out of line:
|
||||
// - PFTYPEDEF_DC: IsKindOf game @0x00172538 (compares the id against &PortWindowDynamicCreate, else calls
|
||||
// TWindow::IsKindOf), PortWindowDynamicCreate game @0x0002f440 (new PortWindow, sizeof 0x74), ClassId game
|
||||
// game @0x0002eaf8, GetTypeName game @0x0002eb02; the PortWindow vtable is at game @0x0021c128.
|
||||
// - lua_pushdirectclosure<PortWindow, void (PortWindow::*)(bool)> game @0x00172304 with
|
||||
// LPCD::ReturnSpecialization<void>::Call<PortWindow, bool> game @0x001723e8 and
|
||||
// LPCD::DirectCallMemberDispatcherHelper<PortWindow, void (PortWindow::*)(bool)>::DirectCallMemberDispatcher game
|
||||
// game @0x0017243c (the dispatcher Init registers as "PausePortAnimations").
|
||||
// - PortWindow::BuildingInfo: implicit default constructor game @0x00172710, copy constructor game @0x00172904,
|
||||
// destructor game @0x001725d4; std::list<BuildingInfo> instantiations: new_allocator<_List_node>::allocate game
|
||||
// @0x00172480, _List_base copy constructor game @0x00172528, _M_clear game @0x00172634, ~_List_base game
|
||||
// @0x00172674, list(const allocator&) game @0x00172694, new_allocator::construct game @0x0017297c, _M_create_node
|
||||
// game @0x001729a4, _M_insert game @0x00172a14, push_back game @0x00172a40.
|
||||
// - The PortWindow constructor's list members (std::list<TSpriteRef>, std::list<TPathSpriteRef>) and destructor
|
||||
// calls are compiler-generated from the member declarations (instantiations shared with other classes).
|
||||
// - ~PortWindow: D0 game @0x0002f1fe (deleting), D1 game @0x0002f2e2 (complete); the constructor is game
|
||||
// @0x0002f3be. The game also lists undecodable exception-handling clones (.eh) of these functions; they are not
|
||||
// source functions.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "PortWindow.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGSound.h"
|
||||
#include "CurveEditor.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/animtask.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/sprite.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
|
||||
// The game's inline double -> uint32_t conversion (see the notes above).
|
||||
static uint32_t ClampToUInt32(double value)
|
||||
{
|
||||
double clamped = value;
|
||||
if (4294967295.0 <= value) {
|
||||
clamped = 4294967295.0;
|
||||
}
|
||||
if (clamped <= 0.0) {
|
||||
clamped = 0.0;
|
||||
}
|
||||
double bias = (2147483648.0 <= value) ? 2147483648.0 : 0.0;
|
||||
return (uint32_t)(int32_t)(clamped - bias) ^ ((2147483648.0 <= value) ? 0x80000000u : 0u);
|
||||
}
|
||||
|
||||
// The game's inline float -> uint32_t conversion (see the notes above).
|
||||
static uint32_t ClampToUInt32(float value)
|
||||
{
|
||||
float clamped = value;
|
||||
if (clamped <= 0.0f) {
|
||||
clamped = 0.0f;
|
||||
}
|
||||
float bias = (2147483648.0f <= clamped) ? 2147483648.0f : 0.0f;
|
||||
uint32_t result = (uint32_t)(int32_t)(clamped - bias);
|
||||
if (2147483648.0f <= clamped) {
|
||||
result += 0x80000000u;
|
||||
}
|
||||
if (4294967296.0f <= clamped) {
|
||||
result = 0xffffffffu;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// game @0x001721f8 (C1), @0x00172228 (Animate), @0x00172244 (D1), game @0x00172260 (D0)
|
||||
class PortAnimTask : public TAnimTask
|
||||
{
|
||||
public:
|
||||
PortAnimTask(PortWindow* window);
|
||||
virtual ~PortAnimTask(void);
|
||||
virtual bool Animate(void);
|
||||
|
||||
protected:
|
||||
PortWindow* pWindow;
|
||||
};
|
||||
|
||||
// game @0x001721f8
|
||||
PortAnimTask::PortAnimTask(PortWindow* window) : TAnimTask(NULL)
|
||||
{
|
||||
pWindow = window;
|
||||
}
|
||||
|
||||
// game @0x00172228 (calls the window's vtable slot 0x74, DoAnimation)
|
||||
bool PortAnimTask::Animate(void)
|
||||
{
|
||||
pWindow->DoAnimation();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00172244 (D1), game @0x00172260 (D0)
|
||||
PortAnimTask::~PortAnimTask(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// game @0x0002f3be
|
||||
PortWindow* PortWindow::pInstance = NULL;
|
||||
|
||||
PFTYPEIMPL_DC(PortWindow);
|
||||
|
||||
// game @0x0002f3be
|
||||
PortWindow::PortWindow(void)
|
||||
{
|
||||
explicitPause = false;
|
||||
pAnimTask = NULL;
|
||||
music = true;
|
||||
pInstance = this;
|
||||
}
|
||||
|
||||
// game @0x0002f1fe (D0), @0x0002f2e2 (D1)
|
||||
PortWindow::~PortWindow(void)
|
||||
{
|
||||
pInstance = NULL;
|
||||
if (pAnimTask != NULL) {
|
||||
TPlatform::GetInstance()->OrphanTask(pAnimTask);
|
||||
delete pAnimTask;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002eb0c
|
||||
bool PortWindow::OnKeyDown(char key, uint32_t flags)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0002eb14
|
||||
void PortWindow::InternalPausePortAnimations(bool pause)
|
||||
{
|
||||
if (pAnimTask != NULL) {
|
||||
if (pause) {
|
||||
pAnimTask->Pause();
|
||||
return;
|
||||
}
|
||||
pAnimTask->SetDelay(50, true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002eb60
|
||||
void PortWindow::WindowToggleForeground(void)
|
||||
{
|
||||
if (!TPlatform::GetInstance()->IsForeground()) {
|
||||
TWindow* pTopModal = TPlatform::GetInstance()->GetWindowManager()->GetTopModalWindow();
|
||||
InternalPausePortAnimations(true);
|
||||
if (pTopModal == this) {
|
||||
TWindowManager::GetInstance()->DoLuaString(this, "if not gUIPaused then DoModal('ui/ui_pause.lua') end");
|
||||
}
|
||||
}
|
||||
else if (!explicitPause) {
|
||||
InternalPausePortAnimations(false);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002ec10
|
||||
void PortWindow::ToggleForeground(void)
|
||||
{
|
||||
if (pInstance != NULL) {
|
||||
pInstance->WindowToggleForeground();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002ec2a
|
||||
void PortWindow::PausePortAnimations(bool pause)
|
||||
{
|
||||
explicitPause = pause;
|
||||
InternalPausePortAnimations(pause);
|
||||
}
|
||||
|
||||
// game @0x0002ec46
|
||||
void PortWindow::ChangeMusic(void)
|
||||
{
|
||||
uint32_t delay;
|
||||
|
||||
if (!music) {
|
||||
music = true;
|
||||
BSGSoundEvent(str::getFormatted("port_music%lu", (unsigned long)RandRange(1, 3)));
|
||||
delay = RandRange(40000, 60000);
|
||||
}
|
||||
else {
|
||||
music = false;
|
||||
BSGSoundEvent("Stop_Music");
|
||||
delay = RandRange(10000, 15000);
|
||||
}
|
||||
musicTime = delay + pAnimTask->GetTime();
|
||||
}
|
||||
|
||||
// game @0x0002ed4e
|
||||
void PortWindow::Draw(void)
|
||||
{
|
||||
TBegin2d begin2d;
|
||||
if (pPortRoot) {
|
||||
pPortRoot->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
}
|
||||
TWindow::Draw();
|
||||
begin2d.Done();
|
||||
}
|
||||
|
||||
// game @0x0002edf6
|
||||
void PortWindow::CancelBuildingHighlight(void)
|
||||
{
|
||||
targetBuilding->pRollover->SetVisible(false);
|
||||
if (targetBuilding->pLabel != NULL) {
|
||||
BSGHideWindow(targetBuilding->pLabel);
|
||||
}
|
||||
rolloverTime = 0;
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x0002ee48
|
||||
void PortWindow::TintBackground(TColor const& tint)
|
||||
{
|
||||
pPortRoot->GetDrawSpec().mTint = tint;
|
||||
for (list<TSpriteRef>::iterator it = masks.begin(); it != masks.end(); ++it) {
|
||||
(*it)->GetDrawSpec().mTint = tint;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002ee9a
|
||||
bool PortWindow::DoAnimation(void)
|
||||
{
|
||||
uint32_t now = pAnimTask->GetTime();
|
||||
|
||||
if (lastTime <= startTime + 2000U) {
|
||||
uint32_t elapsed = now - startTime;
|
||||
float level = 1.0f;
|
||||
if (elapsed < 2000) {
|
||||
level = (float)(((double)elapsed * 0.75) / 2000.0 + 0.25);
|
||||
}
|
||||
TColor tint(level, level, level, 1.0f);
|
||||
TintBackground(tint);
|
||||
if (1000 < elapsed) {
|
||||
float alpha = (float)(((double)elapsed / 2000.0 - 0.5) * -2.0 + 1.0);
|
||||
float labelAlpha = 0.0f;
|
||||
if (0.0f <= alpha) {
|
||||
labelAlpha = alpha;
|
||||
}
|
||||
for (list<BuildingInfo>::iterator it = buildings.begin(); it != buildings.end(); ++it) {
|
||||
if (it != targetBuilding && it->pLabel != NULL) {
|
||||
SetWindowAlpha(it->pLabel, labelAlpha);
|
||||
BSGShowWindow(it->pLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lastTime = now;
|
||||
if (targetBuilding != buildings.end()) {
|
||||
rolloverTime = (rolloverTime + 50U) % 3000;
|
||||
float phase = (float)rolloverTime / 1500.0f;
|
||||
if (1.0f < phase) {
|
||||
phase = 2.0f - phase;
|
||||
}
|
||||
float scale = 1.0f + phase * targetBuilding->rolloverScale;
|
||||
float alpha = 0.8f;
|
||||
if (0.4 < (double)phase) {
|
||||
alpha = (float)((double)phase * -0.5 + 1.0);
|
||||
}
|
||||
TVec3 at(targetBuilding->pRollover->GetDrawSpec().mMatrix[2]);
|
||||
TVec2 at2(at);
|
||||
TDrawSpec spec(at2, alpha, scale, 0);
|
||||
targetBuilding->pRollover->GetDrawSpec() = spec;
|
||||
}
|
||||
for (list<TPathSpriteRef>::iterator it = sprites.begin(); it != sprites.end(); ++it) {
|
||||
(*it)->Update(50);
|
||||
}
|
||||
if (musicTime <= now) {
|
||||
ChangeMusic();
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0002f47e
|
||||
void PortWindow::Init(TWindowStyle& style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
str background = style.GetString("background", "");
|
||||
pPortRoot = TSprite::Create(0, TTexture::Get(background, 0));
|
||||
pPortRoot->GetDrawSpec().mCenter = TVec2(0, 0);
|
||||
pPortRoot->GetDrawSpec().mFlags |= TDrawSpec::kUseCenter;
|
||||
FindParentModal()->SetDefaultFocus(this);
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "PausePortAnimations", this, PortWindow::PausePortAnimations);
|
||||
}
|
||||
|
||||
// game @0x0002f6e2
|
||||
list<PortWindow::BuildingInfo>::iterator PortWindow::FindBuilding(TPoint const& point)
|
||||
{
|
||||
TPoint at(point);
|
||||
TDrawSpec spec(TVec2(), 1.0f, 1.0f, 0);
|
||||
list<BuildingInfo>::iterator best = buildings.end();
|
||||
|
||||
for (list<BuildingInfo>::iterator it = buildings.begin(); it != buildings.end(); ++it) {
|
||||
if (it->pSprite->HitTest(at, spec, 0, 0)) {
|
||||
if (best != buildings.end()) {
|
||||
TSpriteRef second(it->pSprite);
|
||||
TSpriteRef first(best->pSprite);
|
||||
if (!(first < second)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
best = it;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// game @0x0002f846
|
||||
bool PortWindow::OnMouseMove(TPoint const& point)
|
||||
{
|
||||
TDrawSpec spec(TVec2(), 1.0f, 1.0f, 0);
|
||||
list<BuildingInfo>::iterator found = FindBuilding(point);
|
||||
if (targetBuilding != found) {
|
||||
if (targetBuilding != buildings.end()) {
|
||||
CancelBuildingHighlight();
|
||||
}
|
||||
targetBuilding = found;
|
||||
if (found != buildings.end()) {
|
||||
found->pRollover->SetVisible(true);
|
||||
if (targetBuilding->pLabel != NULL) {
|
||||
BSGShowWindow(targetBuilding->pLabel);
|
||||
SetWindowAlpha(targetBuilding->pLabel, 1.0f);
|
||||
}
|
||||
rolloverTime = 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0002f906
|
||||
bool PortWindow::OnMouseUp(TPoint const& point)
|
||||
{
|
||||
if (mouseDown != buildings.end()) {
|
||||
list<BuildingInfo>::iterator found = FindBuilding(point);
|
||||
if (mouseDown == found) {
|
||||
if (targetBuilding != buildings.end()) {
|
||||
CancelBuildingHighlight();
|
||||
}
|
||||
str click = str("gCurrentBuilding=nil;") + found->name + str(":OnClick()");
|
||||
TWindowManager::GetInstance()->GetScript()->DoLuaString(click, -1, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00032510
|
||||
bool PortWindow::OnMouseDown(TPoint const& point)
|
||||
{
|
||||
TCurveEditor* pEditor = GetChildWindowCast<TCurveEditor>(this, "curve_editor", -1);
|
||||
if (pEditor == NULL || (pEditor->GetFlags() & TWindow::kEnabled) == 0) {
|
||||
mouseDown = FindBuilding(point);
|
||||
return buildings.end() != mouseDown;
|
||||
}
|
||||
if (!pEditor->OnMouseDown(point)) {
|
||||
for (list<TPathSpriteRef>::iterator it = sprites.begin(); it != sprites.end(); ++it) {
|
||||
TDrawSpec spec(TVec2(), 1.0f, 1.0f, 0);
|
||||
if ((*it)->HitTest(point, spec, -1, -1)) {
|
||||
pEditor->SetCurve((*it)->GetCurve());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00032348
|
||||
void PortWindow::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
TLuaTable* pPort = style.GetTable("port");
|
||||
CollectBuildingData(pPort);
|
||||
CollectSpriteData(pPort);
|
||||
delete pPort;
|
||||
pAnimTask = new PortAnimTask(this);
|
||||
TPlatform::GetInstance()->AdoptTask(pAnimTask);
|
||||
pAnimTask->SetDelay(50, true, true, true);
|
||||
TintBackground(TColor(0.25f, 0.25f, 0.25f, 1.0f));
|
||||
startTime = pAnimTask->GetTime();
|
||||
lastTime = startTime;
|
||||
uint32_t now = pAnimTask->GetTime();
|
||||
uint32_t delay = ClampToUInt32(style.GetNumber("musicDelay", 25000.0));
|
||||
musicTime = now + delay;
|
||||
}
|
||||
|
||||
// game @0x00031936
|
||||
void PortWindow::CollectBuildingData(TLuaTable* pPort)
|
||||
{
|
||||
str prefix = str("ports/") + pPort->GetString("name", "");
|
||||
prefix = prefix + str("/");
|
||||
TLuaTable* pBuildings = pPort->GetTable("buildings");
|
||||
if (pBuildings != NULL) {
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaTable* pBuilding = static_cast<TLuaTable*>(pBuildings->GetNext(&key));
|
||||
float gridX = 50.0f;
|
||||
float gridY = 100.0f;
|
||||
while (pBuilding != NULL) {
|
||||
str buildingName = pBuilding->GetString("name", "");
|
||||
float x = (float)pBuilding->GetNumber("x", 0);
|
||||
float y = (float)pBuilding->GetNumber("y", 0);
|
||||
int32_t layer = (int32_t)pBuilding->GetNumber("layer", 0);
|
||||
TTextureRef texture = TTexture::Get(prefix + buildingName, 0);
|
||||
if (!texture) {
|
||||
texture = TTexture::Get("ports/temp_building", 0);
|
||||
if (500.0f < gridX + 100.0f) {
|
||||
x = gridX;
|
||||
y = gridY;
|
||||
gridY = gridY + 20.0f + 100.0f;
|
||||
gridX = 50.0f;
|
||||
}
|
||||
else {
|
||||
x = gridX;
|
||||
y = gridY;
|
||||
gridX = gridX + 100.0f;
|
||||
gridY = gridY + 20.0f;
|
||||
}
|
||||
}
|
||||
TSpriteRef pSprite = TSprite::Create(layer, texture);
|
||||
pSprite->GetDrawSpec().mMatrix[2] = TVec3(x, y, 0);
|
||||
pPortRoot->AddChild(pSprite);
|
||||
TSpriteRef pRollover = TSprite::Create(-1, texture);
|
||||
pSprite->AddChild(pRollover);
|
||||
pRollover->SetVisible(false);
|
||||
float height = (float)texture->GetHeight();
|
||||
float width = (float)texture->GetWidth();
|
||||
float widthScale = (width + 50.0f) / width;
|
||||
float heightScale = (50.0f + height) / height;
|
||||
if (1.2f <= widthScale) {
|
||||
widthScale = 1.2f;
|
||||
}
|
||||
if (widthScale <= heightScale) {
|
||||
heightScale = widthScale;
|
||||
}
|
||||
BuildingInfo info;
|
||||
info.name = buildingName;
|
||||
info.pSprite = pSprite;
|
||||
info.pRollover = pRollover;
|
||||
info.pLabel = GetChildWindow(buildingName, -1);
|
||||
info.rolloverScale = heightScale - 1.0f;
|
||||
buildings.push_back(info);
|
||||
if (info.pLabel != NULL) {
|
||||
float defaultY = y + (float)((double)texture->GetHeight() * 0.25);
|
||||
double defaultX = (double)(x - (float)((double)info.pLabel->GetWindowWidth() * 0.5));
|
||||
float labelX = (float)pBuilding->GetNumber("labelx", defaultX);
|
||||
double labelYValue = pBuilding->GetNumber("labely", (double)defaultY);
|
||||
float placeX = 0.0f;
|
||||
if (0.0f <= labelX) {
|
||||
placeX = labelX;
|
||||
}
|
||||
if ((float)(uint32_t)GetWindowWidth() < placeX + (float)(uint32_t)info.pLabel->GetWindowWidth()) {
|
||||
placeX = (float)(uint32_t)(GetWindowWidth() - info.pLabel->GetWindowWidth());
|
||||
}
|
||||
info.pLabel->SetWindowPos((int)placeX, (int)labelYValue);
|
||||
}
|
||||
delete pBuilding;
|
||||
pBuilding = static_cast<TLuaTable*>(pBuildings->GetNext(&key));
|
||||
}
|
||||
delete pBuildings;
|
||||
}
|
||||
targetBuilding = buildings.end();
|
||||
mouseDown = buildings.end();
|
||||
}
|
||||
|
||||
// game @0x0002fa68
|
||||
void PortWindow::CollectSpriteData(TLuaTable* pPort)
|
||||
{
|
||||
float yFar = (float)pPort->GetNumber("yFar", 0);
|
||||
float yNear = (float)pPort->GetNumber("yNear", 800);
|
||||
float scaleFar = (float)pPort->GetNumber("scaleFar", 1);
|
||||
float scaleNear = (float)pPort->GetNumber("scaleNear", 1);
|
||||
TLuaTable* pSprites = pPort->GetTable("sprites");
|
||||
if (pSprites == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
TLuaObjectWrapper* key = NULL;
|
||||
TLuaTable* pEntry;
|
||||
while ((pEntry = static_cast<TLuaTable*>(pSprites->GetNext(&key))) != NULL) {
|
||||
double frequency = pEntry->GetNumber("frequency", 100);
|
||||
uint32_t roll = RandRange(0, 99);
|
||||
if (roll < ClampToUInt32(frequency)) {
|
||||
str image;
|
||||
str mask;
|
||||
TLuaTable* pImages = pEntry->GetTable("images");
|
||||
if (pImages != NULL) {
|
||||
uint32_t count = pImages->GetSize();
|
||||
if (count != 0) {
|
||||
uint32_t pick = RandRange(1, count);
|
||||
image = pImages->GetString((double)pick, "");
|
||||
TLuaTable* pMasks = pEntry->GetTable("masks");
|
||||
if (pMasks != NULL) {
|
||||
if (pick <= pMasks->GetSize()) {
|
||||
mask = pMasks->GetString((double)pick, "");
|
||||
}
|
||||
delete pMasks;
|
||||
}
|
||||
}
|
||||
delete pImages;
|
||||
}
|
||||
if (image.length() == 0) {
|
||||
image = pEntry->GetString("image", "");
|
||||
mask = pEntry->GetString("mask", "");
|
||||
}
|
||||
int32_t layer = (int32_t)ClampToUInt32(pEntry->GetNumber("layer", 0));
|
||||
TLuaTable* pBehind = pEntry->GetTable("behind");
|
||||
if (pBehind != NULL) {
|
||||
uint32_t behindLayer = ClampToUInt32(pBehind->GetNumber("layer", 0));
|
||||
layer = (int32_t)(behindLayer - 1 + (uint32_t)(behindLayer == 0));
|
||||
delete pBehind;
|
||||
}
|
||||
|
||||
TSpriteRef pSprite;
|
||||
TSpriteRef pMaskSprite;
|
||||
TCurveRef pCurve;
|
||||
TLuaTable* pPath = pEntry->GetTable("path");
|
||||
if (pPath == NULL) {
|
||||
TSpriteRef pStatic;
|
||||
if (image.find(".xml", 0, 0) == (size_t)-1) {
|
||||
pStatic = TSprite::Create(layer, TTexture::Get(image, 0));
|
||||
}
|
||||
else {
|
||||
TAnimatedSpriteRef pAnimated = TAnimatedSprite::Create(layer);
|
||||
TAnimatedTextureRef pAnimTexture = TAnimatedTexture::Get(image, "", "");
|
||||
pAnimated->SetTexture(TTextureRef(pAnimTexture));
|
||||
if (pAnimTexture) {
|
||||
if (1 < pAnimTexture->GetNumFrames()) {
|
||||
pAnimated->Play("DoAnim");
|
||||
}
|
||||
}
|
||||
pStatic = pAnimated;
|
||||
}
|
||||
if (pStatic) {
|
||||
float staticScale = (float)pEntry->GetNumber("scale", 1);
|
||||
pStatic->GetDrawSpec().mMatrix.Scale(staticScale, staticScale);
|
||||
float x = (float)pEntry->GetNumber("x", 0);
|
||||
pStatic->GetDrawSpec().mMatrix[2] = TVec3(x, (float)pEntry->GetNumber("y", 0), 1);
|
||||
pPortRoot->AddChild(pStatic);
|
||||
masks.push_back(pStatic);
|
||||
pSprite = pStatic;
|
||||
}
|
||||
if (mask.length() != 0) {
|
||||
pMaskSprite = TSprite::Create(0, TTexture::Get(mask, 0));
|
||||
}
|
||||
}
|
||||
else {
|
||||
pCurve = TCurve::Create(*pPath);
|
||||
delete pPath;
|
||||
float time = (float)pEntry->GetNumber("time", 0);
|
||||
str motion = pEntry->GetString("motion", "loop");
|
||||
TPathSpriteRef pPathSprite = TPathSprite::Create(layer);
|
||||
TAnimatedTextureRef pAnimTexture = TAnimatedTexture::Get(image, "", "");
|
||||
if (!pAnimTexture) {
|
||||
TTextureRef texture = TTexture::Get(image, 0);
|
||||
if (texture) {
|
||||
pPathSprite->SetTexture(texture);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pPathSprite->SetTexture(TTextureRef(pAnimTexture));
|
||||
}
|
||||
if (mask.length() != 0) {
|
||||
TAnimatedSpriteRef pAnimatedMask = TAnimatedSprite::Create(0);
|
||||
pAnimTexture = TAnimatedTexture::Get(image, image, mask);
|
||||
if (!pAnimTexture) {
|
||||
TTextureRef maskTexture = TTexture::Get(mask, 0);
|
||||
if (maskTexture) {
|
||||
pAnimatedMask->SetTexture(maskTexture);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pAnimatedMask->SetTexture(TTextureRef(pAnimTexture));
|
||||
}
|
||||
pPathSprite->SetMask(pAnimatedMask);
|
||||
pMaskSprite = pAnimatedMask;
|
||||
}
|
||||
TPathSprite::PathMode mode;
|
||||
if (motion == str("oneway")) {
|
||||
mode = TPathSprite::ONEWAY;
|
||||
}
|
||||
else if (motion == str("bounce")) {
|
||||
mode = TPathSprite::BOUNCE;
|
||||
}
|
||||
else {
|
||||
mode = TPathSprite::LOOP;
|
||||
}
|
||||
pPathSprite->SetCurve(pCurve, time, mode);
|
||||
float pathYFar = (float)pEntry->GetNumber("yFar", (double)yFar);
|
||||
float pathYNear = (float)pEntry->GetNumber("yNear", (double)yNear);
|
||||
float pathScaleFar = (float)pEntry->GetNumber("scaleFar", (double)scaleFar);
|
||||
double pathScaleNear = pEntry->GetNumber("scaleNear", (double)scaleNear);
|
||||
if (pathYFar != pathYNear) {
|
||||
pPathSprite->SetScaling(pathYFar, pathYNear, pathScaleFar, (float)pathScaleNear);
|
||||
}
|
||||
float pathScale = (float)pEntry->GetNumber("scale", -1);
|
||||
if (0.0f < pathScale) {
|
||||
pPathSprite->SetScaling(pathYFar, pathYNear, pathScale, pathScale);
|
||||
}
|
||||
float speedFar = (float)pEntry->GetNumber("speedFar", 1);
|
||||
double speedNear = pEntry->GetNumber("speedNear", 1);
|
||||
if (pathYFar != pathYNear) {
|
||||
pPathSprite->SetSpeed(speedFar, (float)speedNear);
|
||||
}
|
||||
pPortRoot->AddChild(pPathSprite);
|
||||
sprites.push_back(pPathSprite);
|
||||
pSprite = pPathSprite;
|
||||
if (pEntry->GetBoolean("random", true) && 1.0f < time) {
|
||||
uint32_t steps = ClampToUInt32(time / 50.0f);
|
||||
uint32_t count = 0;
|
||||
if (steps != 0) {
|
||||
count = RandRange(0, steps);
|
||||
}
|
||||
for (uint32_t i = 0; count != i; i++) {
|
||||
pPathSprite->Update(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float htile = (float)pEntry->GetNumber("htile", 0);
|
||||
if (htile != 0.0f && pSprite) {
|
||||
TSpriteRef pTile = TSprite::Create(0, pSprite->GetTexture());
|
||||
pTile->GetDrawSpec().mMatrix[2][0] = -htile;
|
||||
pSprite->AddChild(pTile);
|
||||
pTile = TSprite::Create(0, pSprite->GetTexture());
|
||||
pTile->GetDrawSpec().mMatrix[2][0] = htile * -2.0f;
|
||||
pSprite->AddChild(pTile);
|
||||
pTile = TSprite::Create(0, pSprite->GetTexture());
|
||||
pTile->GetDrawSpec().mMatrix[2][0] = htile;
|
||||
pSprite->AddChild(pTile);
|
||||
pTile = TSprite::Create(0, pSprite->GetTexture());
|
||||
pTile->GetDrawSpec().mMatrix[2][0] = htile + htile;
|
||||
pSprite->AddChild(pTile);
|
||||
}
|
||||
if (pMaskSprite && pSprite) {
|
||||
pSprite->AddChild(pMaskSprite);
|
||||
TColor tint(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
TLuaTable* pTints = pEntry->GetTable("tints");
|
||||
if (pTints == NULL) {
|
||||
tint = pEntry->GetColor("tint", tint);
|
||||
}
|
||||
else {
|
||||
uint32_t tintCount = pTints->GetSize();
|
||||
if (tintCount != 0) {
|
||||
uint32_t pick = RandRange(1, tintCount);
|
||||
tint = pTints->GetColor((double)pick, tint);
|
||||
}
|
||||
delete pTints;
|
||||
}
|
||||
pMaskSprite->GetDrawSpec().mTint = tint;
|
||||
}
|
||||
}
|
||||
delete pEntry;
|
||||
}
|
||||
delete pSprites;
|
||||
}
|
||||
58
port/game/RecipeCreator.cpp
Normal file
58
port/game/RecipeCreator.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Port of the game's RecipeCreator.cpp (Chocolatier 3, Big Splash Games): RecipeCreator, a TWindow subclass whose
|
||||
// overrides only forward to TWindow (OnMouseMove / OnMouseDown return false).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// RecipeCreator.h (port/game/RecipeCreator.h, unchanged).
|
||||
//
|
||||
// Compiler-generated in the game:
|
||||
// - PFTYPEDEF_DC IsKindOf: game @0x00172a60 (compares the id against &RecipeCreatorDynamicCreate, else calls
|
||||
// TWindow::IsKindOf).
|
||||
// - ~RecipeCreator: D2 shares the body of D1 (game @0x00032726); D0 (game @0x0003273c) also deletes the object.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "RecipeCreator.h"
|
||||
|
||||
// game @0x000326ea (RecipeCreatorDynamicCreate: new RecipeCreator)
|
||||
// game @0x000326b8 (ClassId: returns &RecipeCreatorDynamicCreate)
|
||||
// game @0x000326c2 (GetTypeName, "RecipeCreator")
|
||||
PFTYPEIMPL_DC(RecipeCreator);
|
||||
|
||||
// game @0x000326cc
|
||||
RecipeCreator::RecipeCreator(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x00032726 (D1), game @0x0003273c (D0)
|
||||
RecipeCreator::~RecipeCreator(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x00032762
|
||||
void RecipeCreator::Init(TWindowStyle &style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
}
|
||||
|
||||
// game @0x0003276c
|
||||
void RecipeCreator::PostChildrenInit(TWindowStyle &style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
}
|
||||
|
||||
// game @0x00032776
|
||||
bool RecipeCreator::OnMouseMove(TPoint const& point)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0003277e
|
||||
bool RecipeCreator::OnMouseDown(TPoint const& point)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00032786
|
||||
void RecipeCreator::Draw(void)
|
||||
{
|
||||
TWindow::Draw();
|
||||
}
|
||||
212
port/game/RecipeDesigner.cpp
Normal file
212
port/game/RecipeDesigner.cpp
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
// Port of the game's RecipeDesigner.cpp (Chocolatier 3, Big Splash Games): RecipeDesigner, the window of the recipe
|
||||
// designer screen. It lists the "custom/<type>" layer images, lets Lua pick one image per layer (SetLayer), and runs
|
||||
// a short randomize animation (RandomDesign / OnTaskAnimate) that picks random images and tints.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// RecipeDesigner.h (port/game/RecipeDesigner.h, unchanged). String literals of the format calls come from the
|
||||
// shipped function map (choc3/cpp_src/RecipeDesigner.cpp).
|
||||
//
|
||||
// Layout (game, i386): TWindow ..., layerAssets (TAssetMap) 0x30, RandomizeTimer 0x50, layer[4] (vector<str>) 0x54,
|
||||
// layerIndex[4] 0x84; the header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The constructor registers four Lua globals (RandomDesign, SetRecipeType, SetLayer, GetLayerImage) with
|
||||
// ScriptRegisterMemberDirect on the window manager's script; the destructor sets them to nil again.
|
||||
// - SetRecipeType: clears the four layer lists, then walks every file of folder "custom/" + type (TFile::GetNextFile),
|
||||
// skipping names that contain "_highlight" or that lack ".png"; the texture of the name without its last four
|
||||
// characters is loaded, added to layerAssets under the full file name, and the name (without ".png") is appended
|
||||
// to the list of the first of "layer1".."layer4" it contains. Afterwards empty names are appended to layers 2..4
|
||||
// (layers 2 and 4 only when the type is "beverage").
|
||||
// - SetLayer: the index wraps with (nImage + size) % size (signed); "option_layer%lu" / "display_layer%lu" are
|
||||
// TBitmapTint children, "option_highlight%lu" / "display_highlight%lu" TImage children; all four are hidden for an
|
||||
// empty name, the layer pair is hidden when the texture is missing, the highlight pair (texture of
|
||||
// name + "_highlight") when that one is missing. The option windows draw at scale 0.5, the display ones at 1.0.
|
||||
// - OnTaskAnimate: timer += 100; while below 2000 it picks random images for the layers whose phase limit
|
||||
// (timer below 1001, 1501, 1801; layer 4 always) holds and runs "SetRecipeTint(n,%lu);" strings as Lua.
|
||||
//
|
||||
// Compiler-generated in the game:
|
||||
// - PFTYPEDEF_DC IsKindOf: game @0x00172e4c (compares the id against &RecipeDesignerDynamicCreate, else calls
|
||||
// TWindow::IsKindOf).
|
||||
// - Header-inline code emitted out of line (pf/luapluscd.h templates, class registration code):
|
||||
// lua_pushdirectclosure<RecipeDesigner, F> for F = void () game @0x00172a8c, void (str) game @0x00172ad8,
|
||||
// int (int, int) game @0x00172b24, str (int) game @0x00172b70;
|
||||
// LPCD::DirectCallMemberDispatcherHelper<RecipeDesigner, F>::DirectCallMemberDispatcher for F =
|
||||
// void () game @0x00172c54, str (int) game @0x00172e78 (Call game @0x00172d14), int (int, int) game @0x00172ebc
|
||||
// (Call game @0x00172dc4), void (str) game @0x00172f00 (Call game @0x00172c9c).
|
||||
// - ~RecipeDesigner: D1 game @0x00032a2a, D0 game @0x000328b6 (also deletes the object).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "RecipeDesigner.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGSound.h"
|
||||
#include "BitmapTint.h"
|
||||
|
||||
#include "pf/file.h"
|
||||
#include "pf/image.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
// game @0x00032df4 (RecipeDesignerDynamicCreate: new RecipeDesigner)
|
||||
// game @0x00032790 (ClassId: returns &RecipeDesignerDynamicCreate)
|
||||
// game @0x0003279a (GetTypeName, "RecipeDesigner")
|
||||
PFTYPEIMPL_DC(RecipeDesigner);
|
||||
|
||||
// game @0x00032b96 (D1/C1)
|
||||
RecipeDesigner::RecipeDesigner(void)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "RandomDesign", this, RecipeDesigner::RandomDesign);
|
||||
ScriptRegisterMemberDirect(script, "SetRecipeType", this, RecipeDesigner::SetRecipeType);
|
||||
ScriptRegisterMemberDirect(script, "SetLayer", this, RecipeDesigner::SetLayer);
|
||||
ScriptRegisterMemberDirect(script, "GetLayerImage", this, RecipeDesigner::GetLayerImage);
|
||||
}
|
||||
|
||||
// game @0x00032a2a (D1), game @0x000328b6 (D0)
|
||||
RecipeDesigner::~RecipeDesigner(void)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptUnregisterFunction(script, "RandomDesign");
|
||||
ScriptUnregisterFunction(script, "SetRecipeType");
|
||||
ScriptUnregisterFunction(script, "SetLayer");
|
||||
ScriptUnregisterFunction(script, "GetLayerImage");
|
||||
}
|
||||
|
||||
// game @0x000327a4
|
||||
void RecipeDesigner::RandomDesign(void)
|
||||
{
|
||||
RandomizeTimer = 0;
|
||||
BSGSoundEvent("randomize");
|
||||
StartWindowAnimation(100, true, true, false);
|
||||
}
|
||||
|
||||
// game @0x0003281c
|
||||
str RecipeDesigner::GetLayerImage(int32_t nLayer)
|
||||
{
|
||||
str image = layer[nLayer][layerIndex[nLayer]];
|
||||
image = image.substr(7, 0xffffffff);
|
||||
return image;
|
||||
}
|
||||
|
||||
// game @0x00032e32
|
||||
void RecipeDesigner::SetRecipeType(str type)
|
||||
{
|
||||
layer[0].clear();
|
||||
layer[1].clear();
|
||||
layer[2].clear();
|
||||
layer[3].clear();
|
||||
|
||||
str folder = str("custom/") + type;
|
||||
str file;
|
||||
while (TFile::GetNextFile(folder, &file, false)) {
|
||||
if (file.find(str("_highlight"), 0, 0) != (uint32_t)-1)
|
||||
continue;
|
||||
if (file.find(str(".png"), 0, 0) == (uint32_t)-1)
|
||||
continue;
|
||||
|
||||
str name = file.substr(0, file.length() - 4);
|
||||
TTextureRef texture = TTexture::Get(name, 0);
|
||||
if (texture) {
|
||||
TAssetRef asset = texture;
|
||||
layerAssets.AddAsset(file, asset, false);
|
||||
|
||||
if (file.find(str("layer1"), 0, 0) != (uint32_t)-1)
|
||||
layer[0].push_back(name);
|
||||
else if (file.find(str("layer2"), 0, 0) != (uint32_t)-1)
|
||||
layer[1].push_back(name);
|
||||
else if (file.find(str("layer3"), 0, 0) != (uint32_t)-1)
|
||||
layer[2].push_back(name);
|
||||
else if (file.find(str("layer4"), 0, 0) != (uint32_t)-1)
|
||||
layer[3].push_back(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == str("beverage")) {
|
||||
layer[1].push_back(str(""));
|
||||
layer[3].push_back(str(""));
|
||||
} else {
|
||||
layer[1].push_back(str(""));
|
||||
layer[2].push_back(str(""));
|
||||
layer[3].push_back(str(""));
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00033418
|
||||
int32_t RecipeDesigner::SetLayer(int32_t nLayer, int32_t nImage)
|
||||
{
|
||||
int32_t size = (int32_t)layer[nLayer].size();
|
||||
int32_t index = (nImage + size) % size;
|
||||
str name = layer[nLayer][index];
|
||||
layerIndex[nLayer] = index;
|
||||
|
||||
TBitmapTint* pOptionLayer = GetChildWindowCast<TBitmapTint>(this, str::getFormatted("option_layer%lu", nLayer), -1);
|
||||
TImage* pOptionHighlight = GetChildWindowCast<TImage>(this, str::getFormatted("option_highlight%lu", nLayer), -1);
|
||||
TBitmapTint* pDisplayLayer = GetChildWindowCast<TBitmapTint>(this, str::getFormatted("display_layer%lu", nLayer), -1);
|
||||
TImage* pDisplayHighlight = GetChildWindowCast<TImage>(this, str::getFormatted("display_highlight%lu", nLayer), -1);
|
||||
|
||||
if (name.length() == 0) {
|
||||
BSGHideWindow(pOptionLayer);
|
||||
BSGHideWindow(pOptionHighlight);
|
||||
BSGHideWindow(pDisplayLayer);
|
||||
BSGHideWindow(pDisplayHighlight);
|
||||
} else {
|
||||
TTextureRef texture = TTexture::Get(name, 0);
|
||||
if (!texture) {
|
||||
BSGHideWindow(pOptionLayer);
|
||||
BSGHideWindow(pDisplayLayer);
|
||||
} else {
|
||||
BSGShowWindow(pOptionLayer);
|
||||
BSGShowWindow(pDisplayLayer);
|
||||
pOptionLayer->SetTexture(texture, 0.5f);
|
||||
pDisplayLayer->SetTexture(texture, 1.0f);
|
||||
|
||||
texture = TTexture::Get(name + str("_highlight"), 0);
|
||||
if (!texture) {
|
||||
BSGHideWindow(pOptionHighlight);
|
||||
BSGHideWindow(pDisplayHighlight);
|
||||
} else {
|
||||
BSGShowWindow(pOptionHighlight);
|
||||
BSGShowWindow(pDisplayHighlight);
|
||||
pOptionHighlight->SetTexture(texture, 0.5f);
|
||||
pDisplayHighlight->SetTexture(texture, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
// game @0x00033872
|
||||
bool RecipeDesigner::OnTaskAnimate(void)
|
||||
{
|
||||
bool result;
|
||||
|
||||
RandomizeTimer += 100;
|
||||
if (RandomizeTimer < 2000) {
|
||||
str luaCode;
|
||||
|
||||
if (RandomizeTimer < 1001) {
|
||||
SetLayer(0, RandRange(0, (uint32_t)layer[0].size() - 1));
|
||||
luaCode = luaCode + str::getFormatted("SetRecipeTint(1,%lu);", RandRange(1, 100));
|
||||
}
|
||||
if (RandomizeTimer < 1501) {
|
||||
SetLayer(1, RandRange(1, (uint32_t)layer[1].size() - 1));
|
||||
luaCode = luaCode + str::getFormatted("SetRecipeTint(2,%lu);", RandRange(1, 100));
|
||||
}
|
||||
if (RandomizeTimer < 1801) {
|
||||
SetLayer(2, RandRange(2, (uint32_t)layer[2].size() - 1));
|
||||
luaCode = luaCode + str::getFormatted("SetRecipeTint(3,%lu);", RandRange(1, 100));
|
||||
}
|
||||
SetLayer(3, RandRange(0, (uint32_t)layer[3].size() - 1));
|
||||
luaCode = luaCode + str::getFormatted("SetRecipeTint(4,%lu);", RandRange(1, 100));
|
||||
|
||||
TWindowManager::GetInstance()->GetScript()->DoLuaString(luaCode, -1, 0);
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return result;
|
||||
}
|
||||
126
port/game/Rectangle.cpp
Normal file
126
port/game/Rectangle.cpp
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
// Port of the game's Rectangle.cpp (Chocolatier 3, Big Splash Games): TRectangle, an opaque or translucent
|
||||
// colored rectangular window, plus the Lua function SetRectangleColor.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// Rectangle.h (port/game/Rectangle.h, unchanged). Game-only class: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): TRectangle : TWindow (0x30) color 0x30 (r g b a), vertices[4] 0x40..0xc0 (TVert, 0x20 each:
|
||||
// pos at +0, normal at +0xc), alpha 0xc0. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The constructor sets color to (1, 1, 1, 1), default-constructs the four vertices (alpha is left unset) and
|
||||
// registers the Lua function SetRectangleColor once (functionsRegistered, __data game @0x001d8220, initially false).
|
||||
// - PostChildrenInit reads "color" (default: the current color) and "alpha" (default: color.a), then builds the
|
||||
// four vertices at (0, 0), (w, 0), (0, h), (w, h) with z = 0 and the normal (0, 0, 1), w / h being the
|
||||
// window's width / height (converted through unsigned).
|
||||
// - Draw sets color.a = alpha. With alpha == 1 it fills the client rect with the color and draws the children
|
||||
// (TWindow::Draw); with 0 < alpha < 1 it draws the vertices as a triangle strip with a material whose diffuse,
|
||||
// ambient, specular and emit colors are all the window color (power 0) and does not draw the children; with
|
||||
// alpha <= 0 it draws nothing.
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFTYPEDEF_DC: TRectangleDynamicCreate game @0x0003c86c, ClassId game @0x0003c448, GetTypeName game @0x0003c452,
|
||||
// IsKindOf game @0x00175500. TRectangle::OnMouseMove (header inline, returns true) game @0x00175484.
|
||||
// ~TRectangle: D1 game @0x00175490, D0 game @0x001754a8 (also deletes). TWindow::GetCast<TRectangle> game
|
||||
// @0x001754d0. The Lua registration shares lua_pushdirectclosure<void (*)(str, TLuaTable*)> and its dispatchers
|
||||
// with BitmapTint.cpp (game @0x00175110, 0x001751d0, 0x00175244).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "Rectangle.h"
|
||||
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
PFTYPEIMPL_DC(TRectangle);
|
||||
|
||||
// game @0x001d8220 (__data, initial value false)
|
||||
bool TRectangle::functionsRegistered = false;
|
||||
|
||||
// game @0x0003c45c
|
||||
void TRectangle::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
color = style.GetColor("color", color);
|
||||
alpha = (float)style.GetNumber("alpha", (double)color.a);
|
||||
float w = (float)(uint32_t)(GetParentRelativeRect().x2 - GetParentRelativeRect().x1) + 0.0f;
|
||||
float h = (float)(uint32_t)(GetParentRelativeRect().y2 - GetParentRelativeRect().y1) + 0.0f;
|
||||
vertices[0].pos = TVec3(0, 0, 0);
|
||||
vertices[1].pos = TVec3(w, 0, 0);
|
||||
vertices[2].pos = TVec3(0, h, 0);
|
||||
vertices[3].pos = TVec3(w, h, 0);
|
||||
vertices[0].normal = TVec3(0, 0, 1.0f);
|
||||
vertices[1].normal = TVec3(0, 0, 1.0f);
|
||||
vertices[2].normal = TVec3(0, 0, 1.0f);
|
||||
vertices[3].normal = TVec3(0, 0, 1.0f);
|
||||
}
|
||||
|
||||
// game @0x0003c7a2
|
||||
TRectangle::TRectangle(void) :
|
||||
color(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
{
|
||||
if (!functionsRegistered) {
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterDirect(script, "SetRectangleColor", SetRectangleColor);
|
||||
functionsRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003c8aa
|
||||
TRectangle* TRectangle::ByName(str windowName)
|
||||
{
|
||||
TWindow* pTop = TWindowManager::GetInstance()->GetTopModalWindow();
|
||||
if (pTop != 0) {
|
||||
TWindow* pWindow = pTop->GetChildWindow(windowName, -1);
|
||||
if (pWindow != 0) {
|
||||
return pWindow->GetCast<TRectangle>();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// game @0x0003c926
|
||||
void TRectangle::SetRectangleColor(str windowName, TLuaTable* pColor)
|
||||
{
|
||||
TRectangle* pRectangle = ByName(windowName);
|
||||
if (pRectangle != 0) {
|
||||
lua_Number a = pColor->GetNumber(4.0, 0.0);
|
||||
lua_Number b = pColor->GetNumber(3.0, 0.0);
|
||||
lua_Number g = pColor->GetNumber(2.0, 0.0);
|
||||
lua_Number r = pColor->GetNumber(1.0, 0.0);
|
||||
pRectangle->color.a = (float)a;
|
||||
pRectangle->color.b = (float)b;
|
||||
pRectangle->color.g = (float)g;
|
||||
pRectangle->color.r = (float)r;
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003ca5a
|
||||
void TRectangle::Draw(void)
|
||||
{
|
||||
TBegin2d begin2d;
|
||||
color.a = alpha;
|
||||
if (alpha != 1.0f) {
|
||||
if (0.0f < alpha) {
|
||||
TMaterial material;
|
||||
material.mcDiff = color;
|
||||
material.mcAmb = color;
|
||||
material.mcSpec = color;
|
||||
material.mcEmit = color;
|
||||
material.mfPower = 0;
|
||||
TRenderer::GetInstance()->SetMaterial(&material);
|
||||
TVertexSet vertexSet(vertices, 4);
|
||||
TRenderer::GetInstance()->DrawVertices(TRenderer::kDrawTriStrip, vertexSet);
|
||||
}
|
||||
}
|
||||
else {
|
||||
TURect rect;
|
||||
GetClientRect(&rect);
|
||||
TRenderer::GetInstance()->FillRect(rect, color, TTextureRef());
|
||||
TWindow::Draw();
|
||||
}
|
||||
begin2d.Done();
|
||||
}
|
||||
116
port/game/Recycler.cpp
Normal file
116
port/game/Recycler.cpp
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
// Port of the game's Recycler.cpp (Chocolatier 3, Big Splash Games): Recycler (a recycling bin that rides the
|
||||
// recycler curve and swallows ingredients) and RecyclerTask (the task that moves all bins).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// Recycler.h (port/game/Recycler.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): Recycler: TAnimatedSprite 0x0..0x84, lastUpdate 0x84, offset 0x88, radius 0x8c, pCurve 0x90,
|
||||
// sizeof 0x98 (Create allocates 0x98 bytes). RecyclerTask: TScalingTask 0x0..0x1c, cycleTime 0x1c, bins
|
||||
// (std::set<RecyclerRef>) 0x20 (tree header 0x24, leftmost node 0x2c). The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Initial radius 0x42900000 = 72.0f (an immediate). Strings from the game's __cstring: "image/recycler.xml",
|
||||
// "DoAnim", "recycler", "++RecycleCount" and "" (@0x001581bc). Event kSoundEvent 0x3ea.
|
||||
// - RecyclerTask::Reset does not call TScalingTask::Reset: it sets scale = newScale and lastClock = taskClock.
|
||||
// - Recycler::Update: t = t + offset; position = t - floorf(t) on the curve; lastUpdate = that fraction.
|
||||
// - AddIngredient: starts the "DoAnim" animation unless one is playing, removes the ingredient from its parent
|
||||
// sprite (TSprite slot 0x14 is RemoveChild), posts the sound "recycler" and increments the game state
|
||||
// "RecycleCount" (SetState with "++" prefix and a 0 value).
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFSHAREDTYPEDEF / PFTYPEIMPL: ClassId game @0x00033c10, GetTypeName game @0x00033c1a ("Recycler"), IsKindOf
|
||||
// game @0x00173088 (the Recycler class id, else TAnimatedSprite::IsKindOf).
|
||||
// CanAccept (header-declared, no state use) game @0x00033c24: returns true.
|
||||
// ~Recycler (releases pCurve, then ~TAnimatedSprite): D1 game @0x00033d44, D0 game @0x00034000.
|
||||
// RecyclerTask constructor (header inline): TScalingTask(), cycleTime, empty set, game @0x001671ac.
|
||||
// The std::set<RecyclerRef> instantiations are not ported.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "Recycler.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "pf/animatedsprite.h"
|
||||
#include "pf/animatedtexture.h"
|
||||
#include "pf/gamestate.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
PFTYPEIMPL(Recycler);
|
||||
|
||||
// game @0x00033c24
|
||||
bool Recycler::CanAccept(IngredientRef pIngredient) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00033c2e
|
||||
void RecyclerTask::Reset(TReal newScale)
|
||||
{
|
||||
scale = newScale;
|
||||
lastClock = taskClock;
|
||||
}
|
||||
|
||||
// game @0x00033c42
|
||||
void Recycler::Update(TReal t)
|
||||
{
|
||||
TReal sum = t + offset;
|
||||
TReal frac = sum - floorf(sum);
|
||||
if (pCurve) {
|
||||
TVec2 point = pCurve->GetPoint(frac, 0);
|
||||
GetDrawSpec().mMatrix[2] = TVec3(point, 1.0f);
|
||||
}
|
||||
lastUpdate = frac;
|
||||
}
|
||||
|
||||
// game @0x00033ce6
|
||||
bool RecyclerTask::Animate(void)
|
||||
{
|
||||
TScalingTask::Animate();
|
||||
TReal t = GetT(cycleTime);
|
||||
for (set<RecyclerRef>::iterator it = bins.begin(); it != bins.end(); ++it) {
|
||||
(*it)->Update(t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00033d8c
|
||||
Recycler::Recycler(TCurveRef pCurve_, TReal offset_) :
|
||||
TAnimatedSprite(3),
|
||||
offset(offset_),
|
||||
radius(72.0f),
|
||||
pCurve(pCurve_)
|
||||
{
|
||||
TAnimatedSprite::SetTexture(TTextureRef(TAnimatedTexture::Get("image/recycler.xml", "", "")));
|
||||
lastUpdate = offset;
|
||||
TVec2 point = pCurve->GetPoint(offset, 0);
|
||||
GetDrawSpec().mMatrix[2] = TVec3(point, 1.0f);
|
||||
}
|
||||
|
||||
// game @0x00033f70
|
||||
RecyclerRef Recycler::Create(TCurveRef pCurve, TReal offset)
|
||||
{
|
||||
return RecyclerRef(new Recycler(pCurve, offset));
|
||||
}
|
||||
|
||||
// game @0x00033d44 (D1), game @0x00034000 (D0)
|
||||
Recycler::~Recycler(void)
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0003404e
|
||||
bool Recycler::AddIngredient(IngredientRef pIngredient)
|
||||
{
|
||||
if (!IsPlaying(-1)) {
|
||||
Play("DoAnim");
|
||||
}
|
||||
|
||||
TSprite* pParent = pIngredient->GetParent();
|
||||
if (pParent != NULL) {
|
||||
pParent->RemoveChild(pIngredient);
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->PostWindowMessage(new TMessage(kSoundEvent, "recycler", NULL));
|
||||
TGameState::GetInstance()->SetState("++RecycleCount", 0);
|
||||
return true;
|
||||
}
|
||||
116
port/game/Rollover.cpp
Normal file
116
port/game/Rollover.cpp
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
// Port of the game's Rollover.cpp (Chocolatier 3, Big Splash Games): Rollover, a transparent TWindow over a screen
|
||||
// area that pops up a PopupWindow (with Lua contents) when the mouse moves over it.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// Rollover.h (port/game/Rollover.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): Rollover : TWindow (0x30) xOffset 0x30, yOffset 0x34, xAbsolute 0x38, yAbsolute 0x3c,
|
||||
// contentString 0x40, clickString 0x44, pClickFunction 0x48/0x4c, mouseDown 0x50. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Rollover::rolloversEnabled is initialized data (game @0x001d81c0, __data) with the initial value true (read from
|
||||
// the binary). No function in the game writes it; Rollover::EnableRollovers has no code in the game binary.
|
||||
// - The rect constructor sets the offsets to 0 (no clear of mouseDown), copies both strings, then sets the window
|
||||
// size to (x2 - x1, y2 - y1) and the position to (x1, y1).
|
||||
// - Init reads xOffset / yOffset (default 0), xAbsolute / yAbsolute (default -1), "contents" (default "") and the
|
||||
// "command" function (kept only if non-null; otherwise the pointer stays empty).
|
||||
// - OnMouseMove (only when rollovers are enabled) builds a PopupWindow with a TPopupTestRect over this window's
|
||||
// rect, adopts it into the top modal window (no init), sets its contents, positions it at the absolute position
|
||||
// or the mouse (screen space) plus the offset, hands over the click function (or, without one and with a
|
||||
// non-empty click string, the click string) and registers it as a mouse listener. It returns rolloversEnabled.
|
||||
//
|
||||
// Compiler-generated in the game / header-inline code emitted out of line (bodies match Rollover.h):
|
||||
// - PFTYPEDEF_DC IsKindOf: game @0x0016e248 (compares the id against &RolloverDynamicCreate, else calls
|
||||
// TWindow::ClassId and compares).
|
||||
// - Rollover() default constructor: C2 game @0x0016e2bc, C1 game @0x001733d0; ~Rollover: D2 game @0x0016e320,
|
||||
// D1 game @0x00173358, D0 game @0x001731f4 (also deletes). The body releases pClickFunction, destroys
|
||||
// clickString and contentString and calls ~TWindow.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "Rollover.h"
|
||||
#include "Popup.h"
|
||||
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/modalwindow.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
// game @0x001d81c0 (initial value true)
|
||||
bool Rollover::rolloversEnabled = true;
|
||||
|
||||
// game @0x000342fc (RolloverDynamicCreate: new Rollover)
|
||||
// game @0x000341b4 (ClassId: returns &RolloverDynamicCreate)
|
||||
// game @0x000341be (GetTypeName, "Rollover")
|
||||
PFTYPEIMPL_DC(Rollover);
|
||||
|
||||
// game @0x000341ca
|
||||
void Rollover::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
FitToChildren();
|
||||
}
|
||||
|
||||
// game @0x000341f0
|
||||
void Rollover::SetPopupPosition(int32_t x, int32_t y)
|
||||
{
|
||||
xAbsolute = x;
|
||||
yAbsolute = y;
|
||||
}
|
||||
|
||||
// game @0x00034204
|
||||
Rollover::Rollover(TRect const& area, str rolloverContent, str clickCode)
|
||||
: xOffset(0), yOffset(0), xAbsolute(0), yAbsolute(0), contentString(rolloverContent), clickString(clickCode)
|
||||
{
|
||||
SetWindowSize(area.x2 - area.x1, area.y2 - area.y1);
|
||||
SetWindowPos(area.x1, area.y1);
|
||||
}
|
||||
|
||||
// game @0x00034338
|
||||
void Rollover::Init(TWindowStyle& style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
xOffset = (int32_t)style.GetNumber("xOffset", 0);
|
||||
yOffset = (int32_t)style.GetNumber("yOffset", 0);
|
||||
xAbsolute = (int32_t)style.GetNumber("xAbsolute", -1);
|
||||
yAbsolute = (int32_t)style.GetNumber("yAbsolute", -1);
|
||||
contentString = style.GetString("contents", "");
|
||||
TLuaFunction* pFunction = style.GetFunction("command");
|
||||
if (pFunction != 0) {
|
||||
pClickFunction = ::shared_ptr<TLuaFunction>(pFunction);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000345b4
|
||||
bool Rollover::OnMouseMove(TPoint const& point)
|
||||
{
|
||||
if (rolloversEnabled) {
|
||||
TRect rect(0, 0, 0, 0);
|
||||
GetWindowRect(&rect);
|
||||
TPopupTest* pTest = new TPopupTestRect(rect);
|
||||
PopupWindow* pPopup = new PopupWindow(pTest);
|
||||
TWindowManager::GetInstance()->GetTopModalWindow()->AdoptChild(pPopup, false);
|
||||
pPopup->SetContents(contentString);
|
||||
|
||||
TPoint screenMouse = point;
|
||||
ClientToScreen(&screenMouse);
|
||||
int32_t x = xAbsolute;
|
||||
if (x < 0) {
|
||||
x = screenMouse.x + xOffset;
|
||||
}
|
||||
int32_t y = screenMouse.y + yOffset;
|
||||
if (-1 < yAbsolute) {
|
||||
y = yAbsolute;
|
||||
}
|
||||
pPopup->Reposition(x, y);
|
||||
|
||||
if (!pClickFunction) {
|
||||
if (clickString.length() != 0) {
|
||||
pPopup->SetClickString(clickString);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pPopup->SetClickFunction(pClickFunction);
|
||||
}
|
||||
TWindowManager::GetInstance()->AddMouseListener(pPopup);
|
||||
}
|
||||
return rolloversEnabled;
|
||||
}
|
||||
147
port/game/ScalingTask.cpp
Normal file
147
port/game/ScalingTask.cpp
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
// Port of the game's ScalingTask.cpp (Chocolatier 3, Big Splash Games): the two scaled-time tasks the minigames
|
||||
// use, TScalingTask (driven by hand: Restart/Tick/Pause; no TAnimTask base) and TOldScalingTask : TAnimTask
|
||||
// (driven by the TTask scheduler). Both keep a raw time that advances by the elapsed clock time times a scale,
|
||||
// and a parameterized time t = time / full - floor(time / full).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// ScalingTask.h (port/game/ScalingTask.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TScalingTask: vptr 0x0, time 0x4, lastTime 0x8, scale 0xc, lastClock 0x10, taskClock 0x14,
|
||||
// paused 0x18; vtable slots Reset, Restart, Animate (Tick calls Animate, the third slot). TOldScalingTask:
|
||||
// TAnimTask 0x18, time 0x18, lastTime 0x1c, scale 0x20, lastClock 0x24. The headers match.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The elapsed-time term converts the unsigned tick difference to TReal before scaling:
|
||||
// (TReal)(uint32_t)(clock - lastClock) * scale + time.
|
||||
// - TScalingTask::Restart ignores its delay (it only re-bases lastClock and clears paused); TOldScalingTask::Restart
|
||||
// re-bases lastClock and calls TAnimTask::SetDelay(delay, true, true, false).
|
||||
// - TScalingTask::AnimateDelta returns newT - oldT, or 1.0f - oldT + newT when the parameterized time wrapped past
|
||||
// 1.0 (the 1.0f constant sits at 0x001ab6e4).
|
||||
// - TOldScalingTask::SetScale is declared in ScalingTask.h but has no code in the game (its symbol is an undefined
|
||||
// absolute .eh reference); TOldScalingTask::AdjustScale calls it.
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in ScalingTask.h):
|
||||
// ~TOldScalingTask (implicit): D2 game @0x001704c8, D1 game @0x001734d8, D0 game @0x001734f0.
|
||||
// Header-inline code emitted out of line (bodies match ScalingTask.h):
|
||||
// TScalingTask::GetT game @0x00168a08, TOldScalingTask::GetT game @0x0017048c.
|
||||
// The game also lists undecodable exception-handling clones (.eh) of most of these functions
|
||||
// (0x001ba7dc, 0x001bd3f8 .. 0x001bd4f8); they are not source functions.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "ScalingTask.h"
|
||||
|
||||
|
||||
// game @0x000347a2
|
||||
void TScalingTask::SetScale(TReal newScale)
|
||||
{
|
||||
scale = newScale;
|
||||
}
|
||||
|
||||
// game @0x000347b0
|
||||
void TOldScalingTask::Reset(TReal newScale)
|
||||
{
|
||||
time = 0.0f;
|
||||
lastTime = 0.0f;
|
||||
scale = newScale;
|
||||
lastClock = GetTime();
|
||||
}
|
||||
|
||||
// game @0x000347da
|
||||
bool TOldScalingTask::Animate(void)
|
||||
{
|
||||
uint32_t t = GetTime();
|
||||
|
||||
lastTime = time;
|
||||
time = (TReal)(uint32_t)(t - lastClock) * scale + time;
|
||||
lastClock = t;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00034830
|
||||
void TOldScalingTask::Restart(uint32_t delay)
|
||||
{
|
||||
lastClock = GetTime();
|
||||
SetDelay(delay, true, true, false);
|
||||
}
|
||||
|
||||
// game @0x00034872
|
||||
bool TScalingTask::Animate(void)
|
||||
{
|
||||
lastTime = time;
|
||||
time = (TReal)(uint32_t)(taskClock - lastClock) * scale + time;
|
||||
lastClock = taskClock;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x000348ba
|
||||
void TScalingTask::Pause(void)
|
||||
{
|
||||
paused = true;
|
||||
}
|
||||
|
||||
// game @0x000348c6
|
||||
void TScalingTask::Tick(uint32_t milliseconds)
|
||||
{
|
||||
if (!paused) {
|
||||
taskClock += milliseconds;
|
||||
Animate();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000348e6
|
||||
void TScalingTask::Reset(TReal newScale)
|
||||
{
|
||||
taskClock = 0;
|
||||
paused = true;
|
||||
time = 0.0f;
|
||||
lastTime = 0.0f;
|
||||
scale = newScale;
|
||||
lastClock = 0;
|
||||
}
|
||||
|
||||
// game @0x0003490e
|
||||
void TScalingTask::Restart(uint32_t delay)
|
||||
{
|
||||
lastClock = taskClock;
|
||||
paused = false;
|
||||
}
|
||||
|
||||
// game @0x00034920 (C2)
|
||||
TScalingTask::TScalingTask(void)
|
||||
{
|
||||
time = 0.0f;
|
||||
lastTime = 0.0f;
|
||||
scale = 1.0f;
|
||||
lastClock = 0;
|
||||
taskClock = 0;
|
||||
paused = true;
|
||||
}
|
||||
|
||||
// game @0x00034950
|
||||
TReal TScalingTask::AnimateDelta(TReal full)
|
||||
{
|
||||
TReal oldT = GetT(full);
|
||||
|
||||
lastTime = time;
|
||||
time = (TReal)(uint32_t)(taskClock - lastClock) * scale + time;
|
||||
lastClock = taskClock;
|
||||
|
||||
TReal newT = GetT(full);
|
||||
|
||||
if (newT >= oldT)
|
||||
return newT - oldT;
|
||||
|
||||
return (1.0f - oldT) + newT;
|
||||
}
|
||||
|
||||
// game @0x000349ee (C2)
|
||||
TOldScalingTask::TOldScalingTask(void)
|
||||
: TAnimTask(NULL)
|
||||
{
|
||||
time = 0.0f;
|
||||
lastTime = 0.0f;
|
||||
scale = 1.0f;
|
||||
lastClock = GetTime();
|
||||
}
|
||||
353
port/game/SignEditor.cpp
Normal file
353
port/game/SignEditor.cpp
Normal file
|
|
@ -0,0 +1,353 @@
|
|||
// Port of the game's SignEditor.cpp (Chocolatier 3, Big Splash Games): Sign, a TSprite made of a background texture,
|
||||
// a logo child sprite and a text child sprite (all configured from a Lua table), and SignEditor, the window that
|
||||
// owns a Sign and edits its colour, text, logo and font through sliders and Lua calls. HSVtoRGB (game @0x00036bd4)
|
||||
// lives in this object file too (address adjacency, see BSGHelpers.cpp).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// SignEditor.h (port/game/SignEditor.h, unchanged; the SignRef typedef note there is a host-compiler note only).
|
||||
//
|
||||
// Layout (game, i386): Sign : TSprite (0x80), pLogo 0x80 (+count 0x84), pText 0x88 (+count 0x8c); sizeof 0x90
|
||||
// (Sign::Create allocates 0x90). SignEditor : TWindow (0x30), pSign 0x30 (+count 0x34), textH 0x38, textS 0x3c,
|
||||
// textV 0x40, textA 0x44, textR 0x48, textX 0x4c, textY 0x50, textSize 0x54, logoScale 0x58, logoA 0x5c, logoR 0x60,
|
||||
// logoX 0x64, logoY 0x68; the header matches. TSprite::mDrawSpec is at 0x20 (mMatrix[2] at 0x38, mAlpha at 0x5c).
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Float constants (game __literal4 / __const): 100.0f @0x001ab754 (percent), 360.0f @0x001ab760, 6.0f @0x001ab764,
|
||||
// 15.0f @0x001ab768 (text size offset), 1.0f @0x001ab6e4, 2^31 @0x00192f00 / 0x00192ee0 / 0x00192ea0, 2^32
|
||||
// @0x00192f10 / 0x00192ef0 / 0x00192eb0 (the SSE float -> uint32 conversion sequences are plain (uint32_t) casts of
|
||||
// a value clamped to >= 0); the angle (double)(r + r) * pi / 360.0 uses pi @0x001ab4a8 and 360.0 @0x001ab508.
|
||||
// - The Sign constructor reads the table keys textH, textS, textV, textA (default 100), textX, textY, textSize
|
||||
// (default 30), logoScale (default 100), logoA (default 100), logoR, logoX, logoY (default 0), then loads
|
||||
// "logo/" + background (default "bg1") as the sign texture, "logo/" + logo (default "logo1") as a child sprite on
|
||||
// layer 1 (alpha logoA / 100, scale logoScale / 100, rotated by logoR), and a TTextSprite of 0x15e x 200, justify 5,
|
||||
// font "fonts/" + font (default "fertigo.mvec"), line height textSize, colour HSVtoRGB(textH, textS, textV) with
|
||||
// alpha textA / 100, layer 2, at (textX, textY), with the table's "text" (default "").
|
||||
// - SignEditor::OnMessage handles kSliderValChanged (type 9) from a child slider named after the property; the
|
||||
// slider value is scaled (textH by 360, other percent values by 100, textSize by 100 + 15, logoX / logoY / textX /
|
||||
// textY unscaled) before the matching Update* call; logoA is applied straight to the logo sprite's alpha. It always
|
||||
// returns false.
|
||||
// - PostChildrenInit reads the "sign" table of the window style (when present) into the members, creates the Sign from
|
||||
// it, deletes the table, and places the Sign at the style numbers "signx" / "signy".
|
||||
//
|
||||
// Compiler-generated in the game:
|
||||
// - PFTYPEDEF_DC IsKindOf of SignEditor: game @0x00174218 (compares the id against &SignEditorDynamicCreate, else
|
||||
// TWindow::IsKindOf); PFSHAREDTYPEDEF IsKindOf of Sign: game @0x001741ec (compares &Sign::ClassId, else
|
||||
// TSprite::ClassId).
|
||||
// - ~Sign: D1 game @0x00174244, D0 game @0x00174328 (releases pText, then pLogo, then ~TSprite).
|
||||
// - boost::shared_ptr<Sign> instantiations: shared_ptr<Sign>::shared_ptr() game @0x001742b4, shared_ptr<Sign>(Sign*)
|
||||
// game @0x001742cc, shared_count(Sign*, checked_deleter<Sign>) game @0x00174114, sp_counted_base_impl<Sign*,
|
||||
// checked_deleter<Sign>>: ctor game @0x001740ec, dispose game @0x001741d0, get_deleter game @0x001740cc, D1 game
|
||||
// @0x001741b4, D0 game @0x00174188.
|
||||
// - lua_pushdirectclosure<SignEditor, void (SignEditor::*)(str)> game @0x00173fc4;
|
||||
// LPCD::DirectCallMemberDispatcherHelper<SignEditor, void (SignEditor::*)(str)>::DirectCallMemberDispatcher game
|
||||
// game @0x00174088 (ReturnSpecialization<void>::Call<SignEditor, str> game @0x00174010).
|
||||
// - ~SignEditor: D1 game @0x0003771e, D0 game @0x000375e4 (also deletes the object).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "SignEditor.h"
|
||||
|
||||
#include "pf/message.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/slider.h"
|
||||
#include "pf/texture.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
// game @0x00036bd4
|
||||
TColor HSVtoRGB(float h, float s, float v)
|
||||
{
|
||||
TColor color;
|
||||
uint32_t sector;
|
||||
float p, q, t;
|
||||
|
||||
h = h / 360.0f;
|
||||
s = s / 100.0f;
|
||||
v = v / 100.0f;
|
||||
color.r = v;
|
||||
color.g = v;
|
||||
color.b = v;
|
||||
color.a = 1.0f;
|
||||
if (s <= 0.0f)
|
||||
return color;
|
||||
|
||||
h = h * 6.0f;
|
||||
if (h != 6.0f) {
|
||||
float clamped = h;
|
||||
if (h <= 0.0f)
|
||||
clamped = 0.0f;
|
||||
sector = (uint32_t)clamped;
|
||||
} else {
|
||||
sector = 0;
|
||||
h = 0.0f;
|
||||
}
|
||||
p = (1.0f - s) * v;
|
||||
q = (1.0f - s * (h - (float)sector)) * v;
|
||||
t = (1.0f - s * (1.0f - (h - (float)sector))) * v;
|
||||
switch (sector) {
|
||||
case 0:
|
||||
color.g = t;
|
||||
color.b = p;
|
||||
break;
|
||||
case 1:
|
||||
color.r = q;
|
||||
color.b = p;
|
||||
break;
|
||||
case 2:
|
||||
color.r = p;
|
||||
color.b = t;
|
||||
break;
|
||||
case 3:
|
||||
color.r = p;
|
||||
color.g = q;
|
||||
break;
|
||||
case 4:
|
||||
color.r = t;
|
||||
color.g = p;
|
||||
break;
|
||||
case 5:
|
||||
color.g = p;
|
||||
color.b = q;
|
||||
break;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
// game @0x00036bca (GetTypeName, "Sign"); ClassId returns &Sign::ClassId
|
||||
PFTYPEIMPL(Sign);
|
||||
|
||||
// game @0x00037c98
|
||||
Sign::Sign(TLuaTable* pTable) :
|
||||
TSprite(0)
|
||||
{
|
||||
float textH = (float)pTable->GetNumber("textH", 0);
|
||||
float textS = (float)pTable->GetNumber("textS", 0);
|
||||
float textV = (float)pTable->GetNumber("textV", 0);
|
||||
float textA = (float)pTable->GetNumber("textA", 100);
|
||||
float textX = (float)pTable->GetNumber("textX", 0);
|
||||
float textY = (float)pTable->GetNumber("textY", 0);
|
||||
float textSize = (float)pTable->GetNumber("textSize", 30);
|
||||
float logoScale = (float)pTable->GetNumber("logoScale", 100);
|
||||
float logoA = (float)pTable->GetNumber("logoA", 100);
|
||||
float logoR = (float)pTable->GetNumber("logoR", 0);
|
||||
float logoX = (float)pTable->GetNumber("logoX", 0);
|
||||
float logoY = (float)pTable->GetNumber("logoY", 0);
|
||||
|
||||
str background = str("logo/") + pTable->GetString("background", str("bg1"));
|
||||
SetTexture(TTexture::Get(background, 0));
|
||||
|
||||
float logoScaleF = logoScale / 100.0f;
|
||||
float logoAlphaF = logoA / 100.0f;
|
||||
|
||||
str logo = str("logo/") + pTable->GetString("logo", str("logo1"));
|
||||
pLogo = TSprite::Create(1, TTexture::Get(logo, 0));
|
||||
pLogo->GetDrawSpec() = TDrawSpec(TVec2(logoX, logoY), logoAlphaF, logoScaleF, 0);
|
||||
pLogo->GetDrawSpec().mMatrix.Rotate((float)(((double)(logoR + logoR) * 3.141592653589793) / 360.0));
|
||||
AddChild(pLogo);
|
||||
|
||||
str font = str("fonts/") + pTable->GetString("font", str("fertigo.mvec"));
|
||||
TColor rgb = HSVtoRGB(textH, textS, textV);
|
||||
TColor textColor(rgb.r, rgb.g, rgb.b, textA / 100.0f);
|
||||
if (textSize <= 0.0f)
|
||||
textSize = 0.0f;
|
||||
pText = TTextSprite::Create(0x15e, 200, 5, font.c_str(), (uint32_t)textSize, textColor, 2);
|
||||
pText->GetDrawSpec().mMatrix[2] = TVec3(textX, textY, 1.0f);
|
||||
AddChild(pText);
|
||||
|
||||
str text = pTable->GetString("text", str(""));
|
||||
pText->SetText(text);
|
||||
}
|
||||
|
||||
// game @0x00038778
|
||||
SignRef Sign::Create(TLuaTable* pTable)
|
||||
{
|
||||
return SignRef(new Sign(pTable));
|
||||
}
|
||||
|
||||
// game @0x00037c5c (SignEditorDynamicCreate: new SignEditor)
|
||||
// game @0x00036bb6 (ClassId: returns &SignEditorDynamicCreate)
|
||||
// game @0x00036bc0 (GetTypeName, "SignEditor")
|
||||
PFTYPEIMPL_DC(SignEditor);
|
||||
|
||||
// game @0x00037a64
|
||||
SignEditor::SignEditor(void)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "SetBackground", this, SignEditor::SetBackground);
|
||||
ScriptRegisterMemberDirect(script, "SetLogo", this, SignEditor::SetLogo);
|
||||
ScriptRegisterMemberDirect(script, "SetFont", this, SignEditor::SetFont);
|
||||
ScriptRegisterMemberDirect(script, "SetText", this, SignEditor::SetText);
|
||||
}
|
||||
|
||||
// game @0x0003771e (D1), game @0x000375e4 (D0)
|
||||
SignEditor::~SignEditor(void)
|
||||
{
|
||||
TScript* script = TPlatform::GetInstance()->GetWindowManager()->GetScript();
|
||||
ScriptUnregisterFunction(script, "SetBackground");
|
||||
ScriptUnregisterFunction(script, "SetLogo");
|
||||
ScriptUnregisterFunction(script, "SetFont");
|
||||
ScriptUnregisterFunction(script, "SetText");
|
||||
}
|
||||
|
||||
// game @0x000387cc
|
||||
void SignEditor::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
|
||||
TLuaTable* pTable = style.GetTable(str("sign"));
|
||||
if (pTable != NULL) {
|
||||
textH = (float)pTable->GetNumber("textH", 0);
|
||||
textS = (float)pTable->GetNumber("textS", 0);
|
||||
textV = (float)pTable->GetNumber("textV", 0);
|
||||
textA = (float)pTable->GetNumber("textA", 100);
|
||||
textX = (float)pTable->GetNumber("textX", 0);
|
||||
textY = (float)pTable->GetNumber("textY", 0);
|
||||
textSize = (float)pTable->GetNumber("textSize", 30);
|
||||
logoScale = (float)pTable->GetNumber("logoScale", 100);
|
||||
logoA = (float)pTable->GetNumber("logoA", 100);
|
||||
logoR = (float)pTable->GetNumber("logoR", 0);
|
||||
logoX = (float)pTable->GetNumber("logoX", 0);
|
||||
logoY = (float)pTable->GetNumber("logoY", 0);
|
||||
|
||||
pSign = Sign::Create(pTable);
|
||||
delete pTable;
|
||||
|
||||
float signX = (float)style.GetNumber(str("signx"), 0);
|
||||
float signY = (float)style.GetNumber(str("signy"), 0);
|
||||
pSign->GetDrawSpec().mMatrix[2] = TVec3(signX, signY, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00036ec2
|
||||
void SignEditor::Draw(void)
|
||||
{
|
||||
TBegin2d begin2d;
|
||||
|
||||
if (pSign)
|
||||
pSign->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
TWindow::Draw();
|
||||
|
||||
begin2d.Done();
|
||||
}
|
||||
|
||||
// game @0x0003710a
|
||||
bool SignEditor::OnMessage(TMessage* pMessage)
|
||||
{
|
||||
if (pMessage->mType != TMessage::kSliderValChanged)
|
||||
return false;
|
||||
|
||||
str name = pMessage->mName;
|
||||
TWindow* pChild = GetChildWindow(name, -1);
|
||||
if (pChild == NULL)
|
||||
return false;
|
||||
TSlider* pSlider = pChild->GetCast<TSlider>();
|
||||
if (pSlider == NULL)
|
||||
return false;
|
||||
|
||||
str property = pMessage->mName;
|
||||
float value = (float)pSlider->GetValue();
|
||||
|
||||
if (pMessage->mName == str("textH")) {
|
||||
textH = value * 360.0f;
|
||||
UpdateTextColor();
|
||||
} else if (pMessage->mName == str("textS")) {
|
||||
textS = value * 100.0f;
|
||||
UpdateTextColor();
|
||||
} else if (pMessage->mName == str("textV")) {
|
||||
textV = value * 100.0f;
|
||||
UpdateTextColor();
|
||||
} else if (pMessage->mName == str("textA")) {
|
||||
textA = value * 100.0f;
|
||||
UpdateTextColor();
|
||||
} else if (pMessage->mName == str("textX")) {
|
||||
textX = value;
|
||||
UpdateTextMatrix();
|
||||
} else if (pMessage->mName == str("textY")) {
|
||||
textY = value;
|
||||
UpdateTextMatrix();
|
||||
} else if (pMessage->mName == str("textSize")) {
|
||||
textSize = value * 100.0f + 15.0f;
|
||||
float lineHeight = textSize;
|
||||
if (lineHeight <= 0.0f)
|
||||
lineHeight = 0.0f;
|
||||
pSign->pText->SetLineHeight((uint32_t)lineHeight);
|
||||
} else if (pMessage->mName == str("logoScale")) {
|
||||
logoScale = value * 100.0f;
|
||||
UpdateLogoMatrix();
|
||||
} else if (pMessage->mName == str("logoA")) {
|
||||
float percent = value * 100.0f;
|
||||
logoA = percent;
|
||||
pSign->pLogo->GetDrawSpec().mAlpha = percent / 100.0f;
|
||||
} else if (pMessage->mName == str("logoR")) {
|
||||
logoR = value * 100.0f;
|
||||
UpdateLogoMatrix();
|
||||
} else if (pMessage->mName == str("logoX")) {
|
||||
logoX = value;
|
||||
UpdateLogoMatrix();
|
||||
} else if (pMessage->mName == str("logoY")) {
|
||||
logoY = value;
|
||||
UpdateLogoMatrix();
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0003795e
|
||||
void SignEditor::SetBackground(str background)
|
||||
{
|
||||
background = str("logo/") + background;
|
||||
pSign->SetTexture(TTexture::Get(background, 0));
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x00037852
|
||||
void SignEditor::SetLogo(str logo)
|
||||
{
|
||||
logo = str("logo/") + logo;
|
||||
pSign->pLogo->SetTexture(TTexture::Get(logo, 0));
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x00036d4c
|
||||
void SignEditor::SetFont(str font)
|
||||
{
|
||||
font = str("fonts/") + font;
|
||||
pSign->pText->SetFont(font.c_str());
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x00036df2
|
||||
void SignEditor::SetText(str text)
|
||||
{
|
||||
pSign->pText->SetText(text);
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
|
||||
// game @0x00036e54
|
||||
void SignEditor::UpdateTextColor(void)
|
||||
{
|
||||
TColor rgb = HSVtoRGB(textH, textS, textV);
|
||||
TColor color(rgb.r, rgb.g, rgb.b, textA / 100.0f);
|
||||
pSign->pText->SetColor(color);
|
||||
}
|
||||
|
||||
// game @0x0003704a
|
||||
void SignEditor::UpdateTextMatrix(void)
|
||||
{
|
||||
float alpha = textA / 100.0f;
|
||||
TDrawSpec spec(TVec2(textX, textY), alpha, 1.0f, 0);
|
||||
pSign->pText->GetDrawSpec() = spec;
|
||||
pSign->pText->GetDrawSpec().mMatrix.Rotate((float)(((double)(textR + textR) * 3.141592653589793) / 360.0));
|
||||
}
|
||||
|
||||
// game @0x00036f6a
|
||||
void SignEditor::UpdateLogoMatrix(void)
|
||||
{
|
||||
float scale = logoScale / 100.0f;
|
||||
float alpha = logoA / 100.0f;
|
||||
TDrawSpec spec(TVec2(logoX, logoY), alpha, scale, 0);
|
||||
pSign->pLogo->GetDrawSpec() = spec;
|
||||
pSign->pLogo->GetDrawSpec().mMatrix.Rotate((float)(((double)(logoR + logoR) * 3.141592653589793) / 360.0));
|
||||
}
|
||||
265
port/game/SlotMachine.cpp
Normal file
265
port/game/SlotMachine.cpp
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
// Port of the game's SlotMachine.cpp (Chocolatier 3, Big Splash Games): SlotMachine, a four-wheel slot machine
|
||||
// window driven from Lua (StartSlots / StopSlots), and SlotWheel, one scrolling wheel.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); the declarations (SlotMachine.h) are
|
||||
// reconstructed from the binary because the game ships no header. Game-only classes: no SDK counterpart.
|
||||
//
|
||||
// Layout (game, i386): see SlotMachine.h. SlotWheel: spinsLeft 0x4, speed 0x8, offset 0xc, baseY 0x10, pItems 0x14,
|
||||
// target 0x18, pRoot 0x1c/0x20, names[4] 0x24, pSprites[4] 0x34, sizeof 0x54. SlotMachine : TWindow (0x30) stopped
|
||||
// 0x30, payoutPosition 0x34, payoutParticles 0x40 (0xb8 bytes), payoutDone 0xfc, payout 0x100, items 0x104, wheels
|
||||
// 0x110, pOnStopped 0x130, pOnPayout 0x138, sizeof 0x140.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - SlotWheel constructor: root sprite (layer 0, no texture) scaled by (0.425, 0.425) at the given position; four item
|
||||
// sprites (random item, texture "items/<name>_big") stacked at y = -120, -60, 0, 60, children of the root.
|
||||
// Start(target) sets the target index (target - 1), spinsLeft = RandRange(20, 50), speed = RandRange(90, 110).
|
||||
// - Tick: while spinsLeft != 0 the offset grows by speed; every 200 units the names shift down one slot, a random
|
||||
// item enters at the top (the sound "spin_stop" plays on the last step), spinsLeft decreases (at 2 the top item
|
||||
// becomes the target item) and the four sprites get the textures "items/<name>_big". The root sprite's y is
|
||||
// baseY + offset * 60 / 200 (baseY once stopped).
|
||||
// - SlotMachine::OnTaskAnimate ticks the four wheels; when all have stopped it plays "Stop_machine_spin", calls the
|
||||
// "onstopped" function and sets the payout particle globals gSparkleTime = 0.5 * payout + 1 and gSparkleDensity =
|
||||
// 10 * payout; then it runs the payout particles (50 ms steps) until gSparkleTime <= 0 (or at once when
|
||||
// payout <= 0), plays "Stop_win_money" and calls "onpayout". It returns false once both are done.
|
||||
// - StopOne shortens the first wheel that is still spinning to at most 3 steps.
|
||||
// - PostChildrenInit reads the "options" list (the item names), the tables "wheel1".."wheel4" (x, y), sets the
|
||||
// payout particle position to (185, 244) and reads the functions "onstopped" / "onpayout".
|
||||
//
|
||||
// Compiler-generated or macro / header-inline code emitted out of line:
|
||||
// PFTYPEDEF_DC: SlotMachineDynamicCreate game @0x0003b1a4, ClassId game @0x00039eb8, GetTypeName game @0x00039ec2,
|
||||
// IsKindOf game @0x00174f04. ~SlotMachine: D1 game @0x0003a2b4, D0 game @0x0003a114 (also deletes; sets the Lua
|
||||
// functions StartSlots / StopSlots to nil). ~SlotWheel game @0x00174f48. The boost::shared_ptr<SlotWheel>
|
||||
// instantiations (game @0x00174f30, 0x00174ff4..0x00175090) are not ported.
|
||||
// Lua registration instances: lua_pushdirectclosure<SlotMachine, void (SlotMachine::*)(unsigned, unsigned,
|
||||
// unsigned, unsigned, float)> game @0x00174b74, <(void)> game @0x00174bc0; LPCD::ReturnSpecialization<void>::Call<
|
||||
// SlotMachine, unsigned, unsigned, unsigned, unsigned, float> game @0x00174c2c; DirectCallMemberDispatcherHelper
|
||||
// <(unsigned x4, float)> game @0x00174e08, <(void)> game @0x00174ebc.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "SlotMachine.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGSound.h"
|
||||
#include "pf/luaparticlesystem.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
PFTYPEIMPL_DC(SlotMachine);
|
||||
|
||||
// game @0x00039ecc
|
||||
void SlotWheel::Start(uint32_t targetIndex)
|
||||
{
|
||||
target = targetIndex - 1;
|
||||
spinsLeft = RandRange(0x14, 0x32);
|
||||
speed = RandRange(0x5a, 0x6e);
|
||||
}
|
||||
|
||||
// game @0x00039fd4
|
||||
void SlotWheel::Draw(void)
|
||||
{
|
||||
if (pRoot) {
|
||||
pRoot->Draw(TDrawSpec(TVec2(), 1.0f, 1.0f, 0), -1);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003a44c
|
||||
void SlotWheel::Tick(void)
|
||||
{
|
||||
if (spinsLeft != 0) {
|
||||
uint32_t total = offset + speed;
|
||||
offset = total;
|
||||
if (199 < total) {
|
||||
if (spinsLeft == 1) {
|
||||
BSGSoundEvent("spin_stop");
|
||||
}
|
||||
uint32_t pick = RandRange(0, (uint32_t)pItems->size() - 1);
|
||||
names[3] = names[2];
|
||||
names[2] = names[1];
|
||||
names[1] = names[0];
|
||||
names[0] = (*pItems)[pick];
|
||||
spinsLeft = spinsLeft - 1;
|
||||
if (spinsLeft == 2) {
|
||||
names[0] = (*pItems)[target];
|
||||
}
|
||||
for (int i = 0; i != 4; i++) {
|
||||
TTextureRef pTexture = TTexture::Get(str("items/") + names[i] + str("_big"), 0);
|
||||
pSprites[i]->SetTexture(pTexture);
|
||||
}
|
||||
total = offset;
|
||||
}
|
||||
offset = total % 200;
|
||||
if (spinsLeft == 0) {
|
||||
pRoot->GetDrawSpec().mMatrix[2].y = baseY;
|
||||
}
|
||||
else {
|
||||
pRoot->GetDrawSpec().mMatrix[2].y = ((TReal)(total % 200) * 60.0f) / 200.0f + baseY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003aa34
|
||||
SlotWheel::SlotWheel(TVec2 position, vector<str>& items)
|
||||
{
|
||||
pItems = &items;
|
||||
target = 0;
|
||||
pRoot = TSprite::Create(0, TTextureRef());
|
||||
pRoot->GetDrawSpec().mMatrix.Scale(0.42500001192092896f, 0.42500001192092896f);
|
||||
pRoot->GetDrawSpec().mMatrix[2] = TVec3(position, 1.0f);
|
||||
baseY = position.y;
|
||||
TReal y = -120.0f;
|
||||
for (int i = 0; i != 4; i++) {
|
||||
uint32_t pick = RandRange(0, (uint32_t)pItems->size() - 1);
|
||||
names[i] = (*pItems)[pick];
|
||||
TTextureRef pTexture = TTexture::Get(str("items/") + names[i] + str("_big"), 0);
|
||||
pSprites[i] = TSprite::Create(0, pTexture);
|
||||
pSprites[i]->GetDrawSpec().mMatrix[2] = TVec3(0, y, 1.0f);
|
||||
pRoot->AddChild(pSprites[i]);
|
||||
y = y + 60.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00039f16
|
||||
void SlotMachine::StartMachine(uint32_t wheel1, uint32_t wheel2, uint32_t wheel3, uint32_t wheel4, TReal payout_)
|
||||
{
|
||||
stopped = false;
|
||||
payoutDone = false;
|
||||
unused = 0;
|
||||
wheels[0]->Start(wheel1);
|
||||
wheels[1]->Start(wheel2);
|
||||
wheels[2]->Start(wheel3);
|
||||
wheels[3]->Start(wheel4);
|
||||
payout = payout_;
|
||||
StartWindowAnimation(0x32, true, true, false);
|
||||
}
|
||||
|
||||
// game @0x0003a03e
|
||||
void SlotMachine::Draw(void)
|
||||
{
|
||||
TBegin2d begin2d;
|
||||
wheels[0]->Draw();
|
||||
wheels[1]->Draw();
|
||||
wheels[2]->Draw();
|
||||
wheels[3]->Draw();
|
||||
payoutParticles.Draw(payoutPosition);
|
||||
TWindow::Draw();
|
||||
begin2d.Done();
|
||||
}
|
||||
|
||||
// game @0x0003a0ca
|
||||
void SlotMachine::StopOne(void)
|
||||
{
|
||||
SlotWheel* pWheel = wheels[0].get();
|
||||
if (pWheel->spinsLeft != 0 || (pWheel = wheels[1].get(), pWheel->spinsLeft != 0) ||
|
||||
(pWheel = wheels[2].get(), pWheel->spinsLeft != 0) || (pWheel = wheels[3].get(), pWheel->spinsLeft != 0)) {
|
||||
if (3 < pWheel->spinsLeft) {
|
||||
pWheel->spinsLeft = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003a2b4 (D1), game @0x0003a114 (D0)
|
||||
SlotMachine::~SlotMachine()
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptUnregisterFunction(script, "StartSlots");
|
||||
ScriptUnregisterFunction(script, "StopSlots");
|
||||
}
|
||||
|
||||
// game @0x0003a74c
|
||||
bool SlotMachine::OnTaskAnimate(void)
|
||||
{
|
||||
if (!stopped) {
|
||||
stopped = true;
|
||||
for (int i = 0; i != 4; i++) {
|
||||
wheels[i]->Tick();
|
||||
if (wheels[i]->spinsLeft != 0) {
|
||||
stopped = false;
|
||||
}
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
if (stopped) {
|
||||
if (pOnStopped) {
|
||||
BSGSoundEvent("Stop_machine_spin");
|
||||
pOnStopped->Push();
|
||||
TWindowManager::GetInstance()->GetScript()->InjectFunction();
|
||||
}
|
||||
double sparkleTime = (double)(0.5f * payout + 1.0f);
|
||||
payoutParticles.GetScript()->SetGlobalNumber("gSparkleTime", sparkleTime);
|
||||
double sparkleDensity = (double)(10.0f * payout);
|
||||
payoutParticles.GetScript()->SetGlobalNumber("gSparkleDensity", sparkleDensity);
|
||||
}
|
||||
}
|
||||
if (stopped && !payoutDone) {
|
||||
if (payout <= 0.0f) {
|
||||
payoutDone = true;
|
||||
}
|
||||
else {
|
||||
payoutParticles.Update(0x32);
|
||||
double sparkleTime = payoutParticles.GetScript()->GetGlobalNumber("gSparkleTime");
|
||||
if (sparkleTime <= 0.0 && sparkleTime == sparkleTime) {
|
||||
payoutDone = true;
|
||||
}
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
if (payoutDone && pOnPayout) {
|
||||
BSGSoundEvent("Stop_win_money");
|
||||
pOnPayout->Push();
|
||||
TWindowManager::GetInstance()->GetScript()->InjectFunction();
|
||||
}
|
||||
}
|
||||
if (!stopped || !payoutDone) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0003af00
|
||||
SlotMachine::SlotMachine(void) :
|
||||
stopped(false),
|
||||
payoutParticles(0),
|
||||
payoutDone(false)
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "StartSlots", this, SlotMachine::StartMachine);
|
||||
ScriptRegisterMemberDirect(script, "StopSlots", this, SlotMachine::StopOne);
|
||||
payoutParticles.GetScript()->SetGlobalString("gSparkleTexture", "dollars_big");
|
||||
payoutParticles.Init("glitz/slotpayout.lua");
|
||||
}
|
||||
|
||||
// game @0x0003b1e0
|
||||
void SlotMachine::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
TLuaTable* pOptions = style.GetTable("options");
|
||||
if (pOptions != 0) {
|
||||
TLuaObjectWrapper* key = 0;
|
||||
TLuaObjectWrapper* pItem;
|
||||
while ((pItem = pOptions->GetNext(&key)) != 0) {
|
||||
items.push_back(pItem->AsString());
|
||||
delete pItem;
|
||||
}
|
||||
delete pOptions;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
TLuaTable* pWheel = style.GetTable(str::getFormatted("wheel%d", i + 1));
|
||||
if (pWheel != 0) {
|
||||
lua_Number x = pWheel->GetNumber("x", 0.0);
|
||||
lua_Number y = pWheel->GetNumber("y", 0.0);
|
||||
TVec2 position((float)x, (float)y);
|
||||
wheels[i] = SlotWheelRef(new SlotWheel(position, items));
|
||||
delete pWheel;
|
||||
}
|
||||
}
|
||||
payoutPosition = TVec3(185.0f, 244.0f, 1.0f);
|
||||
TLuaFunction* pFunction = style.GetFunction("onstopped");
|
||||
if (pFunction != 0) {
|
||||
pOnStopped = ::shared_ptr<TLuaFunction>(pFunction);
|
||||
}
|
||||
pFunction = style.GetFunction("onpayout");
|
||||
if (pFunction != 0) {
|
||||
pOnPayout = ::shared_ptr<TLuaFunction>(pFunction);
|
||||
}
|
||||
}
|
||||
72
port/game/SlotMachine.h
Normal file
72
port/game/SlotMachine.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
// Declarations for the game's SlotMachine.cpp (Chocolatier 3, Big Splash Games): SlotWheel and SlotMachine.
|
||||
// The shipped game has no header for these classes (choc3/cpp_src/SlotMachine.cpp: "no matching header"), so the
|
||||
// declarations are reconstructed from the game binary: member offsets are those of the i386 build (see the notes
|
||||
// in SlotMachine.cpp), member names are chosen here (the game binary has no member names).
|
||||
|
||||
#ifndef SLOTMACHINE_H
|
||||
#define SLOTMACHINE_H
|
||||
|
||||
#include "chocothree.h"
|
||||
#include <pf/sprite.h>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
//*****************************************************************************
|
||||
// One wheel of the slot machine: a column of four item sprites that scroll in steps of 200 units and settle on the
|
||||
// item given to Start. sizeof 0x54 in the game.
|
||||
class SlotWheel
|
||||
{
|
||||
public:
|
||||
SlotWheel(TVec2 position, vector<str>& items);
|
||||
void Start(uint32_t targetIndex);
|
||||
void Tick(void);
|
||||
void Draw(void);
|
||||
|
||||
int32_t unused; // 0x00 (never accessed in the game)
|
||||
uint32_t spinsLeft; // 0x04 steps still to scroll (0 = stopped)
|
||||
uint32_t speed; // 0x08 scroll units per tick
|
||||
uint32_t offset; // 0x0c scroll offset inside one step (0..199)
|
||||
TReal baseY; // 0x10 y of the wheel root sprite
|
||||
vector<str>* pItems; // 0x14 item names
|
||||
int32_t target; // 0x18 index of the item to stop on
|
||||
TSpriteRef pRoot; // 0x1c root sprite
|
||||
str names[4]; // 0x24 item names shown by the four sprites
|
||||
TSpriteRef pSprites[4]; // 0x34 item sprites
|
||||
};
|
||||
|
||||
typedef ::shared_ptr<SlotWheel> SlotWheelRef;
|
||||
|
||||
//*****************************************************************************
|
||||
// sizeof 0x140 in the game.
|
||||
class SlotMachine : public TWindow
|
||||
{
|
||||
public:
|
||||
SlotMachine(void);
|
||||
virtual ~SlotMachine();
|
||||
|
||||
virtual void PostChildrenInit(TWindowStyle& style);
|
||||
virtual bool OnTaskAnimate(void);
|
||||
virtual void Draw(void);
|
||||
|
||||
void StartMachine(uint32_t wheel1, uint32_t wheel2, uint32_t wheel3, uint32_t wheel4, TReal payout);
|
||||
void StopOne(void);
|
||||
|
||||
protected:
|
||||
bool stopped; // 0x30 all wheels have stopped
|
||||
TVec3 payoutPosition; // 0x34 where the payout particles are drawn
|
||||
TLuaParticleSystem payoutParticles; // 0x40
|
||||
int32_t unused; // 0xf8 (cleared by StartMachine, never read)
|
||||
bool payoutDone; // 0xfc
|
||||
TReal payout; // 0x100
|
||||
vector<str> items; // 0x104
|
||||
SlotWheelRef wheels[4]; // 0x110
|
||||
::shared_ptr<TLuaFunction> pOnStopped; // 0x130
|
||||
::shared_ptr<TLuaFunction> pOnPayout; // 0x138
|
||||
|
||||
private:
|
||||
SlotMachine(SlotMachine const&);
|
||||
SlotMachine& operator=(SlotMachine const&);
|
||||
PFTYPEDEF_DC(SlotMachine, TWindow);
|
||||
};
|
||||
|
||||
#endif // SLOTMACHINE_H
|
||||
44
port/game/SoundHandler.cpp
Normal file
44
port/game/SoundHandler.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// Port of the game's SoundHandler.cpp (Chocolatier 3, Big Splash Games): TSoundHandler, the message listener the
|
||||
// factories create; it turns sound-event messages (mType kSoundEvent, the event name in mName) into BSGSoundEvent
|
||||
// calls.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// SoundHandler.h (port/game/SoundHandler.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TMessageListener vptr 0x0, TAssetMap soundMap 0x4; sizeof 0x24 (the factories allocate 0x24
|
||||
// with new). The constructor adopts the instance with TWindowManager::AdoptMessageListener.
|
||||
//
|
||||
// AddSound and PlaySound are declared in SoundHandler.h but appear nowhere in the game (no symbols, no call sites);
|
||||
// the ChocolateFactory and CoffeeFactory constructors create the handler with new (0x24) and keep it in their
|
||||
// pSoundHandler member.
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in SoundHandler.h):
|
||||
// ~TSoundHandler (implicit, virtual through TMessageListener): D0 game @0x001743d0, D1 game @0x00174418.
|
||||
// The game also lists undecodable exception-handling clones (.eh) at 0x001be660 .. 0x001be6ec; not source functions.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "SoundHandler.h"
|
||||
|
||||
#include "BSGSound.h"
|
||||
#include "chocothree.h"
|
||||
|
||||
#include "pf/message.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x00038ba4
|
||||
bool TSoundHandler::OnMessage(TMessage * pMessage)
|
||||
{
|
||||
if (pMessage->mType == kSoundEvent) {
|
||||
BSGSoundEvent(pMessage->mName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00038c00 (C1)
|
||||
TSoundHandler::TSoundHandler(void)
|
||||
{
|
||||
TWindowManager::GetInstance()->AdoptMessageListener(this);
|
||||
}
|
||||
56
port/game/TightText.cpp
Normal file
56
port/game/TightText.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// Port of the game's TightText.cpp (Chocolatier 3, Big Splash Games): TTightText, a TText whose window is sized to
|
||||
// the rendered text plus a style-configurable padding (the game's "tight" text windows).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// TightText.h (port/game/TightText.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TText 0x48, padding int32 +0x48; sizeof 0x4c (TTightTextDynamicCreate allocates 0x4c).
|
||||
// The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Init calls TText::Init and TWindow::SetWindowSize(800, 600), then reads the style number "pad" (default 3) and
|
||||
// truncates it to int (cvttsd2si).
|
||||
// - PostChildrenInit sizes the window to the text bounds grown by the padding: width (x2 - x1) + padding,
|
||||
// height y2 - y1.
|
||||
//
|
||||
// Compiler-generated in the game:
|
||||
// - TTightText::TTightText is header-inline (TightText.h: "TTightText(void) {}"): emitted out of line at
|
||||
// game @0x00174480 (TText::TText(false) + vtable store).
|
||||
// - ~TTightText is implicit (no declaration in TightText.h): D1 game @0x001744a8, D0 game @0x001744c0 (vtable store
|
||||
// + TText::~TText, D0 then operator delete).
|
||||
// - IsKindOf (PFTYPEDEF_DC): game @0x001744e8 (compares the id against &TTightTextDynamicCreate, else
|
||||
// TText::IsKindOf).
|
||||
//
|
||||
// Strings from the game's __cstring: "TTightText" (@0x0015a4ec), "pad" (@0x0015a4f8).
|
||||
// The game also lists undecodable exception-handling clones (.eh) from 0x001be764 on; not source functions.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "TightText.h"
|
||||
|
||||
#include "pf/rect.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
|
||||
// game @0x00038c62 (TTightTextDynamicCreate: new TTightText, sizeof 0x4c)
|
||||
// game @0x00038c58 (ClassId: returns &TTightTextDynamicCreate)
|
||||
// game @0x00038c9e (GetTypeName, "TTightText")
|
||||
PFTYPEIMPL_DC(TTightText);
|
||||
|
||||
// game @0x00038ca8
|
||||
void TTightText::Init(TWindowStyle& style)
|
||||
{
|
||||
TText::Init(style);
|
||||
SetWindowSize(800, 600);
|
||||
|
||||
padding = (int32_t)style.GetNumber("pad", 3.0);
|
||||
}
|
||||
|
||||
// game @0x00038d38
|
||||
void TTightText::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
|
||||
TRect bounds;
|
||||
GetTextBounds(&bounds);
|
||||
SetWindowSize((bounds.x2 - bounds.x1) + padding, bounds.y2 - bounds.y1);
|
||||
}
|
||||
269
port/game/Transitions.cpp
Normal file
269
port/game/Transitions.cpp
Normal file
|
|
@ -0,0 +1,269 @@
|
|||
// Port of the game's Transitions.cpp (Chocolatier 3, Big Splash Games): the window transition tasks (fade in, fade
|
||||
// out, swipe along a straight line, move along a curve, zoom an image) and DoTransition, the Lua "Transition"
|
||||
// function that builds one from a table and starts it.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// Transitions.h (port/game/Transitions.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): BSGTransition: TAnimTask 0x0 (vptr 0x0), TMessageListener 0x18 (vptr 0x18), pTarget 0x1c,
|
||||
// name 0x20, pEndFunction 0x24, pLiveFlag 0x28 (px, count 0x2c), duration 0x30, startTime 0x34, t 0x38;
|
||||
// FadeIn/FadeOut alpha 0x3c (sizeof 0x40), Swipe start 0x3c / end 0x44 (sizeof 0x4c), Curve pCurve 0x3c (0x44),
|
||||
// ZoomIn pImage 0x3c (0x40). TWindowFader: vptr 0x0, alpha 0x4. The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The constructor names the transition after the top modal window's ID ("%8x" of its mID, the inlined
|
||||
// TWindow::GetID); BSGTransition::OnMessage listens for kModalClosed (type 6) with that name and, while the live
|
||||
// flag is set, runs and deletes the end function and clears the flag. Animate does the same when the duration is
|
||||
// over; the destructor clears the live flag and orphans the message listener.
|
||||
// - Animate: while the live flag is unset (or absent) it does nothing and returns false. Otherwise it shows the
|
||||
// target (BSGShowWindow), sets t = (float)elapsed / (float)duration (1.0f once elapsed >= duration), calls the
|
||||
// virtual ApplyTransition, invalidates the screen and returns true until the duration is over.
|
||||
// - FadeOutTransition applies (1.0f - t) * alpha. ZoomInTransition re-sets the image's own texture with scale t.
|
||||
// CurveTransition places the window at the curve point for normalized length t, adding 0.5 to each component
|
||||
// before the int conversion (the double at @0x001ab488; 1.0f at @0x001ab6e4).
|
||||
// - DoTransition ("Transition" in Lua, see chocothree.cpp): the table's "window" names a child of the top modal
|
||||
// window, element 1 selects the type, "onend" is the end function and "time" the duration in milliseconds
|
||||
// (default 100.0, converted like (uint32_t)double, sseconv.h). Types: "center_fadein" (hide, alpha 0, FadeIn, center
|
||||
// horizontally), "center" (only centers; the end function is deleted without being called), "fadein" (FadeIn,
|
||||
// alpha set to 0), "fadeout", "swipe" (startx, starty, endx, endy default to the window's position), "path"
|
||||
// (a TCurve built from the "path" table), "zoomin". "alpha" defaults to 1.0. When no transition object is made the
|
||||
// end function is deleted; otherwise StartTransition hands it over (adopted by the platform with a 0x19 ms delay).
|
||||
//
|
||||
// Strings from the game's __cstring: "window" (@0x0015a504), "onend" (@0x0015a50c), "time" (@0x001589ac),
|
||||
// "center_fadein" (@0x0015a514), "center" (@0x0015a524), "fadein" (@0x0015a52c), "fadeout" (@0x0015a534), "swipe"
|
||||
// (@0x0015a53c), "path" (@0x00159244), "zoomin" (@0x0015a564), "alpha" (@0x0015852c), "startx" (@0x0015a544),
|
||||
// "starty" (@0x0015a54c), "endx" (@0x0015a554), "endy" (@0x0015a55c), "%8x".
|
||||
//
|
||||
// Compiler-generated in the game (no declaration in Transitions.h):
|
||||
// ~BSGTransition D2 game @0x00039232, D1 game @0x0003917e, D0 game @0x00039d8e; ~FadeInTransition D1 game
|
||||
// game @0x00174940, D0 game @0x00174908; ~FadeOutTransition D1 game @0x001748e0, D0 game @0x001748a8;
|
||||
// ~SwipeTransition D1 game @0x00174880, D0 game @0x00174848; ~CurveTransition D1 game @0x00174968 (releases
|
||||
// pCurve), D0 game @0x001747e8; ~ZoomInTransition D1 game @0x001747c0, D0 game @0x00174788; ~TWindowFader D0 game
|
||||
// game @0x00174628 (D1 game @0x00163704 is cited in BSGHelpers.cpp).
|
||||
// Header-inline code emitted out of line: BSGTransition::ApplyTransition (empty) game @0x001745b8.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "Transitions.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGWindow.h"
|
||||
#include "Character.h"
|
||||
#include "sseconv.h"
|
||||
|
||||
#include "pf/image.h"
|
||||
#include "pf/luatable.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/screen.h"
|
||||
#include "pf/text.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x00038da4
|
||||
bool TWindowFader::Process(TWindow* pWindow)
|
||||
{
|
||||
if (pWindow->IsKindOf(TText::ClassId())) {
|
||||
pWindow->GetCast<TText>()->SetAlpha(alpha);
|
||||
} else if (pWindow->IsKindOf(TImage::ClassId())) {
|
||||
pWindow->GetCast<TImage>()->SetAlpha(alpha);
|
||||
} else if (pWindow->IsKindOf(Character::ClassId())) {
|
||||
pWindow->GetCast<Character>()->SetAlpha(alpha);
|
||||
} else if (pWindow->IsKindOf(TBSGWindow::ClassId())) {
|
||||
pWindow->GetCast<TBSGWindow>()->SetAlpha(alpha, false);
|
||||
}
|
||||
|
||||
pWindow->ForEachChild(this, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00038e9e
|
||||
void FadeInTransition::ApplyTransition(void)
|
||||
{
|
||||
TWindowFader fader(t * alpha);
|
||||
fader.Process(pTarget);
|
||||
}
|
||||
|
||||
// game @0x00038ef6
|
||||
void FadeOutTransition::ApplyTransition(void)
|
||||
{
|
||||
TWindowFader fader((1.0f - t) * alpha);
|
||||
fader.Process(pTarget);
|
||||
}
|
||||
|
||||
// game @0x00038f56
|
||||
void CurveTransition::ApplyTransition(void)
|
||||
{
|
||||
TVec2 p = pCurve->GetPoint(t, 0);
|
||||
pTarget->SetWindowPos((int)((double)p.x + 0.5), (int)((double)p.y + 0.5));
|
||||
}
|
||||
|
||||
// game @0x0003911c
|
||||
void SwipeTransition::ApplyTransition(void)
|
||||
{
|
||||
pTarget->SetWindowPos((int)((float)start.mX + (float)(end.mX - start.mX) * t),
|
||||
(int)((float)start.mY + t * (float)(end.mY - start.mY)));
|
||||
}
|
||||
|
||||
// game @0x00039e4a
|
||||
void ZoomInTransition::ApplyTransition(void)
|
||||
{
|
||||
if (pImage) {
|
||||
pImage->SetTexture(pImage->GetTexture(), t);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00038fc4
|
||||
bool BSGTransition::OnMessage(TMessage* message)
|
||||
{
|
||||
if (message->mType == TMessage::kModalClosed) {
|
||||
if (message->mName == name) {
|
||||
if (pLiveFlag.get() && *pLiveFlag) {
|
||||
if (pEndFunction) {
|
||||
pEndFunction->Call();
|
||||
delete pEndFunction;
|
||||
}
|
||||
*pLiveFlag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00039036
|
||||
bool BSGTransition::Animate(void)
|
||||
{
|
||||
if (!pLiveFlag.get() || *pLiveFlag) {
|
||||
BSGShowWindow(pTarget);
|
||||
|
||||
uint32_t elapsed = GetTime() - startTime;
|
||||
if (elapsed < duration) {
|
||||
t = (float)elapsed / (float)duration;
|
||||
} else {
|
||||
t = 1.0f;
|
||||
}
|
||||
|
||||
ApplyTransition();
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
|
||||
if (elapsed < duration) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pEndFunction) {
|
||||
pEndFunction->Call();
|
||||
delete pEndFunction;
|
||||
}
|
||||
if (pLiveFlag.get()) {
|
||||
*pLiveFlag = false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0003917e (D1) / game @0x00039232 (D2) / game @0x00039d8e (D0)
|
||||
BSGTransition::~BSGTransition(void)
|
||||
{
|
||||
TWindowManager::GetInstance()->OrphanMessageListener(this);
|
||||
if (pLiveFlag.get()) {
|
||||
*pLiveFlag = false;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000392e6 (C2)
|
||||
BSGTransition::BSGTransition(TWindow* pWindow, uint32_t duration_, TLuaFunction* pEndFunction_)
|
||||
: TAnimTask(0)
|
||||
{
|
||||
pTarget = pWindow;
|
||||
name = TWindowManager::GetInstance()->GetTopModalWindow()->GetID();
|
||||
pEndFunction = pEndFunction_;
|
||||
duration = duration_;
|
||||
t = 0.0f;
|
||||
TWindowManager::GetInstance()->AdoptMessageListener(this);
|
||||
startTime = GetTime();
|
||||
pLiveFlag = ::shared_ptr<bool>(new bool);
|
||||
*pLiveFlag = true;
|
||||
}
|
||||
|
||||
// game @0x00172014 (FadeInTransition::FadeInTransition)
|
||||
// game @0x00174a14 (FadeOutTransition::FadeOutTransition)
|
||||
// game @0x00174a54 (SwipeTransition::SwipeTransition)
|
||||
// game @0x00174aa8 (CurveTransition::CurveTransition)
|
||||
// game @0x00174b0c (ZoomInTransition::ZoomInTransition)
|
||||
// The five derived constructors are inline in Transitions.h: each calls BSGTransition::BSGTransition (C2) and then
|
||||
// stores its members (alpha at 0x3c; start/end at 0x3c..0x48; pCurve copy at 0x3c; pImage = GetCast<TImage>() at
|
||||
// 0x3c); the game emits them out of line at the addresses above.
|
||||
|
||||
// game @0x0003941e
|
||||
::shared_ptr<bool> StartTransition(BSGTransition* pTransition)
|
||||
{
|
||||
::shared_ptr<bool> result;
|
||||
if (pTransition) {
|
||||
result = pTransition->GetLiveFlag();
|
||||
*result = true;
|
||||
TPlatform::GetInstance()->AdoptTask(pTransition);
|
||||
pTransition->SetDelay(0x19, true, true, false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x000394ee
|
||||
void DoTransition(TLuaTable* pTable)
|
||||
{
|
||||
str windowName = pTable->GetString("window", "");
|
||||
str type = pTable->GetString(1.0, "");
|
||||
|
||||
TWindow* pWindow = TWindowManager::GetInstance()->GetTopModalWindow()->GetChildWindow(windowName, -1);
|
||||
if (pWindow == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
TLuaFunction* pEnd = pTable->GetFunction("onend");
|
||||
uint32_t time = SseDoubleToUInt32(pTable->GetNumber("time", 100.0));
|
||||
BSGTransition* pTransition = 0;
|
||||
|
||||
if (str("center_fadein") == type) {
|
||||
BSGHideWindow(pWindow);
|
||||
SetWindowAlpha(pWindow, 0.0f);
|
||||
float alpha = (float)pTable->GetNumber("alpha", 1.0);
|
||||
pTransition = new FadeInTransition(pWindow, alpha, time, pEnd);
|
||||
int32_t y = pWindow->GetParentRelativeRect().y1;
|
||||
uint32_t w = pWindow->GetParentRelativeRect().GetWidth();
|
||||
pWindow->SetWindowPos((int32_t)((TWindowManager::GetInstance()->GetScreen()->GetWindowWidth() - w) >> 1), y);
|
||||
} else if (str("center") == type) {
|
||||
int32_t y = pWindow->GetParentRelativeRect().y1;
|
||||
uint32_t w = pWindow->GetParentRelativeRect().GetWidth();
|
||||
pWindow->SetWindowPos((int32_t)((TWindowManager::GetInstance()->GetScreen()->GetWindowWidth() - w) >> 1), y);
|
||||
} else if (str("fadein") == type) {
|
||||
float alpha = (float)pTable->GetNumber("alpha", 1.0);
|
||||
pTransition = new FadeInTransition(pWindow, alpha, time, pEnd);
|
||||
SetWindowAlpha(pWindow, 0.0f);
|
||||
} else if (str("fadeout") == type) {
|
||||
float alpha = (float)pTable->GetNumber("alpha", 1.0);
|
||||
pTransition = new FadeOutTransition(pWindow, alpha, time, pEnd);
|
||||
} else if (str("swipe") == type) {
|
||||
int32_t x = pWindow->GetParentRelativeRect().x1;
|
||||
int32_t y = pWindow->GetParentRelativeRect().y1;
|
||||
int32_t startx = SseDoubleToInt32(pTable->GetNumber("startx", (double)x));
|
||||
int32_t starty = SseDoubleToInt32(pTable->GetNumber("starty", (double)y));
|
||||
int32_t endx = SseDoubleToInt32(pTable->GetNumber("endx", (double)x));
|
||||
int32_t endy = SseDoubleToInt32(pTable->GetNumber("endy", (double)y));
|
||||
pTransition = new SwipeTransition(pWindow, TPoint(startx, starty), TPoint(endx, endy), time, pEnd);
|
||||
} else if (str("path") == type) {
|
||||
TCurveRef pCurve;
|
||||
TLuaTable* pPath = pTable->GetTable("path");
|
||||
if (pPath) {
|
||||
pCurve = TCurve::Create(*pPath);
|
||||
delete pPath;
|
||||
}
|
||||
if (pCurve) {
|
||||
pTransition = new CurveTransition(pWindow, pCurve, time, pEnd);
|
||||
}
|
||||
} else if (str("zoomin") == type) {
|
||||
pTransition = new ZoomInTransition(pWindow, time, pEnd);
|
||||
}
|
||||
|
||||
if (pTransition) {
|
||||
StartTransition(pTransition);
|
||||
} else if (pEnd) {
|
||||
delete pEnd;
|
||||
}
|
||||
}
|
||||
344
port/game/cadilite.cpp
Normal file
344
port/game/cadilite.cpp
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
// Port of the game's cadilite.cpp (Chocolatier 3; PlayFirst "CADI-lite" sound event layer adapted by Big Splash
|
||||
// Games): TCadiLite, which reads the event definition file "<data folder>/cadilite.spec", keeps the named sound
|
||||
// events (TLiteSoundEvent, see cadilite_event.cpp) and runs them by name, with a few built-in events
|
||||
// ("<Group> Volume", "Stop <Group>").
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// cadilite.h (port/game/cadilite.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): mDataPath 0x0 (str), mEvents 0x4 (std::map, 0x18 bytes), mTraceFile 0x1c; sizeof 0x20
|
||||
// (CadiInit allocates 0x20). The header matches.
|
||||
//
|
||||
// The game's cadilite.o starts at game @0x0003f368 with the two file-static helpers below (gcc passes their
|
||||
// arguments in registers, which marks them local): snarfGroup and bufferGrabQuotedString.
|
||||
//
|
||||
// Spec file format (loadSpecFile): lines of up to 0x2800 characters; blank lines end an event. A line starting with
|
||||
// ':' at column 0 starts an event (":\"name\"" with the name quoted); inside an event a quoted name calls another
|
||||
// event, "play <volgroup> <file> [loop]" adds a sound (separators " \t,"; "loop" is matched without regard to case)
|
||||
// and "stop <file>" adds a stop. Trailing white space is cut off (never the first character). A problem stops reading
|
||||
// and sets the error text: the pending event is still added (a duplicate definition error of addSoundEvent is not
|
||||
// checked in loadSpecFile), then, when reading went fine, resolveReferences runs. A non-empty error text ends in
|
||||
// WriteDbg("%s", "CADI LITE: Fatal Error in file '<translated path>'.\n\n<error>") and exit(-1).
|
||||
// - procHardcodedEvent splits the event name at spaces, else at '_': "<Group> Volume" sets that group's type volume to
|
||||
// the value, "Stop <Group>" kills all sounds of the group ("all" = every group, -1); unknown groups (getGroupId
|
||||
// without creation gives -1, mapped to -2 by snarfGroup) are not handled and the event is reported as not defined.
|
||||
// - procEvent writes a line to the trace file (if it exists) saying whether the event was defined (with its line),
|
||||
// hardcoded, or ignored. The trace file is created by the constructor when "activate_CADILITE_event_log.txt" exists
|
||||
// in the working directory.
|
||||
//
|
||||
// Strings from the game's __cstring: "cadilite.spec", "/", "Unable to open CADI-lite file. Looking for '%s' under
|
||||
// 'assets'" (@0x0015aba8), "Expecting a quoted event Name on line %d." (@0x0015ac9c), "Volume" (@0x0015aabc),
|
||||
// "Stop" (@0x0015aac4), "all" (@0x00159740), " " (@0x0015aab4), "_" (@0x0015aab8), " \t,", "play", "loop", "stop",
|
||||
// "activate_CADILITE_event_log.txt", "CADILITE_event_log.txt" and the message texts below (verbatim).
|
||||
//
|
||||
// Compiler-generated / template code: the std::map<const str, TLiteSoundEvent*> instantiations (find, operator[],
|
||||
// insert, erase, destructor) at game @0x00175db4 .. @0x00177248 (not ported); ~TCadiLite below is the game's D1
|
||||
// (game @0x0003f622, which closes the trace file and destroys the map and the path).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#define CADIAPI_IMPL
|
||||
|
||||
#include <ctype.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <pf/pflib.h>
|
||||
|
||||
#include "cadilite.h"
|
||||
#include "cadilite_event.h"
|
||||
|
||||
#include "pf/debug.h"
|
||||
#include "pf/file.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/sound.h"
|
||||
#include "pf/soundmanager.h"
|
||||
|
||||
|
||||
// game @0x0003f368 (file-local; registers eax, edx, ecx in the game)
|
||||
static int snarfGroup(char* groupName, const char* eventName, bool allowAll)
|
||||
{
|
||||
if (allowAll && strcasecmp(groupName, "all") == 0) {
|
||||
return -1;
|
||||
}
|
||||
int id = TLiteSoundEvent::getGroupId(str(groupName), false);
|
||||
if (id == -1) {
|
||||
id = -2;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
// game @0x0003f544 (file-local; registers eax, edx in the game)
|
||||
static str bufferGrabQuotedString(char* buffer)
|
||||
{
|
||||
if (*buffer == '"') {
|
||||
char* pEnd = strchr(buffer + 1, '"');
|
||||
if (pEnd != 0) {
|
||||
*pEnd = '\0';
|
||||
return str(buffer + 1);
|
||||
}
|
||||
}
|
||||
return str();
|
||||
}
|
||||
|
||||
// game @0x0003f3dc
|
||||
bool TCadiLite::procHardcodedEvent(const char* eventName, double valueOpt)
|
||||
{
|
||||
char* pCopy = strdup(eventName);
|
||||
char* pToken1 = strtok(pCopy, " ");
|
||||
char* pToken2 = strtok(0, " ");
|
||||
bool handled = false;
|
||||
|
||||
if (pToken1 == 0 || pToken2 == 0) {
|
||||
pToken1 = strtok(pCopy, "_");
|
||||
pToken2 = strtok(0, "_");
|
||||
if (pToken1 == 0 || pToken2 == 0) {
|
||||
free(pCopy);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(pToken2, "Volume") == 0) {
|
||||
int group = snarfGroup(pToken1, eventName, false);
|
||||
if (group >= 0) {
|
||||
TPlatform::GetInstance()->GetSoundManager()->SetTypeVolume(group, (float)valueOpt);
|
||||
handled = true;
|
||||
}
|
||||
} else if (strcmp(pToken1, "Stop") == 0) {
|
||||
int group = snarfGroup(pToken2, eventName, true);
|
||||
if (group > -2) {
|
||||
TPlatform::GetInstance()->GetSoundManager()->KillAllSounds(group);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
free(pCopy);
|
||||
return handled;
|
||||
}
|
||||
|
||||
// game @0x0003f58c
|
||||
str TCadiLite::resolveReferences()
|
||||
{
|
||||
str result;
|
||||
for (tSoundEventMap::iterator it = mEvents.begin(); it != mEvents.end(); ++it) {
|
||||
result += it->second->resolveReferences(&mEvents);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x0003f622 (D1)
|
||||
TCadiLite::~TCadiLite()
|
||||
{
|
||||
if (mTraceFile != 0) {
|
||||
fclose(mTraceFile);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003f67a
|
||||
void TCadiLite::procEvent(const char* eventName, double valueOpt)
|
||||
{
|
||||
tSoundEventMap::iterator it = mEvents.find(str(eventName));
|
||||
if (it == mEvents.end()) {
|
||||
if (!procHardcodedEvent(eventName, valueOpt)) {
|
||||
if (mTraceFile == 0) {
|
||||
return;
|
||||
}
|
||||
fprintf(mTraceFile, "IGNORE EVENT '%s': Not Defined\n", eventName);
|
||||
} else {
|
||||
if (mTraceFile == 0) {
|
||||
return;
|
||||
}
|
||||
fprintf(mTraceFile, "PLAY EVENT '%s': Hardcoded Event\n", eventName);
|
||||
}
|
||||
} else {
|
||||
if (mTraceFile != 0) {
|
||||
fprintf(mTraceFile, "PLAY EVENT '%s': Defined on line %d\n", eventName, it->second->getLine());
|
||||
}
|
||||
it->second->procEvent();
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003f76a
|
||||
str TCadiLite::addSoundEvent(TLiteSoundEvent* event)
|
||||
{
|
||||
tSoundEventMap::iterator it = mEvents.find(event->getName());
|
||||
if (it == mEvents.end()) {
|
||||
mEvents[event->getName()] = event;
|
||||
return str();
|
||||
}
|
||||
|
||||
int otherLine = it->second->getLine();
|
||||
str otherName(it->second->getName());
|
||||
int newLine = event->getLine();
|
||||
str newName(event->getName());
|
||||
return str::getFormatted("Duplicate sound event definition for '%s' on line %d. Other definition for '%s' is on line %d.",
|
||||
newName.c_str(), newLine, otherName.c_str(), otherLine);
|
||||
}
|
||||
|
||||
// game @0x0003f8aa
|
||||
void TCadiLite::loadSpecFile()
|
||||
{
|
||||
str errorMsg;
|
||||
str fullPath = mDataPath + str("/") + str("cadilite.spec");
|
||||
|
||||
TFile* pFile = pf_open(fullPath.c_str(), kReadText);
|
||||
if (pFile == 0) {
|
||||
errorMsg.format("Unable to open CADI-lite file. Looking for '%s' under 'assets'", fullPath.c_str());
|
||||
} else {
|
||||
int lineNumber = 0;
|
||||
TLiteSoundEvent* pEvent = 0;
|
||||
char line[0x2800];
|
||||
|
||||
while (pf_gets(pFile, line, 0x2800) != 0) {
|
||||
lineNumber++;
|
||||
|
||||
bool blank = true;
|
||||
for (char* p = line; *p != '\0'; p++) {
|
||||
if (!isspace((int)*p)) {
|
||||
blank = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (blank) {
|
||||
if (pEvent != 0) {
|
||||
addSoundEvent(pEvent);
|
||||
pEvent = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// cut trailing white space (the first character is never examined)
|
||||
int length = (int)strlen(line);
|
||||
for (int i = length - 1; i >= 1; i--) {
|
||||
if (!isspace((int)line[i])) {
|
||||
break;
|
||||
}
|
||||
line[i] = '\0';
|
||||
}
|
||||
|
||||
if (line[0] == ':') {
|
||||
if (pEvent == 0) {
|
||||
str name = bufferGrabQuotedString(line + 1);
|
||||
if (name.length() == 0) {
|
||||
errorMsg.format("Expecting a quoted event Name on line %d.", lineNumber);
|
||||
break;
|
||||
}
|
||||
pEvent = new TLiteSoundEvent(str(name), lineNumber);
|
||||
continue;
|
||||
}
|
||||
str eventName(pEvent->getName());
|
||||
errorMsg.format("Events should be seperated by at leas one blank line, but you have a line starting with ':' (which defines new events), while still processcing working on event '%s' on line %d.",
|
||||
eventName.c_str(), lineNumber);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pEvent == 0) {
|
||||
errorMsg.format("Expecting an event definition ':\"<event Name>\" at this point on line %d.", lineNumber);
|
||||
break;
|
||||
}
|
||||
|
||||
if (line[0] == '"') {
|
||||
str name = bufferGrabQuotedString(line);
|
||||
if (name.length() == 0) {
|
||||
str eventName(pEvent->getName());
|
||||
errorMsg.format("Expecting a quoted event Name on line %d -- to add to event '%s'.", lineNumber,
|
||||
eventName.c_str());
|
||||
break;
|
||||
}
|
||||
pEvent->addCallEntry(str(name), lineNumber);
|
||||
continue;
|
||||
}
|
||||
|
||||
char* pDirective = strtok(line, " \t,");
|
||||
if (strcmp(pDirective, "play") == 0) {
|
||||
char* pGroup = strtok(0, " \t,");
|
||||
char* pSoundFile = strtok(0, " \t,");
|
||||
char* pLoop = strtok(0, " \t,");
|
||||
char* pExtra = strtok(0, " \t,");
|
||||
if (pGroup == 0 || pSoundFile == 0) {
|
||||
str eventName(pEvent->getName());
|
||||
errorMsg.format("Expecting %s on line %d -- to add to event '%s'.",
|
||||
"'play <volgroup> <soundfile.ogg> [<loop>]'", lineNumber, eventName.c_str());
|
||||
break;
|
||||
}
|
||||
if (pExtra != 0) {
|
||||
str eventName(pEvent->getName());
|
||||
errorMsg.format("Unexpected word '%s'. Expecting %s on line %d -- to add to event '%s'.", pExtra,
|
||||
"'play <volgroup> <soundfile.ogg> [<loop>]'", lineNumber, eventName.c_str());
|
||||
break;
|
||||
}
|
||||
if (pLoop != 0) {
|
||||
if (strcasecmp(pLoop, "loop") != 0) {
|
||||
str eventName(pEvent->getName());
|
||||
errorMsg.format("Unexpected word '%s'. Expecting %s on line %d -- to add to event '%s'.",
|
||||
pLoop, "'play <volgroup> <soundfile.ogg> [<loop>]'", lineNumber,
|
||||
eventName.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool looping = (pLoop != 0);
|
||||
pEvent->addPlayEntry(str(mDataPath), str(pGroup), str(pSoundFile), looping, lineNumber);
|
||||
} else if (strcmp(pDirective, "stop") == 0) {
|
||||
char* pSoundFile = strtok(0, " \t,");
|
||||
char* pExtra = strtok(0, " \t,");
|
||||
if (pSoundFile == 0) {
|
||||
str eventName(pEvent->getName());
|
||||
errorMsg.format("Expecting %s on line %d -- to add to event '%s'.", "'stop <soundfile.ogg>'",
|
||||
lineNumber, eventName.c_str());
|
||||
break;
|
||||
}
|
||||
if (pExtra != 0) {
|
||||
str eventName(pEvent->getName());
|
||||
errorMsg.format("Unexpected word '%s'. Expecting %s on line %d -- to add to event '%s'.", pExtra,
|
||||
"'stop <soundfile.ogg>'", lineNumber, eventName.c_str());
|
||||
break;
|
||||
}
|
||||
pEvent->addStopEntry(str(pSoundFile), lineNumber);
|
||||
} else {
|
||||
str eventName(pEvent->getName());
|
||||
errorMsg.format("Unexpected Event entry directive '%s' on line %d -- to add to event '%s'.",
|
||||
pDirective, lineNumber, eventName.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pEvent != 0) {
|
||||
addSoundEvent(pEvent);
|
||||
}
|
||||
pf_close(pFile);
|
||||
}
|
||||
|
||||
if (errorMsg.length() == 0) {
|
||||
errorMsg = resolveReferences();
|
||||
}
|
||||
|
||||
if (errorMsg.length() != 0) {
|
||||
str translated = TFile::TranslateResource(str(fullPath), false);
|
||||
if (translated.length() == 0) {
|
||||
translated.format("<file not found: '%s'>", fullPath.c_str());
|
||||
}
|
||||
str message = str::getFormatted("CADI LITE: Fatal Error in file '%s'.\n\n%s", translated.c_str(),
|
||||
errorMsg.c_str());
|
||||
WriteDbg("%s", message.c_str());
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00040252
|
||||
TCadiLite::TCadiLite(const char* cadiDataPath)
|
||||
: mDataPath(cadiDataPath)
|
||||
{
|
||||
mTraceFile = 0;
|
||||
loadSpecFile();
|
||||
if (access("activate_CADILITE_event_log.txt", 0) != -1) {
|
||||
mTraceFile = fopen("CADILITE_event_log.txt", "w");
|
||||
if (mTraceFile == 0) {
|
||||
str message = str::getFormatted("unable to create file: %s -- but %s exists.", "CADILITE_event_log.txt",
|
||||
"activate_CADILITE_event_log.txt");
|
||||
WriteDbg("%s", message.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
248
port/game/cadilite_event.cpp
Normal file
248
port/game/cadilite_event.cpp
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
// Port of the game's cadilite_event.cpp (Chocolatier 3; PlayFirst "CADI-lite" sound event layer adapted by Big Splash
|
||||
// Games): TLiteSoundEvent, a named list of sound entries (play / stop / call another event) with the static volume
|
||||
// group and stop-sound tables, the file-private TLiteSoundEventEntry, and the CadiInit / CadiShutdown / CadiEvent API
|
||||
// (CadiApi.h) on top of the TCadiLite singleton.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// cadilite_event.h, cadilite.h and CadiApi.h (port/game, unchanged).
|
||||
//
|
||||
// Object order: the game's cadilite_event.o spans game @0x0003e9a0 (CadiInit) .. game @0x0003f366 (end of
|
||||
// TLiteSoundEvent::procEvent); the static helper snarfGroup (game @0x0003f368) belongs to cadilite.o (its first
|
||||
// function; see cadilite.cpp), as does bufferGrabQuotedString. The old choc3/cpp_src map put snarfGroup here.
|
||||
//
|
||||
// Layout (game, i386): TLiteSoundEvent: mEventName 0x0, mLine 0x4, mEntries 0x8 (std::list); sizeof 0x10 (loadSpecFile
|
||||
// allocates 0x10). TLiteSoundEventEntry (not in any header; defined here, the member and enumerator names are the
|
||||
// port's, the layout and the three operation numbers are from the game): mOperation 0x0 (1 play, 2 stop, 3 call),
|
||||
// mFile 0x4 (str), mLooping 0x8 (bool), mVolGroup 0xc (str), mEventName 0x10 (str), mLine 0x14, mCalledEvent 0x18,
|
||||
// mSound 0x1c (shared_ptr, count 0x20); sizeof 0x24 (the three add*Entry functions allocate 0x24).
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - getGroupId: volume group names map to type ids; a new name gets (current table size + 1000) when createNew is set,
|
||||
// else -1 is returned for an unknown group.
|
||||
// - addPlayEntry loads the sound as "<dataPath>/<file>" in memory with the group's type, and adds it to the stop table
|
||||
// (addToStopMap skips a sound that is already in the list for that file name). addStopEntry / addCallEntry just
|
||||
// record the file name / the called event's name.
|
||||
// - resolveReferences returns the text of every problem found: calls to events that do not exist or are defined later
|
||||
// in the file (an event may only call one defined before it), play entries whose sound failed to load, and stop
|
||||
// entries naming a sound no play entry has registered. Called events are bound by pointer on the way.
|
||||
// - procEvent runs the entries in order: play (TSound::Play with the loop flag), stop (Kill every sound registered
|
||||
// under the file name), call (run the bound event).
|
||||
// - CadiInit registers the volume groups "Sfx", "Music" and "Environments" (in that order, so ids 1000, 1001, 1002)
|
||||
// and creates the TCadiLite on the data folder "cadi" (the arguments of the declaration are not used); CadiEvent
|
||||
// forwards to it while it exists.
|
||||
//
|
||||
// Strings from the game's __cstring: "Sfx", "Music", "Environments", "cadi" and the resolveReferences messages.
|
||||
//
|
||||
// Static data: TLiteSoundEvent::mSoundGroup (game @0x0021fab8) and mStopMap (game @0x0021faa0), file-local gCadi.
|
||||
// Static initializer: __static_initialization_and_destruction_0 game @0x001abbde constructs both maps and
|
||||
// registers their destructors (___tcf_0, ___tcf_1 game @0x0003eafc destroys mStopMap); __GLOBAL__I game @0x001abc46
|
||||
// jumps to it.
|
||||
//
|
||||
// Header-inline code emitted out of line: TLiteSoundEvent::TLiteSoundEvent(str, int) game @0x00177080 (copies the name,
|
||||
// stores the line, default-constructs the entry list); TLiteSoundEventEntry::TLiteSoundEventEntry(tOperation, int)
|
||||
// game @0x00176740 (defined in the class below). TLiteSoundEvent::~TLiteSoundEvent is declared but has no code in the
|
||||
// game (nothing deletes an event).
|
||||
//
|
||||
// Compiler-generated / template code emitted out of line (std::map / std::list / boost instantiations, not ported):
|
||||
// _Rb_tree / list / pair members for the three container types, all under 0x00175dxx .. 0x00177248.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#define CADIAPI_IMPL
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <pf/pflib.h>
|
||||
|
||||
#include "CadiApi.h"
|
||||
#include "cadilite.h"
|
||||
#include "cadilite_event.h"
|
||||
|
||||
#include "pf/sound.h"
|
||||
#include "pf/soundmanager.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// One entry of an event: play a sound, stop sounds, or call another event
|
||||
|
||||
class TLiteSoundEventEntry
|
||||
{
|
||||
public:
|
||||
enum tOperation { ePlay = 1, eStop = 2, eCall = 3 };
|
||||
|
||||
// game @0x00176740
|
||||
TLiteSoundEventEntry(tOperation operation, int line)
|
||||
: mOperation(operation), mLooping(false), mEventName((const char*)0), mLine(line), mCalledEvent(0) {}
|
||||
|
||||
tOperation mOperation;
|
||||
str mFile;
|
||||
bool mLooping;
|
||||
str mVolGroup;
|
||||
str mEventName;
|
||||
int mLine;
|
||||
TLiteSoundEvent* mCalledEvent;
|
||||
TSoundRef mSound;
|
||||
};
|
||||
|
||||
// game @0x0021fab8 / game @0x0021faa0
|
||||
TLiteSoundGroup TLiteSoundEvent::mSoundGroup;
|
||||
TLiteSoundStopMap TLiteSoundEvent::mStopMap;
|
||||
|
||||
static TCadiLite* gCadi = 0;
|
||||
|
||||
|
||||
// game @0x0003e9a0
|
||||
void CadiInit(const char* fullDataFolderPath, void* hWnd)
|
||||
{
|
||||
if (gCadi == 0) {
|
||||
TLiteSoundEvent::getGroupId(str("Sfx"), true);
|
||||
TLiteSoundEvent::getGroupId(str("Music"), true);
|
||||
TLiteSoundEvent::getGroupId(str("Environments"), true);
|
||||
gCadi = new TCadiLite("cadi");
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003ea8c
|
||||
void CadiShutdown()
|
||||
{
|
||||
TCadiLite* pCadi = gCadi;
|
||||
if (gCadi != 0) {
|
||||
delete pCadi;
|
||||
gCadi = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003eabe
|
||||
void CadiEvent(const char* szEventName, double optional)
|
||||
{
|
||||
if (gCadi != 0) {
|
||||
gCadi->procEvent(szEventName, optional);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0003eb0c
|
||||
int TLiteSoundEvent::getGroupId(str groupName, bool createNew)
|
||||
{
|
||||
TLiteSoundGroup::iterator it = mSoundGroup.find(groupName);
|
||||
if (it == mSoundGroup.end()) {
|
||||
if (!createNew) {
|
||||
return -1;
|
||||
}
|
||||
int id = (int)mSoundGroup.size() + 1000;
|
||||
mSoundGroup[groupName] = id;
|
||||
return id;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// game @0x0003eb6a
|
||||
void TLiteSoundEvent::addStopEntry(str file, int line)
|
||||
{
|
||||
TLiteSoundEventEntry* pEntry = new TLiteSoundEventEntry(TLiteSoundEventEntry::eStop, line);
|
||||
pEntry->mFile = file;
|
||||
mEntries.push_back(pEntry);
|
||||
}
|
||||
|
||||
// game @0x0003ebdc
|
||||
void TLiteSoundEvent::addCallEntry(str eventName, int line)
|
||||
{
|
||||
TLiteSoundEventEntry* pEntry = new TLiteSoundEventEntry(TLiteSoundEventEntry::eCall, line);
|
||||
pEntry->mEventName = eventName;
|
||||
mEntries.push_back(pEntry);
|
||||
}
|
||||
|
||||
// game @0x0003ec4e
|
||||
str TLiteSoundEvent::resolveReferences(tSoundEventMap* library)
|
||||
{
|
||||
str result;
|
||||
|
||||
for (std::list<TLiteSoundEventEntry*>::iterator it = mEntries.begin(); it != mEntries.end(); ++it) {
|
||||
TLiteSoundEventEntry* pEntry = *it;
|
||||
if (pEntry->mOperation == TLiteSoundEventEntry::eCall) {
|
||||
tSoundEventMap::iterator found = library->find(pEntry->mEventName);
|
||||
if (found == library->end()) {
|
||||
result += str::getFormatted("Event definition '%s' calls to another event '%s' on line %d. But event '%s' is not defined anyhere. Is the spelling correct?\n\n",
|
||||
str(mEventName).c_str(), pEntry->mEventName.c_str(), pEntry->mLine,
|
||||
pEntry->mEventName.c_str());
|
||||
} else {
|
||||
TLiteSoundEvent* pTarget = found->second;
|
||||
if (pTarget->mLine <= pEntry->mLine) {
|
||||
pEntry->mCalledEvent = pTarget;
|
||||
} else {
|
||||
result += str::getFormatted("Event definition '%s' calls to another event '%s' on line %d.But event '%s' is defined later in the file (on line %d), which is not valid (to avoid ciruclar references). Please make sure that event '%s' precedes all references to it.\n\n",
|
||||
str(mEventName).c_str(), pEntry->mEventName.c_str(), pEntry->mLine,
|
||||
pEntry->mEventName.c_str(), pTarget->mLine, pEntry->mEventName.c_str());
|
||||
}
|
||||
}
|
||||
} else if (pEntry->mOperation == TLiteSoundEventEntry::ePlay && pEntry->mSound.get() == 0) {
|
||||
result += str::getFormatted("Event definition '%s' refers to sound '%s' on line %d. But sound '%s' fails to load. Is the spelling correct?\n\n",
|
||||
str(mEventName).c_str(), pEntry->mFile.c_str(), pEntry->mLine,
|
||||
pEntry->mFile.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
for (std::list<TLiteSoundEventEntry*>::iterator it = mEntries.begin(); it != mEntries.end(); ++it) {
|
||||
TLiteSoundEventEntry* pEntry = *it;
|
||||
if (pEntry->mOperation == TLiteSoundEventEntry::eStop) {
|
||||
if (mStopMap[pEntry->mFile].size() == 0) {
|
||||
result += str::getFormatted("Event definition '%s' refers to sound '%s' on line %d. But sound '%s' doesn't appear to be defined as a playable sound. Is the spelling correct?\n\n",
|
||||
str(mEventName).c_str(), pEntry->mFile.c_str(), pEntry->mLine,
|
||||
pEntry->mFile.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x0003eff6
|
||||
bool TLiteSoundEvent::addToStopMap(str sound, TSoundRef ref)
|
||||
{
|
||||
TLiteSoundRefList::iterator it = mStopMap[sound].begin();
|
||||
while (true) {
|
||||
if (it == mStopMap[sound].end()) {
|
||||
mStopMap[sound].push_back(ref);
|
||||
return true;
|
||||
}
|
||||
if (*it == ref) {
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0003f070
|
||||
void TLiteSoundEvent::addPlayEntry(str dataPath, str volGrp, str file, bool looping, int line)
|
||||
{
|
||||
TLiteSoundEventEntry* pEntry = new TLiteSoundEventEntry(TLiteSoundEventEntry::ePlay, line);
|
||||
pEntry->mFile = file;
|
||||
pEntry->mVolGroup = volGrp;
|
||||
pEntry->mLooping = looping;
|
||||
mEntries.push_back(pEntry);
|
||||
|
||||
int groupId = getGroupId(str(pEntry->mVolGroup), true);
|
||||
pEntry->mSound = TSound::Get(dataPath + str("/") + pEntry->mFile, true, groupId);
|
||||
addToStopMap(str(pEntry->mFile), pEntry->mSound);
|
||||
}
|
||||
|
||||
// game @0x0003f2ae
|
||||
void TLiteSoundEvent::procEvent()
|
||||
{
|
||||
for (std::list<TLiteSoundEventEntry*>::iterator it = mEntries.begin(); it != mEntries.end(); ++it) {
|
||||
TLiteSoundEventEntry* pEntry = *it;
|
||||
if (pEntry->mOperation == TLiteSoundEventEntry::eCall) {
|
||||
if (pEntry->mCalledEvent != 0) {
|
||||
pEntry->mCalledEvent->procEvent();
|
||||
}
|
||||
} else if (pEntry->mOperation == TLiteSoundEventEntry::ePlay) {
|
||||
pEntry->mSound->Play(pEntry->mLooping);
|
||||
} else if (pEntry->mOperation == TLiteSoundEventEntry::eStop) {
|
||||
TLiteSoundRefList::iterator s = mStopMap[pEntry->mFile].begin();
|
||||
while (s != mStopMap[pEntry->mFile].end()) {
|
||||
(*s)->Kill();
|
||||
++s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
160
port/game/chocothree.cpp
Normal file
160
port/game/chocothree.cpp
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
// Port of the game's chocothree.cpp (Chocolatier 3, Big Splash Games): ChocoThreeMain, the game's main after the
|
||||
// Playground setup in main.cpp: string table and content manager, Lua globals and helpers, the game's window
|
||||
// types, cursor, sound, ui/mainloop.lua and the event loop (close asks the script, activation pauses the
|
||||
// animated windows and the sound, full-screen toggles update the settings); at the end the script saves the
|
||||
// player.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// chocothree.h (port/game/chocothree.h, unchanged).
|
||||
//
|
||||
// The Lua globals are the binary's constants: kScreenWidth 800.0, kScreenHeight 600.0, kGameWidth 800.0,
|
||||
// kGameHeight 600.0, kGameScale 1.0 (chocothree.h's SCREEN_* / GAME_* values).
|
||||
//
|
||||
// SlotMachine has no shipped header (choc3/cpp_src/SlotMachine.cpp: "no matching header"); only its ClassId is
|
||||
// declared here.
|
||||
//
|
||||
// Header-inline code emitted out of line: lua_pushdirectclosure<void (*)(str, float)> is shared with
|
||||
// BSGHelpers.o (game @0x00163890); lua_pushdirectclosure<void (*)()> game @0x00169888 and <void (*)(TLuaTable*)>
|
||||
// game @0x001698c8, with LPCD::DirectCallFunctionDispatchHelper<void (*)()> game @0x0016998c and
|
||||
// <void (*)(TLuaTable*)> game @0x00169954 (its ReturnSpecialization<void>::Call<TLuaTable*> game @0x00169908),
|
||||
// are instantiated by a later object (CoffeeFactory.o's coalesced range).
|
||||
//
|
||||
// Strings from the game's __cstring: "kScreenWidth", "kScreenHeight", "kGameWidth", "kGameHeight", "kGameScale",
|
||||
// "", "ver ", "gVersionString", "SetMood", "GrabLedger", "ReleaseLedger", "Transition", the window type names
|
||||
// "BitmapTint" .. "HiscoreWindow", "cursor/cursor", "ui/mainloop.lua", "AskQuit()",
|
||||
// "if Player then Player:SaveGame() end". No static data.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "chocothree.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "BSGSound.h"
|
||||
#include "BSGStringTable.h"
|
||||
#include "BitmapTint.h"
|
||||
#include "BonusGame.h"
|
||||
#include "Character.h"
|
||||
#include "ChocolateFactory.h"
|
||||
#include "CoffeeFactory.h"
|
||||
#include "CurveEditor.h"
|
||||
#include "DookieDropper.h"
|
||||
#include "Fireworks.h"
|
||||
#include "LedgerWindow.h"
|
||||
#include "MapWindow.h"
|
||||
#include "PortWindow.h"
|
||||
#include "RecipeCreator.h"
|
||||
#include "RecipeDesigner.h"
|
||||
#include "Rectangle.h"
|
||||
#include "Rollover.h"
|
||||
#include "SignEditor.h"
|
||||
#include "TightText.h"
|
||||
#include "Transitions.h"
|
||||
#include "credits.h"
|
||||
#include "hiscore.h"
|
||||
#include "options.h"
|
||||
#include "serversubmit.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "pf/event.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
// No shipped header: the class is defined in SlotMachine.cpp (PFTYPEDEF_DC, ClassId game @0x00039eb8).
|
||||
class SlotMachine
|
||||
{
|
||||
public:
|
||||
static PFClassId ClassId();
|
||||
};
|
||||
|
||||
// game @0x0001001c
|
||||
void ChocoThreeMain(void)
|
||||
{
|
||||
BSGStringTable stringTable;
|
||||
Content::Initialize();
|
||||
|
||||
TPlatform* platform = TPlatform::GetInstance();
|
||||
TWindowManager* windowManager = TWindowManager::GetInstance();
|
||||
TScript* script = windowManager->GetScript();
|
||||
|
||||
RegisterBSGLuaHelpers();
|
||||
script->SetGlobalNumber("kScreenWidth", SCREEN_WIDTH);
|
||||
script->SetGlobalNumber("kScreenHeight", SCREEN_HEIGHT);
|
||||
script->SetGlobalNumber("kGameWidth", GAME_WIDTH);
|
||||
script->SetGlobalNumber("kGameHeight", GAME_HEIGHT);
|
||||
script->SetGlobalNumber("kGameScale", 1.0);
|
||||
|
||||
str versionString = str("ver ") + TPlatform::GetInstance()->GetConfig(TPlatform::kGameVersion, "");
|
||||
TWindowManager::GetInstance()->GetScript()->SetGlobalString("gVersionString", versionString);
|
||||
|
||||
ScriptRegisterDirect(script, "SetMood", Character::SetCharacterMood);
|
||||
ScriptRegisterDirect(script, "GrabLedger", LedgerWindow::Grab);
|
||||
ScriptRegisterDirect(script, "ReleaseLedger", LedgerWindow::Release);
|
||||
ScriptRegisterDirect(script, "Transition", DoTransition);
|
||||
|
||||
windowManager->AddWindowType("BitmapTint", TBitmapTint::ClassId());
|
||||
windowManager->AddWindowType("BSGWindow", TBSGWindow::ClassId());
|
||||
windowManager->AddWindowType("CharWindow", Character::ClassId());
|
||||
windowManager->AddWindowType("ChocolateFactory", ChocolateFactory::ClassId());
|
||||
windowManager->AddWindowType("CoffeeFactory", CoffeeFactory::ClassId());
|
||||
windowManager->AddWindowType("CratesGame", TBonusGame::ClassId());
|
||||
windowManager->AddWindowType("CreditsWindow", TCredits::ClassId());
|
||||
windowManager->AddWindowType("CurveEditor", TCurveEditor::ClassId());
|
||||
windowManager->AddWindowType("DookieDropper", DookieDropper::ClassId());
|
||||
windowManager->AddWindowType("FireworksWindow", TFireworksWindow::ClassId());
|
||||
windowManager->AddWindowType("MapWindow", MapWindow::ClassId());
|
||||
windowManager->AddWindowType("PortWindow", PortWindow::ClassId());
|
||||
windowManager->AddWindowType("RecipeCreator", RecipeCreator::ClassId());
|
||||
windowManager->AddWindowType("RecipeDesigner", RecipeDesigner::ClassId());
|
||||
windowManager->AddWindowType("Rectangle", TRectangle::ClassId());
|
||||
windowManager->AddWindowType("Rollover", Rollover::ClassId());
|
||||
windowManager->AddWindowType("SignEditor", SignEditor::ClassId());
|
||||
windowManager->AddWindowType("SlotMachine", SlotMachine::ClassId());
|
||||
windowManager->AddWindowType("TightText", TTightText::ClassId());
|
||||
windowManager->AddWindowType("OptionsWindow", TOptions::ClassId());
|
||||
windowManager->AddWindowType("HiscoreWindow", THiscore::ClassId());
|
||||
TServerSubmit::Register();
|
||||
|
||||
platform->SetCursor(Content::GetInstance()->LoadCursor("cursor/cursor"), TPoint(1, 1), false);
|
||||
|
||||
BSGSoundInit();
|
||||
TSettings::GetInstance()->SetSoundForCurrentUser();
|
||||
|
||||
windowManager->GetScript()->RunScript("ui/mainloop.lua");
|
||||
|
||||
TEvent event;
|
||||
for (;;)
|
||||
{
|
||||
platform->GetEvent(&event);
|
||||
if (event.mType == TEvent::kQuit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (event.mType == TEvent::kClose)
|
||||
{
|
||||
TWindowManager::GetInstance()->GetScript()->DoLuaString("AskQuit()", -1, 0);
|
||||
}
|
||||
else if (event.mType == TEvent::kActivate)
|
||||
{
|
||||
MapWindow::ToggleForeground();
|
||||
PortWindow::ToggleForeground();
|
||||
LedgerWindow::ToggleForeground();
|
||||
ChocolateFactory::ToggleForeground();
|
||||
CoffeeFactory::ToggleForeground();
|
||||
if (event.mKey == 0)
|
||||
{
|
||||
BSGSoundDeactivate();
|
||||
}
|
||||
else
|
||||
{
|
||||
BSGSoundActivate();
|
||||
}
|
||||
}
|
||||
else if (event.mType == TEvent::kFullScreenToggle)
|
||||
{
|
||||
TSettings::GetInstance()->UpdateFullScreen();
|
||||
}
|
||||
TPlatform::GetInstance()->GetWindowManager()->HandleEvent(&event);
|
||||
}
|
||||
|
||||
BSGSoundShutdown();
|
||||
platform->GetWindowManager()->GetScript()->DoLuaString("if Player then Player:SaveGame() end", -1, 0);
|
||||
}
|
||||
228
port/game/credits.cpp
Normal file
228
port/game/credits.cpp
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
// Port of the game's credits.cpp (Chocolatier 3, Big Splash Games): TCredits, the end-credits window. Init reads a
|
||||
// credits text file and builds the three scrolling text columns; Draw scrolls them through the window.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// credits.h (port/game/credits.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TWindow 0x30; mText1 0x30, mText2 0x34, mText3 0x38, mStart 0x3c, mHeight 0x40, mFont 0x44,
|
||||
// mFontSize 0x48, mColumnGap 0x4c, mCreditsTime 0x50, mCreditsIntroPause 0x54, mColumnWidth 0x58, mFontColor 0x5c,
|
||||
// mHeaderColorHex 0x6c, mCreditsFile 0x70; sizeof 0x74 (TCreditsDynamicCreate allocates 0x74). The header matches.
|
||||
// The constructor leaves mHeight and mFontSize uninitialized; Init sets both.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - Init opens mCreditsFile with pf_open(kReadText) and reads it with pf_gets(..., 1024). Every line drops its last
|
||||
// character (the newline) and is split at the first '|'. A line without a pipe is a full-width text line: columns
|
||||
// 1 and 2 get a blank line and column 3 gets the line. A line with a pipe is a two-column row: the left half goes
|
||||
// to column 1, the right half to column 2, and column 3 gets a blank line.
|
||||
// - CreditLine strips trailing spaces/tabs, skips leading whitespace, and expands "[...]" into
|
||||
// "<font color='" + color + "'>" ... "</font>". It has no bounds checks: an empty line reads one byte before the
|
||||
// buffer, and after leading whitespace the right-trimmed length is not adjusted, so the scan can read past the
|
||||
// terminator. Kept as-is (a latent game bug).
|
||||
// - Each column is one TTextGraphic over the text repeated twice ("col + col") so the scroll wraps around. Draw
|
||||
// sets SetStartLine(f / mFontSize) where f = ((pos % mCreditsTime) * mHeight) / mCreditsTime; mHeight is half the
|
||||
// measured bounds height of column 1 (GetTextBounds, y2 / 2 = the height of one copy of the doubled text), and
|
||||
// pos is 0 for the first mCreditsIntroPause ms and then the time since mStart (set on the first Draw).
|
||||
// - The three draw rectangles are built from the window rect via GetWindowWidth / GetWindowHeight (unsigned):
|
||||
// column 1 {gap, -fontSize, width/2 - gap/2, height + 2*fontSize}, column 2 {width/2 + gap/2, ..., width - gap,
|
||||
// ...}, column 3 {gap, ..., width - gap, ...}. Draw first calls GetWindowRect(&rect) but never reads the result.
|
||||
//
|
||||
// Strings from the game's __cstring: "time" (@0x001589ac), "intropause" (@0x00159088), "columngap" (@0x00159094),
|
||||
// "columnwidth" (@0x001590a0), "font" (@0x001590ac), "fontsize" (@0x001590b4), "fontcolor" (@0x001590c0),
|
||||
// "headercolor" (@0x001590cc), "%02x%02x%02x%02x" (@0x001590d8), "file" (@0x00158fcc), "" (@0x001581bc),
|
||||
// "'>" (@0x0015905c), "<font color='" (@0x00159060), "</font>" (@0x00159070), "\n" (@0x00159078),
|
||||
// "TCredits" (@0x0015907c).
|
||||
//
|
||||
// Compiler-generated in the game:
|
||||
// - PFTYPEDEF_DC IsKindOf: game @0x0016cec8 (compares the id against &TCreditsDynamicCreate, else calls
|
||||
// TWindow::ClassId and compares).
|
||||
// - The destructor's vtable reset, str member destruction and TWindow::~TWindow call are compiler-generated from
|
||||
// the destructor body (visible in D1/D0, cited below).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "credits.h"
|
||||
|
||||
#include "pf/file.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/rect.h"
|
||||
#include "pf/renderer.h"
|
||||
#include "pf/textgraphic.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// game @0x0001b1f2 (TCreditsDynamicCreate: new TCredits, sizeof 0x74)
|
||||
// game @0x0001af18 (ClassId: returns &TCreditsDynamicCreate)
|
||||
// game @0x0001b12c (GetTypeName, "TCredits")
|
||||
PFTYPEIMPL_DC(TCredits);
|
||||
|
||||
// game @0x0001af22
|
||||
static str CreditLine(char* line, str color)
|
||||
{
|
||||
int len = strlen(line);
|
||||
|
||||
while (line[len - 1] == ' ' || line[len - 1] == '\t')
|
||||
{
|
||||
line[--len] = '\0';
|
||||
}
|
||||
while (*line == ' ' || *line == '\t')
|
||||
{
|
||||
line++;
|
||||
}
|
||||
|
||||
str result;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
char c = line[i];
|
||||
if (c == '[')
|
||||
{
|
||||
result += str("<font color='") + color + str("'>");
|
||||
}
|
||||
else if (c == ']')
|
||||
{
|
||||
result += "</font>";
|
||||
}
|
||||
else
|
||||
{
|
||||
char one[2];
|
||||
one[0] = c;
|
||||
one[1] = '\0';
|
||||
result += one;
|
||||
}
|
||||
}
|
||||
result += "\n";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x0001b136
|
||||
TCredits::TCredits()
|
||||
{
|
||||
mText1 = NULL;
|
||||
mText2 = NULL;
|
||||
mText3 = NULL;
|
||||
mStart = 0;
|
||||
mColumnGap = 0;
|
||||
mCreditsTime = 0;
|
||||
mCreditsIntroPause = 0;
|
||||
mColumnWidth = 0;
|
||||
}
|
||||
|
||||
// game @0x0001b230 (D1) / game @0x0001b2d6 (D0)
|
||||
TCredits::~TCredits()
|
||||
{
|
||||
mText1->Destroy();
|
||||
mText2->Destroy();
|
||||
mText3->Destroy();
|
||||
}
|
||||
|
||||
// game @0x0001b384
|
||||
bool TCredits::OnTaskAnimate()
|
||||
{
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x0001b39e
|
||||
void TCredits::Init(TWindowStyle& style)
|
||||
{
|
||||
TWindow::Init(style);
|
||||
|
||||
mCreditsTime = style.GetInt("time");
|
||||
mCreditsIntroPause = style.GetInt("intropause");
|
||||
mColumnGap = style.GetInt("columngap");
|
||||
mColumnWidth = style.GetInt("columnwidth");
|
||||
mFont = style.GetString("font");
|
||||
mFontSize = (int32_t)style.GetNumber("fontsize", 16.0);
|
||||
|
||||
mFontColor = style.GetColor("fontcolor", TColor(1, 1, 1, 1));
|
||||
TColor headerColor = style.GetColor("headercolor", TColor(1, 1, 1, 1));
|
||||
mHeaderColorHex.format("%02x%02x%02x%02x",
|
||||
(int)(headerColor.r * 255.0f), (int)(headerColor.g * 255.0f),
|
||||
(int)(headerColor.b * 255.0f), (int)(headerColor.a * 255.0f));
|
||||
|
||||
mCreditsFile = style.GetString("file");
|
||||
|
||||
TFile* file = pf_open(mCreditsFile.c_str(), kReadText);
|
||||
|
||||
str col1("\n");
|
||||
str col2("\n");
|
||||
str col3("\n");
|
||||
|
||||
char line[1024];
|
||||
while (pf_gets(file, line, 1024) != NULL)
|
||||
{
|
||||
line[strlen(line) - 1] = '\0';
|
||||
|
||||
char* bar = strchr(line, '|');
|
||||
if (bar == NULL)
|
||||
{
|
||||
col1 += "\n";
|
||||
col2 += "\n";
|
||||
col3 += CreditLine(line, mHeaderColorHex);
|
||||
}
|
||||
else
|
||||
{
|
||||
*bar = '\0';
|
||||
col1 += CreditLine(line, mHeaderColorHex);
|
||||
col2 += CreditLine(bar + 1, mHeaderColorHex);
|
||||
col3 += "\n";
|
||||
}
|
||||
}
|
||||
pf_close(file);
|
||||
|
||||
uint32_t height = GetWindowHeight();
|
||||
for (uint32_t i = 0; i < height / mFontSize; i++)
|
||||
{
|
||||
col1 += "\n";
|
||||
col2 += "\n";
|
||||
col3 += "\n";
|
||||
}
|
||||
|
||||
mText1 = TTextGraphic::Create(col1 + col1, mColumnWidth, height, 1, mFont.c_str(), mFontSize, mFontColor);
|
||||
mText2 = TTextGraphic::Create(col2 + col2, mColumnWidth, height, 1, mFont.c_str(), mFontSize, mFontColor);
|
||||
mText3 = TTextGraphic::Create(col3 + col3, mColumnGap + mColumnWidth * 2, height, 1, mFont.c_str(), mFontSize, mFontColor);
|
||||
|
||||
TRect bounds;
|
||||
mText1->GetTextBounds(&bounds, 1.0f);
|
||||
mHeight = bounds.y2 / 2;
|
||||
mStart = 0;
|
||||
|
||||
StartWindowAnimation(16, true, true, false);
|
||||
}
|
||||
|
||||
// game @0x0001be5e
|
||||
void TCredits::Draw()
|
||||
{
|
||||
if (mStart == 0)
|
||||
{
|
||||
mStart = TPlatform::GetInstance()->Timer();
|
||||
}
|
||||
|
||||
uint32_t elapsed = TPlatform::GetInstance()->Timer() - mStart;
|
||||
uint32_t pos = (elapsed < mCreditsIntroPause) ? 0 : (elapsed - mCreditsIntroPause);
|
||||
TReal f = (TReal)((pos % mCreditsTime) * mHeight) / (TReal)mCreditsTime;
|
||||
|
||||
TRenderer::GetInstance()->Begin2d();
|
||||
|
||||
TRect windowRect;
|
||||
GetWindowRect(&windowRect);
|
||||
|
||||
TRect rect(mColumnGap, -(int32_t)mFontSize,
|
||||
(GetWindowWidth() >> 1) - (mColumnGap >> 1), GetWindowHeight() + mFontSize * 2);
|
||||
mText1->SetStartLine(f / (TReal)mFontSize);
|
||||
mText1->Draw(rect, 1.0, 0, 1.0);
|
||||
|
||||
rect.x1 = (GetWindowWidth() >> 1) + (mColumnGap >> 1);
|
||||
rect.x2 = GetWindowWidth() - mColumnGap;
|
||||
mText2->SetStartLine(f / (TReal)mFontSize);
|
||||
mText2->Draw(rect, 1.0, 0, 1.0);
|
||||
|
||||
rect.x1 = mColumnGap;
|
||||
rect.x2 = GetWindowWidth() - mColumnGap;
|
||||
mText3->SetStartLine(f / (TReal)mFontSize);
|
||||
mText3->Draw(rect, 1.0, 0, 1.0);
|
||||
|
||||
TRenderer::GetInstance()->End2d();
|
||||
}
|
||||
198
port/game/customtextedit.cpp
Normal file
198
port/game/customtextedit.cpp
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
// Port of the game's customtextedit.cpp (Chocolatier 3, Big Splash Games): TCustomTextEdit, a TTextEdit that plays
|
||||
// key-click sounds, clears its initial text the first time it is edited, and enables/disables a linked window as its
|
||||
// text goes empty or non-empty.
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// customtextedit.h (port/game/customtextedit.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TTextEdit ...; mAssetMap 0x7c, mRandom 0x9c, mClearedInitialText 0xa60, mWidthLimit 0xa61,
|
||||
// mEnableWindow 0xa64, pOnKey 0xa68; sizeof 0xa6c (TCustomTextEditDynamicCreate allocates 0xa6c). The header matches.
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The constructor registers four typing sounds ("sfx/sfx_typing_01.ogg?group=1000" .. _04) with mAssetMap through
|
||||
// AddAssets, then leaves mClearedInitialText true (the initial text is not yet cleared) and mWidthLimit false.
|
||||
// - OnChar always calls TTextEdit::OnChar first; when pOnKey is set it then pushes that Lua function and offers it to
|
||||
// the running script with TScript::InjectFunction (a virtual call, see the note below), so a key press reaches the
|
||||
// window's Lua "onkey" handler.
|
||||
// - OnMouseUp: the first mouse-up clears the edit's text (SetText("")) and reports the event as handled; afterwards
|
||||
// it defers to TText::OnMouseUp.
|
||||
// - TestEnable looks up the "enablewindow" child under the parent modal and toggles its kEnabled state flag (0x100)
|
||||
// depending on whether the text length plus the typed count is non-empty, then invalidates the screen. Doing nothing
|
||||
// when the name is empty or the child is not found.
|
||||
// - KeyHit first clears the initial text like OnMouseUp does. A kKeyChar key that would overrun a width-limited field
|
||||
// (client width minus text width below 20 pixels) is rejected. Otherwise the key is passed to TTextEdit::KeyHit, a
|
||||
// random typing sound (o.gg _01 .. _04) is looked up from mAssetMap and played, and TestEnable(1) runs. Any other
|
||||
// key type just forwards to TTextEdit::KeyHit and, for kKeyMove backspace, calls TestEnable(-1).
|
||||
//
|
||||
// Strings from the game's __cstring: "TCustomTextEdit" (@0x00159270), "sfx/sfx_typing_01.ogg?group=1000"
|
||||
// (@0x00159280), "sfx/sfx_typing_02.ogg?group=1000" (@0x001592a4), "sfx/sfx_typing_03.ogg?group=1000"
|
||||
// (@0x001592c8), "sfx/sfx_typing_04.ogg?group=1000" (@0x001592ec), "clearinitial" (@0x00159310), "enablewindow"
|
||||
// (@0x00159320), "onkey" (@0x00159330), "widthlimited" (@0x00159338), "sfx/sfx_typing_%02d.ogg?group=1000"
|
||||
// (@0x00159348), "" (@0x001581bc). The random sound suffix is (int)(RandDouble() * 4.0) + 1 (the constant at
|
||||
// @0x001ab510 is 4.0).
|
||||
//
|
||||
// Compiler-generated in the game:
|
||||
// - PFTYPEDEF_DC IsKindOf: game @0x0016e168 (compares the id against &TCustomTextEditDynamicCreate, else calls
|
||||
// TTextEdit::IsKindOf).
|
||||
// - The constructor's member constructions (TTextEdit base, vtable store, TAssetMap, TRandom, mEnableWindow, pOnKey)
|
||||
// are compiler-generated from the member declarations; only AddAssets and the two flag stores are the ctor body.
|
||||
// - The destructor deletes pOnKey through its virtual deleting destructor, then destroys mEnableWindow (str) and
|
||||
// mAssetMap before the TTextEdit base (visible in D1/D0, cited below).
|
||||
// - OnChar's pOnKey->Push() + InjectFunction() is an inlined TLuaObjectWrapper::Push and a virtual call through
|
||||
// TScript's vtable slot 5 (TScript::InjectFunction), which TWindowScript overrides (game @0x0020559f calls
|
||||
// *0x14(%vtable)).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "customtextedit.h"
|
||||
|
||||
#include "pf/rect.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/sound.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
|
||||
// game @0x00020414 (TCustomTextEditDynamicCreate: new TCustomTextEdit, sizeof 0xa6c)
|
||||
// game @0x0002033c (ClassId: returns &TCustomTextEditDynamicCreate)
|
||||
// game @0x00020346 (GetTypeName, "TCustomTextEdit")
|
||||
PFTYPEIMPL_DC(TCustomTextEdit);
|
||||
|
||||
// game @0x00020350
|
||||
TCustomTextEdit::TCustomTextEdit()
|
||||
{
|
||||
pOnKey = NULL;
|
||||
|
||||
const char* assets[] =
|
||||
{
|
||||
"sfx/sfx_typing_01.ogg?group=1000",
|
||||
"sfx/sfx_typing_02.ogg?group=1000",
|
||||
"sfx/sfx_typing_03.ogg?group=1000",
|
||||
"sfx/sfx_typing_04.ogg?group=1000",
|
||||
NULL
|
||||
};
|
||||
mAssetMap.AddAssets(assets);
|
||||
|
||||
mClearedInitialText = true;
|
||||
mWidthLimit = false;
|
||||
}
|
||||
|
||||
// game @0x00020452 (D1) / game @0x000204d4 (D0)
|
||||
TCustomTextEdit::~TCustomTextEdit()
|
||||
{
|
||||
delete pOnKey;
|
||||
}
|
||||
|
||||
// game @0x0002055e
|
||||
bool TCustomTextEdit::OnChar(char key)
|
||||
{
|
||||
bool result = TTextEdit::OnChar(key);
|
||||
|
||||
if (pOnKey != NULL)
|
||||
{
|
||||
pOnKey->Push();
|
||||
TWindowManager::GetInstance()->GetScript()->InjectFunction();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x000205ae
|
||||
void TCustomTextEdit::Init(TWindowStyle& style)
|
||||
{
|
||||
mClearedInitialText = !style.GetBool("clearinitial", false);
|
||||
mEnableWindow = style.GetString("enablewindow", "");
|
||||
pOnKey = style.GetFunction("onkey");
|
||||
mWidthLimit = style.GetBool("widthlimited", false);
|
||||
|
||||
TTextEdit::Init(style);
|
||||
}
|
||||
|
||||
// game @0x00020746
|
||||
bool TCustomTextEdit::OnMouseUp(const TPoint& point)
|
||||
{
|
||||
if (!mClearedInitialText)
|
||||
{
|
||||
mClearedInitialText = true;
|
||||
SetText("");
|
||||
return true;
|
||||
}
|
||||
|
||||
return TText::OnMouseUp(point);
|
||||
}
|
||||
|
||||
// game @0x000207be
|
||||
void TCustomTextEdit::TestEnable(int count)
|
||||
{
|
||||
if (mEnableWindow.length() != 0)
|
||||
{
|
||||
TWindow* window = FindParentModal()->GetChildWindow(mEnableWindow, -1);
|
||||
if (window != NULL)
|
||||
{
|
||||
if ((int)GetText().length() + count < 1)
|
||||
{
|
||||
window->SetFlags(window->GetFlags() & ~(uint32_t)TWindow::kEnabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->SetFlags(window->GetFlags() | (uint32_t)TWindow::kEnabled);
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00020898
|
||||
bool TCustomTextEdit::KeyHit(eKeyType type, char key)
|
||||
{
|
||||
if (!mClearedInitialText)
|
||||
{
|
||||
mClearedInitialText = true;
|
||||
SetText("");
|
||||
}
|
||||
|
||||
if (type == kKeyChar)
|
||||
{
|
||||
if (mWidthLimit)
|
||||
{
|
||||
TRect clientRect;
|
||||
TRect textBounds;
|
||||
GetClientRect(&clientRect);
|
||||
GetTextBounds(&textBounds);
|
||||
if ((clientRect.x2 - clientRect.x1) - (textBounds.x2 - textBounds.x1) < 20)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!TTextEdit::KeyHit(kKeyChar, key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
double random = mRandom.RandDouble();
|
||||
str name = str::getFormatted("sfx/sfx_typing_%02d.ogg?group=1000", (int)(random * 4.0) + 1);
|
||||
|
||||
TSoundRef sound = mAssetMap.GetSound(name);
|
||||
if (sound != NULL)
|
||||
{
|
||||
sound->Play();
|
||||
}
|
||||
|
||||
TestEnable(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!TTextEdit::KeyHit(type, key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type == kKeyMove && key == '\b')
|
||||
{
|
||||
TestEnable(-1);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
583
port/game/hiscore.cpp
Normal file
583
port/game/hiscore.cpp
Normal file
|
|
@ -0,0 +1,583 @@
|
|||
// Port of the game's hiscore.cpp (Chocolatier 3; PlayFirst skeleton code adapted by Big Splash Games): THiscore, the
|
||||
// high score window: a local table, a global (server) table with category browsing and scrolling, the submit result
|
||||
// texts, and the Lua functions it registers (GetState, ScoreAvailable, UpdateText, LaunchPrivacyPolicy,
|
||||
// SubmissionDone).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// hiscore.h (port/game/hiscore.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TWindow 0x0..0x2f, mState 0x30, mSubmitState 0x34, mpPFHiscores 0x38, mServerError 0x3c,
|
||||
// mCurrentCategory 0x40, mCurrentEditField 0x44, mScoreOffset 0x48, mNames 0x4c, mScores 0x74, mNumbers 0x9c,
|
||||
// mP1s 0xc4, mInfos 0xec (10 pointers each); sizeof 0x114 (THiscoreDynamicCreate allocates 0x114). The header matches.
|
||||
// The constructor sets mState (eLocalView), mServerError, mCurrentCategory, mCurrentEditField and mScoreOffset and
|
||||
// leaves mSubmitState and the pointer arrays untouched (PostChildrenInit fills the arrays).
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - States: eLocalView 0, eRequestingCategories 1, eRequestingScores 2, eSubmitting 3, eGlobalView 4, eError 5;
|
||||
// submit states: eNone 0, eSuccess 1, eDNQ 2.
|
||||
// - UpdateText hides everything (HideAllText), then shows the right panel variant ("rightpanel" in the local
|
||||
// view, "rightpanelsmall" otherwise; both hidden when TPlatform::kHiscoreLocalOnly is enabled), the table
|
||||
// (UpdateScoresTable) and the state specific children. UpdateScoresTable shows up to 10 rows (n = mScoreOffset + i),
|
||||
// shrinks each name's line height from 20 down to 2 until its bounds fit the window, formats the score through the
|
||||
// string table ("score_format") and the rank as "%d.", fills the info text from ParseGameData and shows the "p1"
|
||||
// image only for a non anonymous score while neither kHiscoreLocalOnly nor kHiscoreAnonymous is enabled.
|
||||
// - ParseGameData reads a "rank-score-money" style string: the first character selects the "rank_%c" string table
|
||||
// entry; the text between the first and second '-' is the score (to_int; values from 1000000000 up are shown as
|
||||
// 999999999.0) and the rest the money (to_float, floored at 0.0); both go through Dollars() (the leading currency
|
||||
// sign of the score is cut off) into the "score_info_format" string table entry (rank, money, score).
|
||||
// - SubmissionDone(qualified) goes to eRequestingCategories and records eSuccess / eDNQ.
|
||||
// - OnTaskAnimate polls the server request in states 1 and 2 (error: stores the message and goes to eError;
|
||||
// states 0, 4 and 5 do nothing). OnDirtyRect reports the whole 800x600 screen.
|
||||
//
|
||||
// Strings from the game's __cstring: "THiscore", "UpdateButtons();", "http://www.playfirst.com/privacypolicy.html",
|
||||
// "rank_%c" (@0x001594a8), "score_info_format" (@0x001594b0), "score_format", "%d.", "%d" (@0x001588dc), "name%d",
|
||||
// "score%d", "info%d", "p1_%d", "rightpanel" (@0x001595d4), "rightpanelsmall" (@0x001595e0), "eligible"
|
||||
// (@0x00159510), "eligibleasterisk" (@0x0015951c), "info" (@0x00159540), "category" (@0x00159548),
|
||||
// "yourrankglobalinfo" (@0x00159588), "congratulations" (@0x00159568), "dnq" (@0x00159578), "yourrank"
|
||||
// (@0x0015957c), "server", "error", "local", "global", "topplayers", "yourrank", "rankvalue", "scrollup",
|
||||
// "scrolldown", "categoryleft", "categoryright", "view", "viewlocal", and the registered names "GetState",
|
||||
// "ScoreAvailable", "UpdateText", "LaunchPrivacyPolicy", "SubmissionDone". Constant 999999999.0 at @0x001ab530.
|
||||
//
|
||||
// Compiler-generated / header-inline code emitted out of line: PFTYPEDEF_DC IsKindOf game @0x0016ead8 (compares the
|
||||
// id against &THiscoreDynamicCreate, else TWindow::IsKindOf; ClassId game @0x00022d90, GetTypeName
|
||||
// game @0x00022d9a); GetState game @0x0016e87c; ~THiscore D1 game @0x00023666 / D0 game @0x00023786 (the Lua
|
||||
// unregistration below, then the mServerError and TWindow destructors; "LaunchPrivacyPolicy" stays registered, as in
|
||||
// the game); lua_pushdirectclosure<THiscore, F> for F = int () game @0x0016e888, bool () game @0x0016e8d4,
|
||||
// void () game @0x0016e920, void (bool) game @0x0016e96c; LPCD::ReturnSpecialization<R>::Call / DirectCallMember
|
||||
// DispatcherHelper<THiscore, F>::DirectCallMemberDispatcher for F = int () (Call game @0x0016e9b8, dispatcher game
|
||||
// game @0x0016e9fc), bool () (Call game @0x0016ea40, dispatcher game @0x0016eb90), void (bool) (Call game @0x0016ea84,
|
||||
// dispatcher game @0x0016eb04), void () (dispatcher game @0x0016eb48) (pf/luapluscd.h templates).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "hiscore.h"
|
||||
|
||||
#include "BSGHelpers.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "pf/image.h"
|
||||
#include "pf/pfhiscores.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/stringtable.h"
|
||||
#include "pf/text.h"
|
||||
#include "pf/textgraphic.h"
|
||||
#include "pf/windowmanager.h"
|
||||
#include "pf/windowstyle.h"
|
||||
|
||||
|
||||
// game @0x0002362a (THiscoreDynamicCreate: new THiscore, sizeof 0x114)
|
||||
// game @0x00022d90 (ClassId), game @0x00022d9a (GetTypeName, "THiscore"), game @0x0016ead8 (IsKindOf)
|
||||
PFTYPEIMPL_DC(THiscore);
|
||||
|
||||
// game @0x00022da4
|
||||
bool THiscore::OnDirtyRect(TRect* rect)
|
||||
{
|
||||
if (rect != NULL) {
|
||||
rect->x1 = 0;
|
||||
rect->x2 = 800;
|
||||
rect->y1 = 0;
|
||||
rect->y2 = 600;
|
||||
}
|
||||
return rect != NULL;
|
||||
}
|
||||
|
||||
// game @0x00022dd0
|
||||
void THiscore::UpdateButtons()
|
||||
{
|
||||
str command("UpdateButtons();");
|
||||
TWindowManager::GetInstance()->GetScript()->DoLuaString(command, -1, 0);
|
||||
}
|
||||
|
||||
// game @0x00022e38
|
||||
bool THiscore::ScoreAvailable()
|
||||
{
|
||||
int32_t score;
|
||||
return mpPFHiscores->GetUserBestScore(TPfHiscores::eLocalEligible, &score, 0, 0, 0);
|
||||
}
|
||||
|
||||
// game @0x00022e78
|
||||
void THiscore::LaunchPrivacyPolicy()
|
||||
{
|
||||
TPlatform::GetInstance()->OpenBrowser("http://www.playfirst.com/privacypolicy.html");
|
||||
}
|
||||
|
||||
// game @0x00022e96
|
||||
str THiscore::ParseGameData(char const* pGameData)
|
||||
{
|
||||
str gameData(pGameData);
|
||||
str rank = str::getFormatted("rank_%c", (int)*pGameData);
|
||||
{
|
||||
rank = TPlatform::GetInstance()->GetStringTable()->GetString(str(rank), str(), str(), str(), str(), str());
|
||||
}
|
||||
|
||||
int32_t first = gameData.find('-', 0, 0);
|
||||
int32_t second = gameData.find('-', 0, first + 1);
|
||||
str score = gameData.substr(first + 1, second - (first + 1));
|
||||
str money = gameData.substr(second + 1, 0xffffffff);
|
||||
|
||||
uint32_t scoreValue = (uint32_t)score.to_int();
|
||||
double scoreDouble;
|
||||
if (scoreValue < 1000000000) {
|
||||
scoreDouble = (double)scoreValue;
|
||||
} else {
|
||||
scoreDouble = 999999999.0;
|
||||
}
|
||||
score = Dollars(scoreDouble);
|
||||
score = score.substr(1, score.length() - 1);
|
||||
|
||||
double moneyValue = (double)(float)money.to_float();
|
||||
moneyValue = (0.0 > moneyValue) ? 0.0 : moneyValue;
|
||||
money = Dollars(moneyValue);
|
||||
|
||||
return TPlatform::GetInstance()->GetStringTable()->GetString(str("score_info_format"), str(rank), str(money),
|
||||
str(score), str(), str());
|
||||
}
|
||||
|
||||
// game @0x0002339e (C1)
|
||||
THiscore::THiscore()
|
||||
{
|
||||
mState = eLocalView;
|
||||
mCurrentCategory = 0;
|
||||
mCurrentEditField = 0;
|
||||
mScoreOffset = 0;
|
||||
mpPFHiscores = TSettings::GetInstance()->GetHiscores();
|
||||
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "GetState", this, THiscore::GetState);
|
||||
ScriptRegisterMemberDirect(script, "ScoreAvailable", this, THiscore::ScoreAvailable);
|
||||
ScriptRegisterMemberDirect(script, "UpdateText", this, THiscore::UpdateText);
|
||||
ScriptRegisterMemberDirect(script, "LaunchPrivacyPolicy", this, THiscore::LaunchPrivacyPolicy);
|
||||
ScriptRegisterMemberDirect(script, "SubmissionDone", this, THiscore::SubmissionDone);
|
||||
}
|
||||
|
||||
// game @0x00023666 (D1) / game @0x00023786 (D0)
|
||||
THiscore::~THiscore()
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptUnregisterFunction(script, "GetState");
|
||||
ScriptUnregisterFunction(script, "ScoreAvailable");
|
||||
ScriptUnregisterFunction(script, "UpdateText");
|
||||
ScriptUnregisterFunction(script, "SubmissionDone");
|
||||
}
|
||||
|
||||
// game @0x000238ae
|
||||
void THiscore::HideAllText()
|
||||
{
|
||||
for (int i = 0; i < NUM_SCORES_ON_SCREEN; i++) {
|
||||
mNames[i]->SetFlags(mNames[i]->GetFlags() & ~TWindow::kEnabled);
|
||||
mScores[i]->SetFlags(mScores[i]->GetFlags() & ~TWindow::kEnabled);
|
||||
mInfos[i]->SetFlags(mInfos[i]->GetFlags() & ~TWindow::kEnabled);
|
||||
mNumbers[i]->SetFlags(mNumbers[i]->GetFlags() & ~TWindow::kEnabled);
|
||||
mP1s[i]->SetFlags(mP1s[i]->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
|
||||
static const char* const names[] = {
|
||||
"eligible", "eligibleasterisk", "server", "error", "info", "category", "local", "global", "topplayers",
|
||||
"congratulations", "dnq", "yourrank", "yourrankglobalinfo", "rankvalue", "scrollup", "scrolldown"
|
||||
};
|
||||
for (int n = 0; n < 16; n++) {
|
||||
TWindow* w = GetChildWindow(names[n], -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00023e2e
|
||||
void THiscore::UpdateScoresTable()
|
||||
{
|
||||
int32_t count;
|
||||
bool local;
|
||||
|
||||
if (mState == eGlobalView) {
|
||||
count = mpPFHiscores->GetScoreCount(false);
|
||||
TWindow* w = GetChildWindow("global", -1);
|
||||
if (w != 0) {
|
||||
if (!TPlatform::GetInstance()->IsEnabled(str(TPlatform::kHiscoreLocalOnly))) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
if (count - 5 < mScoreOffset) {
|
||||
mScoreOffset = count - 5;
|
||||
}
|
||||
if (mScoreOffset < 0) {
|
||||
mScoreOffset = 0;
|
||||
}
|
||||
if (mScoreOffset < 1) {
|
||||
w = GetChildWindow("scrollup", -1);
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
} else {
|
||||
w = GetChildWindow("scrollup", -1);
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
if (mScoreOffset + 10 < count) {
|
||||
w = GetChildWindow("scrolldown", -1);
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
} else {
|
||||
w = GetChildWindow("scrolldown", -1);
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
local = false;
|
||||
} else {
|
||||
count = mpPFHiscores->GetScoreCount(true);
|
||||
TWindow* w = GetChildWindow("local", -1);
|
||||
if (w != 0) {
|
||||
if (!TPlatform::GetInstance()->IsEnabled(str(TPlatform::kHiscoreLocalOnly))) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
w = GetChildWindow("topplayers", -1);
|
||||
if (w != 0) {
|
||||
if (TPlatform::GetInstance()->IsEnabled(str(TPlatform::kHiscoreLocalOnly))) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
w = GetChildWindow("scrollup", -1);
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
w = GetChildWindow("scrolldown", -1);
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
mScoreOffset = 0;
|
||||
local = true;
|
||||
}
|
||||
|
||||
for (int i = 0; ; i++) {
|
||||
if (count <= i + mScoreOffset || i == 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t rank;
|
||||
int32_t score;
|
||||
char name[64];
|
||||
char gameData[64];
|
||||
bool anonymous;
|
||||
mpPFHiscores->GetScore(local, i + mScoreOffset, &rank, name, 0x40, &anonymous, &score, gameData, 0x40);
|
||||
|
||||
mNames[i]->SetFlags(mNames[i]->GetFlags() | TWindow::kEnabled);
|
||||
mNames[i]->SetText(str(name));
|
||||
|
||||
TRect bounds(0, 0, 0, 0);
|
||||
int32_t lineHeight = 0x14;
|
||||
do {
|
||||
mNames[i]->GetTextBounds(&bounds);
|
||||
TText* pName = mNames[i];
|
||||
if (bounds.x2 < (int32_t)pName->GetWindowWidth() && -1 < bounds.y1 && bounds.y2 <= (int32_t)pName->GetWindowHeight()) {
|
||||
break;
|
||||
}
|
||||
lineHeight--;
|
||||
pName->GetTextGraphic()->SetLineHeight(lineHeight);
|
||||
} while (1 < lineHeight);
|
||||
|
||||
str text;
|
||||
text = TPlatform::GetInstance()->GetStringTable()->GetString(str("score_format"), Dollars((double)score),
|
||||
str(), str(), str(), str());
|
||||
|
||||
mScores[i]->SetText(str(text));
|
||||
mScores[i]->SetFlags(mScores[i]->GetFlags() | TWindow::kEnabled);
|
||||
mNumbers[i]->SetFlags(mNumbers[i]->GetFlags() | TWindow::kEnabled);
|
||||
mInfos[i]->SetText(ParseGameData(gameData));
|
||||
mInfos[i]->SetFlags(mInfos[i]->GetFlags() | TWindow::kEnabled);
|
||||
|
||||
text.format("%d.", rank);
|
||||
mNumbers[i]->SetText(str(text));
|
||||
|
||||
bool showP1;
|
||||
if (!anonymous) {
|
||||
if (TPlatform::GetInstance()->IsEnabled(str(TPlatform::kHiscoreLocalOnly))) {
|
||||
showP1 = false;
|
||||
} else {
|
||||
showP1 = !TPlatform::GetInstance()->IsEnabled(str(TPlatform::kHiscoreAnonymous));
|
||||
}
|
||||
} else {
|
||||
showP1 = false;
|
||||
}
|
||||
if (showP1) {
|
||||
mP1s[i]->SetFlags(mP1s[i]->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000247ea
|
||||
void THiscore::UpdateText()
|
||||
{
|
||||
HideAllText();
|
||||
|
||||
TWindow* pPanel;
|
||||
TWindow* pPanelSmall;
|
||||
if (!TPlatform::GetInstance()->IsEnabled(str(TPlatform::kHiscoreLocalOnly))) {
|
||||
if (mState == eLocalView) {
|
||||
pPanel = GetChildWindow("rightpanel", -1);
|
||||
pPanel->SetFlags(pPanel->GetFlags() | TWindow::kEnabled);
|
||||
pPanelSmall = GetChildWindow("rightpanelsmall", -1);
|
||||
pPanelSmall->SetFlags(pPanelSmall->GetFlags() & ~TWindow::kEnabled);
|
||||
} else {
|
||||
pPanel = GetChildWindow("rightpanel", -1);
|
||||
pPanel->SetFlags(pPanel->GetFlags() & ~TWindow::kEnabled);
|
||||
pPanelSmall = GetChildWindow("rightpanelsmall", -1);
|
||||
pPanelSmall->SetFlags(pPanelSmall->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
} else {
|
||||
pPanel = GetChildWindow("rightpanel", -1);
|
||||
pPanel->SetFlags(pPanel->GetFlags() & ~TWindow::kEnabled);
|
||||
pPanelSmall = GetChildWindow("rightpanelsmall", -1);
|
||||
pPanelSmall->SetFlags(pPanelSmall->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
|
||||
if (mState == eLocalView || mState == eGlobalView) {
|
||||
UpdateScoresTable();
|
||||
|
||||
if (mState == eLocalView) {
|
||||
int32_t score;
|
||||
bool available = mpPFHiscores->GetUserBestScore(TPfHiscores::eLocalEligible, &score, 0, 0, 0);
|
||||
if (available) {
|
||||
TWindow* w = GetChildWindow("eligible", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
w = GetChildWindow("eligibleasterisk", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
TWindow* w = GetChildWindow("info", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
if (mState == eGlobalView) {
|
||||
int32_t rank;
|
||||
TWindow* w = GetChildWindow("category", -1);
|
||||
if (w != 0) {
|
||||
TText* pText = w->GetCast<TText>();
|
||||
pText->SetFlags(pText->GetFlags() | TWindow::kEnabled);
|
||||
char categoryName[64];
|
||||
if (mpPFHiscores->GetCategoryName(mCurrentCategory, categoryName, 0x40)) {
|
||||
pText->SetText(str(categoryName));
|
||||
}
|
||||
}
|
||||
w = GetChildWindow("yourrankglobalinfo", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
|
||||
bool ranked = mpPFHiscores->GetUserBestScore(TPfHiscores::eGlobalBest, 0, &rank, 0, 0);
|
||||
|
||||
if (mSubmitState == eSuccess) {
|
||||
w = GetChildWindow("congratulations", -1);
|
||||
if (w != 0) {
|
||||
TText* pText = w->GetCast<TText>();
|
||||
pText->SetFlags(pText->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
w = GetChildWindow("yourrankglobalinfo", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
} else if (mSubmitState == eDNQ) {
|
||||
w = GetChildWindow("dnq", -1);
|
||||
if (w != 0) {
|
||||
TText* pText = w->GetCast<TText>();
|
||||
pText->SetFlags(pText->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
w = GetChildWindow("yourrankglobalinfo", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
if (ranked) {
|
||||
w = GetChildWindow("yourrank", -1);
|
||||
if (w != 0) {
|
||||
TText* pText = w->GetCast<TText>();
|
||||
pText->SetFlags(pText->GetFlags() | TWindow::kEnabled);
|
||||
str rankText;
|
||||
rankText.format("%d", rank);
|
||||
str text = TPlatform::GetInstance()->GetStringTable()->GetString(str("yourrank"), str(rankText),
|
||||
str(), str(), str(), str());
|
||||
pText->SetText(str(text));
|
||||
}
|
||||
w = GetChildWindow("yourrankglobalinfo", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((uint32_t)(mState - 1) < 3) {
|
||||
TWindow* w = GetChildWindow("server", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
if (mState == eError) {
|
||||
TWindow* w = GetChildWindow("error", -1);
|
||||
if (w != 0) {
|
||||
TText* pText = w->GetCast<TText>();
|
||||
pText->SetFlags(pText->GetFlags() | TWindow::kEnabled);
|
||||
pText->SetText(str(mServerError));
|
||||
}
|
||||
}
|
||||
|
||||
if (TPlatform::GetInstance()->IsEnabled(str(TPlatform::kHiscoreLocalOnly))) {
|
||||
TWindow* w = GetChildWindow("info", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
w = GetChildWindow("eligible", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
w = GetChildWindow("eligibleasterisk", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00025314
|
||||
bool THiscore::OnTaskAnimate()
|
||||
{
|
||||
if (mState == eLocalView) {
|
||||
return true;
|
||||
}
|
||||
if (mState == eGlobalView) {
|
||||
return true;
|
||||
}
|
||||
if (mState == eError) {
|
||||
return true;
|
||||
}
|
||||
if ((uint32_t)(mState - 1) < 2) {
|
||||
char msg[512];
|
||||
bool qualified;
|
||||
int status = mpPFHiscores->GetServerRequestStatus(msg, 0x200, &qualified);
|
||||
if (status == 2) {
|
||||
mServerError = msg;
|
||||
mState = eError;
|
||||
} else {
|
||||
if (status != 0) {
|
||||
return true;
|
||||
}
|
||||
if (mState == eRequestingCategories) {
|
||||
mState = eRequestingScores;
|
||||
mpPFHiscores->RequestScores(mCurrentCategory);
|
||||
return true;
|
||||
}
|
||||
if (mState != eRequestingScores) {
|
||||
return true;
|
||||
}
|
||||
mState = eGlobalView;
|
||||
}
|
||||
UpdateText();
|
||||
UpdateButtons();
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x000253ec
|
||||
void THiscore::SubmissionDone(bool qualified)
|
||||
{
|
||||
mState = eRequestingCategories;
|
||||
mpPFHiscores->RequestCategoryInformation();
|
||||
mSubmitState = qualified ? eSuccess : eDNQ;
|
||||
UpdateText();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
// game @0x00025432
|
||||
bool THiscore::OnMessage(TMessage* message)
|
||||
{
|
||||
if (message->mType == TMessage::kButtonPress) {
|
||||
const str& name = message->mName;
|
||||
int32_t category;
|
||||
if (name == str("categoryleft")) {
|
||||
category = mCurrentCategory - 1;
|
||||
mCurrentCategory = category;
|
||||
if (category < 0) {
|
||||
category = mpPFHiscores->GetCategoryCount() - 1;
|
||||
mCurrentCategory = category;
|
||||
}
|
||||
mState = eRequestingScores;
|
||||
} else if (name == str("categoryright")) {
|
||||
int32_t next = mCurrentCategory + 1;
|
||||
mCurrentCategory = next;
|
||||
if (mpPFHiscores->GetCategoryCount() <= next) {
|
||||
mCurrentCategory = 0;
|
||||
}
|
||||
mState = eRequestingScores;
|
||||
category = mCurrentCategory;
|
||||
} else {
|
||||
if (name == str("view")) {
|
||||
mSubmitState = eNone;
|
||||
mState = eRequestingCategories;
|
||||
mpPFHiscores->RequestCategoryInformation();
|
||||
} else if (name == str("viewlocal")) {
|
||||
mState = eLocalView;
|
||||
} else if (name == str("scrollup")) {
|
||||
mScoreOffset = mScoreOffset - 10;
|
||||
UpdateText();
|
||||
return false;
|
||||
} else if (name == str("scrolldown")) {
|
||||
mScoreOffset = mScoreOffset + 10;
|
||||
UpdateText();
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
UpdateText();
|
||||
UpdateButtons();
|
||||
return false;
|
||||
}
|
||||
mpPFHiscores->RequestScores(category);
|
||||
UpdateText();
|
||||
UpdateButtons();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0002566c
|
||||
void THiscore::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow::PostChildrenInit(style);
|
||||
StartWindowAnimation(0x14, true, true, false);
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; ; i++) {
|
||||
str buffer;
|
||||
n = n + 1;
|
||||
buffer.format("name%d", n);
|
||||
TWindow* w = GetChildWindow(str(buffer), -1);
|
||||
if (w != 0) {
|
||||
mNames[i] = w->GetCast<TText>();
|
||||
}
|
||||
buffer.format("score%d", n);
|
||||
w = GetChildWindow(str(buffer), -1);
|
||||
if (w != 0) {
|
||||
mScores[i] = w->GetCast<TText>();
|
||||
}
|
||||
buffer.format("info%d", n);
|
||||
w = GetChildWindow(str(buffer), -1);
|
||||
if (w != 0) {
|
||||
mInfos[i] = w->GetCast<TText>();
|
||||
}
|
||||
buffer.format("%d", n);
|
||||
w = GetChildWindow(str(buffer), -1);
|
||||
if (w != 0) {
|
||||
mNumbers[i] = w->GetCast<TText>();
|
||||
}
|
||||
buffer.format("p1_%d", n);
|
||||
w = GetChildWindow(str(buffer), -1);
|
||||
if (w != 0) {
|
||||
mP1s[i] = w->GetCast<TImage>();
|
||||
}
|
||||
if (n == 10) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateText();
|
||||
UpdateButtons();
|
||||
}
|
||||
113
port/game/main.cpp
Normal file
113
port/game/main.cpp
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
// Port of the game's main.cpp (Chocolatier 3; the Playground SDK skeleton's main.cpp adapted by Big Splash Games):
|
||||
// PlaygroundInit (platform configuration from key.h before the platform starts) and Main (renderer options, the
|
||||
// TGameState session/progress reporting setup, window title, settings, the custom TextEdit window type, then
|
||||
// ChocoThreeMain).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); configuration values from the
|
||||
// original key.h (port/game/key.h, unchanged).
|
||||
//
|
||||
// main() itself (_main game @0x000294fa: PlaygroundInit(); PlayFirstExec(argc, argv, Main, false); return 0) is the
|
||||
// pf/pflibcore.h boilerplate that a file defining PLAYFIRST_MAIN (and PLAYGROUND_INIT) gets; the game's main.cpp
|
||||
// defines both. main() is written out below (first link, 2026-10-22) instead of defining PLAYFIRST_MAIN, because the
|
||||
// pflibcore.h boilerplate is selected by the MACINTOSH macro, which the port does not define.
|
||||
//
|
||||
// Strings from the game's __cstring: "chocolatier-decadence-design" (kGameName value), "%s%d", "1",
|
||||
// "new_subtractive", "new_render_blend", "texture_rectangle", "SessionTime", "SessionData", "begin-session", "",
|
||||
// "add-value", "add-timer", "GameWeeks", "add-state", "Money", "Rank", "IntroMovieTime", "end-session",
|
||||
// "Progress-15/30/45/59", "begin-elapsed(15/30/45/59)", "end-elapsed(15/30/45/59)", "windowtitle", "TextEdit";
|
||||
// key.h: ENCRYPTION_KEY, PFGAMEHANDLE, PFGAMEMODENAMES (1 entry), PFGAMEMEDALNAMES (9 entries) in __data.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#define PLAYGROUND_INIT
|
||||
|
||||
#include "pf/pflib.h"
|
||||
|
||||
#include "chocothree.h"
|
||||
#include "customtextedit.h"
|
||||
#include "key.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "pf/gamestate.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
// game @0x00029294
|
||||
void PlaygroundInit()
|
||||
{
|
||||
TPlatform::SetConfig(TPlatform::kGameName, "chocolatier-decadence-design");
|
||||
TPlatform::SetConfig(TPlatform::kEncryptionKey, ENCRYPTION_KEY);
|
||||
TPlatform::SetConfig(TPlatform::kPFGameHandle, PFGAMEHANDLE);
|
||||
|
||||
for (int i = 0; i < (int)(sizeof(PFGAMEMODENAMES) / sizeof(PFGAMEMODENAMES[0])); i++)
|
||||
{
|
||||
str key = str::getFormatted("%s%d", TPlatform::kPFGameModeName, i + 1);
|
||||
TPlatform::SetConfig(key, PFGAMEMODENAMES[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)(sizeof(PFGAMEMEDALNAMES) / sizeof(PFGAMEMEDALNAMES[0])); i++)
|
||||
{
|
||||
str key = str::getFormatted("%s%d", TPlatform::kPFGameMedalName, i + 1);
|
||||
TPlatform::SetConfig(key, PFGAMEMEDALNAMES[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002952c
|
||||
void Main(TPlatform* pPlatform, const char* cmdLine)
|
||||
{
|
||||
TRenderer::GetInstance()->SetOption("new_subtractive", "1");
|
||||
TRenderer::GetInstance()->SetOption("new_render_blend", "1");
|
||||
TRenderer::GetInstance()->SetOption("texture_rectangle", "1");
|
||||
|
||||
TGameState* gameState = TGameState::GetInstance();
|
||||
gameState->SetState("SessionTime", 1);
|
||||
gameState->SetState("begin-session", "SessionData");
|
||||
gameState->SetState("add-value", TPlatform::GetConfig(TPlatform::kGameVersion, ""));
|
||||
gameState->SetState("add-timer", "SessionTime");
|
||||
gameState->SetState("add-state", "GameWeeks");
|
||||
gameState->SetState("add-state", "Money");
|
||||
gameState->SetState("add-state", "Rank");
|
||||
gameState->SetState("add-timer", "IntroMovieTime");
|
||||
gameState->SetState("end-session", "SessionData");
|
||||
|
||||
gameState->SetState("begin-elapsed(15)", "Progress-15");
|
||||
gameState->SetState("add-state", "GameWeeks");
|
||||
gameState->SetState("add-state", "Money");
|
||||
gameState->SetState("add-state", "Rank");
|
||||
gameState->SetState("end-elapsed(15)", "Progress-15");
|
||||
|
||||
gameState->SetState("begin-elapsed(30)", "Progress-30");
|
||||
gameState->SetState("add-state", "GameWeeks");
|
||||
gameState->SetState("add-state", "Money");
|
||||
gameState->SetState("add-state", "Rank");
|
||||
gameState->SetState("end-elapsed(30)", "Progress-30");
|
||||
|
||||
gameState->SetState("begin-elapsed(45)", "Progress-45");
|
||||
gameState->SetState("add-state", "GameWeeks");
|
||||
gameState->SetState("add-state", "Money");
|
||||
gameState->SetState("add-state", "Rank");
|
||||
gameState->SetState("end-elapsed(45)", "Progress-45");
|
||||
|
||||
gameState->SetState("begin-elapsed(59)", "Progress-59");
|
||||
gameState->SetState("add-state", "GameWeeks");
|
||||
gameState->SetState("add-state", "Money");
|
||||
gameState->SetState("add-state", "Rank");
|
||||
gameState->SetState("end-elapsed(59)", "Progress-59");
|
||||
|
||||
pPlatform->SetWindowTitle(pPlatform->GetStringTable()->GetString("windowtitle").c_str());
|
||||
|
||||
TSettings::CreateSettings();
|
||||
TSettings::GetInstance()->InitGameToSettings();
|
||||
|
||||
TWindowManager::GetInstance()->AddWindowType("TextEdit", TCustomTextEdit::ClassId());
|
||||
|
||||
ChocoThreeMain();
|
||||
|
||||
TSettings::DeleteSettings();
|
||||
}
|
||||
|
||||
// game @0x000294fa
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
PlaygroundInit();
|
||||
PlayFirstExec(argc, argv, Main, false);
|
||||
return 0;
|
||||
}
|
||||
192
port/game/options.cpp
Normal file
192
port/game/options.cpp
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
// Port of the game's options.cpp (Chocolatier 3; PlayFirst skeleton code): TOptions, the options window: shows the
|
||||
// full-screen and mute state and the three volume sliders, previews slider changes, and saves the volumes
|
||||
// (SaveVolumes, also published to Lua).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// options.h (port/game/options.h, unchanged).
|
||||
//
|
||||
// Game notes: PostChildrenInit does not call TWindow::PostChildrenInit. Unmuted, it re-applies the current user's
|
||||
// sound settings. Slider previews apply only when the user's "soundoff" pref is not 1; OnMessage returns true for a
|
||||
// slider message whose slider exists, even when muted. Volumes are stored as (int)(value * 1000.0f) (mulss,
|
||||
// cvttss2si); sliders get pref / 1000.0f.
|
||||
//
|
||||
// Header-inline code emitted out of line: TOptions::IsKindOf game @0x00171d24 (PFTYPEDEF_DC),
|
||||
// lua_pushdirectclosure<TOptions, void (TOptions::*)()> game @0x00171c90 and its
|
||||
// LPCD::DirectCallMemberDispatcherHelper game @0x00171cdc (pf/luapluscd.h), TWindow::GetCast<TButton> game
|
||||
// @0x00171c5c (pf/window.h).
|
||||
//
|
||||
// Strings from the game's __cstring: "TOptions", "fullscreen", "curuser", "soundoff", "mutebox", "sfxlevelslider",
|
||||
// "soundlevel", "musiclevelslider", "musiclevel", "ambientlevelslider", "ambientlevel", "SaveVolumes".
|
||||
// No static data; no static initializer.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "options.h"
|
||||
|
||||
#include "BSGSound.h"
|
||||
#include "globaldefines.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "pf/button.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/slider.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
// game @0x0002dcf0 (TOptionsDynamicCreate: new TOptions, sizeof 0x30)
|
||||
// game @0x0002d17c (ClassId: returns &TOptionsDynamicCreate)
|
||||
// game @0x0002d186 (GetTypeName, "TOptions")
|
||||
PFTYPEIMPL_DC(TOptions);
|
||||
|
||||
// game @0x0002d192 (D1) / game @0x0002d1a8 (D0)
|
||||
TOptions::~TOptions()
|
||||
{
|
||||
}
|
||||
|
||||
// game @0x0002d1ce
|
||||
void TOptions::PostChildrenInit(TWindowStyle& style)
|
||||
{
|
||||
TWindow* window = GetChildWindow("fullscreen", -1);
|
||||
TButton* button = window ? window->GetCast<TButton>() : NULL;
|
||||
if (button)
|
||||
{
|
||||
button->SetOn(TSettings::GetInstance()->IsFullScreen());
|
||||
}
|
||||
|
||||
int user = TSettings::GetInstance()->GetPreferences()->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
int soundOff = TSettings::GetInstance()->GetPreferences()->GetInt("soundoff", 0, user);
|
||||
window = GetChildWindow("mutebox", -1);
|
||||
button = window ? window->GetCast<TButton>() : NULL;
|
||||
if (button)
|
||||
{
|
||||
if (soundOff == 1)
|
||||
{
|
||||
button->SetOn(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
button->SetOn(false);
|
||||
TSettings::GetInstance()->SetSoundForCurrentUser();
|
||||
}
|
||||
}
|
||||
|
||||
window = GetChildWindow("sfxlevelslider", -1);
|
||||
TSlider* slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
user = TSettings::GetInstance()->GetPreferences()->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
int level = TSettings::GetInstance()->GetPreferences()->GetInt("soundlevel", DEFAULT_SOUND_VOLUME, user);
|
||||
slider->SetValue((float)level / 1000.0f, false);
|
||||
}
|
||||
|
||||
window = GetChildWindow("musiclevelslider", -1);
|
||||
slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
user = TSettings::GetInstance()->GetPreferences()->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
int level = TSettings::GetInstance()->GetPreferences()->GetInt("musiclevel", DEFAULT_MUSIC_VOLUME, user);
|
||||
slider->SetValue((float)level / 1000.0f, false);
|
||||
}
|
||||
|
||||
window = GetChildWindow("ambientlevelslider", -1);
|
||||
slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
user = TSettings::GetInstance()->GetPreferences()->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
int level = TSettings::GetInstance()->GetPreferences()->GetInt("ambientlevel", DEFAULT_AMBIENT_VOLUME, user);
|
||||
slider->SetValue((float)level / 1000.0f, false);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002d678
|
||||
// Lua: SaveVolumes().
|
||||
void TOptions::SaveVolumes()
|
||||
{
|
||||
TWindow* window = GetChildWindow("sfxlevelslider", -1);
|
||||
TSlider* slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
int user = TSettings::GetInstance()->GetPreferences()->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
float level = slider->GetValue() * 1000.0f;
|
||||
TSettings::GetInstance()->GetPreferences()->SetInt("soundlevel", (int)level, user, true);
|
||||
}
|
||||
|
||||
window = GetChildWindow("musiclevelslider", -1);
|
||||
slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
int user = TSettings::GetInstance()->GetPreferences()->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
float level = slider->GetValue() * 1000.0f;
|
||||
TSettings::GetInstance()->GetPreferences()->SetInt("musiclevel", (int)level, user, true);
|
||||
}
|
||||
|
||||
window = GetChildWindow("ambientlevelslider", -1);
|
||||
slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
int user = TSettings::GetInstance()->GetPreferences()->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
float level = slider->GetValue() * 1000.0f;
|
||||
TSettings::GetInstance()->GetPreferences()->SetInt("ambientlevel", (int)level, user, true);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x0002d98c
|
||||
bool TOptions::OnMessage(TMessage* message)
|
||||
{
|
||||
if (message->mType == TMessage::kSliderValChanged)
|
||||
{
|
||||
int user = TSettings::GetInstance()->GetPreferences()->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
bool soundOn = TSettings::GetInstance()->GetPreferences()->GetInt("soundoff", 0, user) != 1;
|
||||
|
||||
if (message->mName == str("sfxlevelslider"))
|
||||
{
|
||||
TWindow* window = GetChildWindow("sfxlevelslider", -1);
|
||||
TSlider* slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
float level = slider->GetValue();
|
||||
if (soundOn)
|
||||
{
|
||||
BSGSetSoundLevel(level);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (message->mName == str("musiclevelslider"))
|
||||
{
|
||||
TWindow* window = GetChildWindow("musiclevelslider", -1);
|
||||
TSlider* slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
float level = slider->GetValue();
|
||||
if (soundOn)
|
||||
{
|
||||
BSGSetMusicLevel(level);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (message->mName == str("ambientlevelslider"))
|
||||
{
|
||||
TWindow* window = GetChildWindow("ambientlevelslider", -1);
|
||||
TSlider* slider = window ? window->GetCast<TSlider>() : NULL;
|
||||
if (slider)
|
||||
{
|
||||
float level = slider->GetValue();
|
||||
if (soundOn)
|
||||
{
|
||||
BSGSetAmbientLevel(level);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x0002dc3e
|
||||
TOptions::TOptions()
|
||||
{
|
||||
TWindowManager* windowManager = TPlatform::GetInstance()->GetWindowManager();
|
||||
lua_pushstring(windowManager->GetScript()->GetState(), "SaveVolumes");
|
||||
lua_pushdirectclosure(windowManager->GetScript()->GetState(), this, &TOptions::SaveVolumes, 0);
|
||||
lua_settable(windowManager->GetScript()->GetState(), LUA_GLOBALSINDEX);
|
||||
}
|
||||
209
port/game/serversubmit.cpp
Normal file
209
port/game/serversubmit.cpp
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
// Port of the game's serversubmit.cpp (Chocolatier 3; PlayFirst skeleton code adapted by Big Splash Games):
|
||||
// TServerSubmit, the window that submits the current user's hiscore data to the server, and the Lua functions it
|
||||
// registers ("SubmitToServer", "GetLuaServerSubmitSetupVars"; window type "SubmitWindow").
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// serversubmit.h (port/game/serversubmit.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): TWindow 0x0..0x2f, mpPFHiscores 0x30; sizeof 0x34 (TServerSubmitDynamicCreate allocates 0x34).
|
||||
//
|
||||
// Notes on the game code:
|
||||
// - The constructor takes the hiscore store from TSettings (offset 4) and registers SubmitToServer as a member
|
||||
// direct function in the Lua globals; the destructor sets that global to nil again. Register adds the window type
|
||||
// "SubmitWindow" and binds GetLuaSetupVars (the script is looked up again for each of the three Lua calls).
|
||||
// - OnMessage handles only type 7 (kTextEditChanged): the "submittoserver" child is enabled (flag 0x100) when the
|
||||
// "nameedit" text is non-empty or, if it is empty, when the "accountedit" text is non-empty; otherwise it is
|
||||
// disabled and its OnMouseLeave virtual (vtable offset 0x4c) is called through GetCast<TButton>(). The screen is
|
||||
// invalidated and the message reported as handled; every other message returns false.
|
||||
// - OnTaskAnimate polls GetServerRequestStatus (512 byte message buffer). Status 2 (error): "submiterror" gets the
|
||||
// message text and is enabled, "submitconnect" is disabled and "submiterrorok" is enabled; the task goes on
|
||||
// (returns false, as the game does). Any other nonzero status keeps polling (returns true). Status 0 sets the Lua
|
||||
// global gReturnValue to 'qualified' or 'success' (when the data qualified for a global record or not) and pops the
|
||||
// parent modal window, named "%8x" of its ID; returns false.
|
||||
// - SubmitToServer: the mode is kSubmitMedal when medalsOnly, else kSubmitAll (0xFFFFFFFF). With an empty account
|
||||
// name the user name is stored in the prefs ("_anonusername", current user, saved) and the data is submitted
|
||||
// under that name with a null password and no remember flag; otherwise the account and password are used with the
|
||||
// remember flag. Then SwitchModes(true) and StartWindowAnimation(0x14).
|
||||
// - GetLuaSetupVars builds the Lua text "gNameEdit='<anon user name>'; " + (remembered login ?
|
||||
// "gAccountEdit='..'; gPassEdit='..'; gRemember=true; " : "gAccountEdit=''; gPassEdit=''; gRemember=false; ") +
|
||||
// (medalsMode ? "gMedalsMode=true;" : "gMedalsMode=false;" + "gEligibleScore=%d" of the local eligible score).
|
||||
//
|
||||
// Strings from the game's __cstring: "SwitchModes(%s)", "true", "false", "SubmitToServer", "nameedit"
|
||||
// (@0x0015a1a4), "accountedit" (@0x0015a1b0), "submittoserver", "submiterror", "submitconnect", "submiterrorok",
|
||||
// "gReturnValue='success'", "gReturnValue='qualified'", "%8x", "_anonusername", "gNameEdit='%s'; ",
|
||||
// "gAccountEdit='%s'; ", "gPassEdit='%s'; ", "gRemember=true; ", "gAccountEdit=''; gPassEdit=''; gRemember=false; ",
|
||||
// "gMedalsMode=true;", "gMedalsMode=false;", "gEligibleScore=%d", "SubmitWindow", "GetLuaServerSubmitSetupVars".
|
||||
//
|
||||
// Compiler-generated / header-inline code emitted out of line: TServerSubmit D1 game @0x00034acc, D0 game
|
||||
// @0x00034b40 (the destructor body above); the PFTYPEDEF_DC IsKindOf game @0x00173668 (compares the id against
|
||||
// &TServerSubmitDynamicCreate, else TWindow::ClassId); lua_pushdirectclosure<TServerSubmit, void
|
||||
// (TServerSubmit::*)(str, str, str, bool, bool)> game @0x00173558 and
|
||||
// lua_pushdirectclosure<str (*)(bool)> game @0x00173518 (called from Register), with
|
||||
// LPCD::ReturnSpecialization<void>::Call<TServerSubmit, str, str, str, bool, bool> game @0x00173694 and
|
||||
// DirectCallMemberDispatcherHelper<TServerSubmit, void (TServerSubmit::*)(str, str, str, bool, bool)> game
|
||||
// game @0x001737dc; ReturnSpecialization<str>::Call<bool> game @0x001735a4 and DirectCallFunctionDispatchHelper<str
|
||||
// (*)(bool)> game @0x00173630 (pf/luapluscd.h templates).
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "serversubmit.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include "pf/button.h"
|
||||
#include "pf/modalwindow.h"
|
||||
#include "pf/pfhiscores.h"
|
||||
#include "pf/platform.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/text.h"
|
||||
#include "pf/textedit.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
|
||||
// game @0x0003512c (TServerSubmitDynamicCreate: new TServerSubmit, sizeof 0x34)
|
||||
// game @0x00173668 (IsKindOf)
|
||||
PFTYPEIMPL_DC(TServerSubmit);
|
||||
|
||||
// game @0x00034a4c
|
||||
void TServerSubmit::SwitchModes(bool submit)
|
||||
{
|
||||
str command = str::getFormatted("SwitchModes(%s)", submit ? "true" : "false");
|
||||
TWindowManager::GetInstance()->GetScript()->DoLuaString(command, -1, 0);
|
||||
}
|
||||
|
||||
// game @0x00034acc (D1) / game @0x00034b40 (D0)
|
||||
TServerSubmit::~TServerSubmit()
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptUnregisterFunction(script, "SubmitToServer");
|
||||
}
|
||||
|
||||
// game @0x00034bbc
|
||||
bool TServerSubmit::OnMessage(TMessage* message)
|
||||
{
|
||||
if (message->mType == TMessage::kTextEditChanged) {
|
||||
TTextEdit* pNameEdit = GetChildWindow("nameedit", -1)->GetCast<TTextEdit>();
|
||||
TTextEdit* pAccountEdit = GetChildWindow("accountedit", -1)->GetCast<TTextEdit>();
|
||||
|
||||
bool enable;
|
||||
if (pNameEdit->GetText().length() == 0) {
|
||||
enable = pAccountEdit->GetText().length() != 0;
|
||||
} else {
|
||||
enable = true;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
TWindow* pButton = GetChildWindow("submittoserver", -1);
|
||||
pButton->SetFlags(pButton->GetFlags() | TWindow::kEnabled);
|
||||
} else {
|
||||
TWindow* pButton = GetChildWindow("submittoserver", -1);
|
||||
pButton->SetFlags(pButton->GetFlags() & ~TWindow::kEnabled);
|
||||
pButton->GetCast<TButton>()->OnMouseLeave();
|
||||
}
|
||||
|
||||
TWindowManager::GetInstance()->InvalidateScreen();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00034dda
|
||||
bool TServerSubmit::OnTaskAnimate()
|
||||
{
|
||||
char msg[512];
|
||||
bool qualified;
|
||||
|
||||
int status = mpPFHiscores->GetServerRequestStatus(msg, 0x200, &qualified);
|
||||
if (status == 2) {
|
||||
TWindow* w = GetChildWindow("submiterror", -1);
|
||||
if (w != 0) {
|
||||
TText* pText = w->GetCast<TText>();
|
||||
pText->SetFlags(pText->GetFlags() | TWindow::kEnabled);
|
||||
pText->SetText(str(msg));
|
||||
}
|
||||
w = GetChildWindow("submitconnect", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() & ~TWindow::kEnabled);
|
||||
}
|
||||
w = GetChildWindow("submiterrorok", -1);
|
||||
if (w != 0) {
|
||||
w->SetFlags(w->GetFlags() | TWindow::kEnabled);
|
||||
}
|
||||
} else {
|
||||
if (status != 0) {
|
||||
return true;
|
||||
}
|
||||
if (!qualified) {
|
||||
TWindowManager::GetInstance()->GetScript()->DoLuaString(str("gReturnValue='success'"), -1, 0);
|
||||
} else {
|
||||
TWindowManager::GetInstance()->GetScript()->DoLuaString(str("gReturnValue='qualified'"), -1, 0);
|
||||
}
|
||||
TModalWindow* pModal = FindParentModal();
|
||||
TPlatform::GetInstance()->GetWindowManager()->PopModal(pModal->GetID());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// game @0x00035084 (C1)
|
||||
TServerSubmit::TServerSubmit()
|
||||
{
|
||||
mpPFHiscores = TSettings::GetInstance()->GetHiscores();
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "SubmitToServer", this, TServerSubmit::SubmitToServer);
|
||||
}
|
||||
|
||||
// game @0x00035168
|
||||
str TServerSubmit::GetLuaSetupVars(bool medalsMode)
|
||||
{
|
||||
str result;
|
||||
str name;
|
||||
{
|
||||
int user = TSettings::GetInstance()->GetCurrentUser();
|
||||
name = TSettings::GetInstance()->GetPreferences()->GetStr("_anonusername", "", user);
|
||||
}
|
||||
result.format("gNameEdit='%s'; ", name.c_str());
|
||||
|
||||
str account;
|
||||
str pass;
|
||||
if (TSettings::GetInstance()->GetHiscores()->GetRememberedUserInfo(&account, &pass)) {
|
||||
result += str::getFormatted("gAccountEdit='%s'; ", account.c_str());
|
||||
result += str::getFormatted("gPassEdit='%s'; ", pass.c_str());
|
||||
result += str("gRemember=true; ");
|
||||
} else {
|
||||
result += str("gAccountEdit=''; gPassEdit=''; gRemember=false; ");
|
||||
}
|
||||
|
||||
if (medalsMode == true) {
|
||||
result += str("gMedalsMode=true;");
|
||||
} else {
|
||||
result += str("gMedalsMode=false;");
|
||||
int32_t score = 0;
|
||||
TSettings::GetInstance()->GetHiscores()->GetUserBestScore(TPfHiscores::eLocalEligible, &score, 0, 0, 0);
|
||||
result += str::getFormatted("gEligibleScore=%d", score);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// game @0x000354ce
|
||||
void TServerSubmit::SubmitToServer(str name, str account, str pass, bool remember, bool medalsOnly)
|
||||
{
|
||||
TPfHiscores::ESubmitMode mode = medalsOnly ? TPfHiscores::kSubmitMedal : TPfHiscores::kSubmitAll;
|
||||
|
||||
if (account.length() == 0) {
|
||||
int user = TSettings::GetInstance()->GetCurrentUser();
|
||||
TSettings::GetInstance()->GetPreferences()->SetStr("_anonusername", str(name), user, true);
|
||||
mpPFHiscores->SubmitData(str(name.c_str()), str((const char*)0), false, mode);
|
||||
} else {
|
||||
mpPFHiscores->SubmitData(str(account.c_str()), str(pass.c_str()), remember, mode);
|
||||
}
|
||||
|
||||
SwitchModes(true);
|
||||
StartWindowAnimation(0x14, true, true, false);
|
||||
}
|
||||
|
||||
// game @0x000356b2
|
||||
void TServerSubmit::Register()
|
||||
{
|
||||
TWindowManager::GetInstance()->AddWindowType("SubmitWindow", TServerSubmit::ClassId());
|
||||
ScriptRegisterDirect(TWindowManager::GetInstance()->GetScript(), "GetLuaServerSubmitSetupVars",
|
||||
TServerSubmit::GetLuaSetupVars);
|
||||
}
|
||||
285
port/game/settings.cpp
Normal file
285
port/game/settings.cpp
Normal file
|
|
@ -0,0 +1,285 @@
|
|||
// Port of the game's settings.cpp (Chocolatier 3; PlayFirst skeleton code adapted by Big Splash Games): TSettings,
|
||||
// the singleton that owns the prefs (TPrefs) and the hiscore store (TPfHiscores): users, full screen, sound
|
||||
// levels and mute, game mode, and the Lua functions for them (registered by the constructor).
|
||||
// Ported from the shipped game binary (release build, addresses "game @"); declarations from the original
|
||||
// settings.h (port/game/settings.h, unchanged).
|
||||
//
|
||||
// Layout (game, i386): mPreferences +0, mHiscores +4, mGameMode +8; sizeof 0xc (CreateSettings allocates 0xc).
|
||||
//
|
||||
// Game notes: GetCurrentUser and SetSoundForCurrentUser read "curuser" with default -1, ChangeCurrentUserName and
|
||||
// GetCurrentUserName with default 0. ToggleSoundMute stores (soundoff + 1) % 2 and mutes according to
|
||||
// TGameState::QueryMuteGame. SetCurrentUser and IsNameInUse compare with (int)GetNumUsers() (signed). DeleteUser
|
||||
// selects user - 1, or the last user when that is negative. Sound levels are prefs / 1000.0f (cvtsi2ss, divss).
|
||||
//
|
||||
// Header-inline code emitted out of line (pf/luapluscd.h templates): lua_pushdirectclosure<TSettings, F> for F =
|
||||
// bool () game @0x00173820, void (str) game @0x0017386c, void (int) game @0x001738b8,
|
||||
// bool (str) game @0x00173904, void () game @0x00173950, int () game @0x0017399c,
|
||||
// str () game @0x001739e8, str (int) game @0x00173a34;
|
||||
// LPCD::DirectCallMemberDispatcherHelper<TSettings, F>::DirectCallMemberDispatcher for F =
|
||||
// bool () game @0x00173ac4 (Call game @0x00173a80), str (int) game @0x00173de4 (Call game @0x00173ca8),
|
||||
// str () game @0x00173e28 (Call game @0x00173c18), int () game @0x00173e6c (Call game @0x00173b5c),
|
||||
// void () game @0x00173eb0, bool (str) game @0x00173ef8 (Call game @0x00173d58),
|
||||
// void (int) game @0x00173f3c (Call game @0x00173b08), void (str) game @0x00173f80 (Call game @0x00173ba0).
|
||||
//
|
||||
// Strings from the game's __cstring: "curuser", "fullscreen", "soundoff" (@0x00159e28), "name", "", "soundlevel",
|
||||
// "musiclevel", "ambientlevel", "%8x" (TWindow::GetID), and the registered names "ToggleFullScreen" ..
|
||||
// "GetUserName". key.h: PFGAMEMODENAMES.
|
||||
//
|
||||
// Static data: gSettings (__data @0x001d81e0, NULL). No static initializer.
|
||||
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include "BSGSound.h"
|
||||
#include "globaldefines.h"
|
||||
#include "key.h"
|
||||
|
||||
#include "pf/gamestate.h"
|
||||
#include "pf/modalwindow.h"
|
||||
#include "pf/script.h"
|
||||
#include "pf/windowmanager.h"
|
||||
|
||||
static TSettings* gSettings = NULL;
|
||||
|
||||
// game @0x00035774
|
||||
TSettings* TSettings::GetInstance()
|
||||
{
|
||||
return gSettings;
|
||||
}
|
||||
|
||||
// game @0x0003577e
|
||||
TSettings::~TSettings()
|
||||
{
|
||||
delete mPreferences;
|
||||
delete mHiscores;
|
||||
}
|
||||
|
||||
// game @0x000357c4
|
||||
void TSettings::DeleteSettings()
|
||||
{
|
||||
delete gSettings;
|
||||
gSettings = NULL;
|
||||
}
|
||||
|
||||
// game @0x000357f8
|
||||
int TSettings::GetCurrentUser()
|
||||
{
|
||||
return mPreferences->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
}
|
||||
|
||||
// game @0x0003585c
|
||||
bool TSettings::IsFullScreen()
|
||||
{
|
||||
return TPlatform::GetInstance()->IsFullscreen();
|
||||
}
|
||||
|
||||
// game @0x00035874
|
||||
void TSettings::UpdateFullScreen()
|
||||
{
|
||||
if (TPlatform::GetInstance()->IsFullscreen())
|
||||
{
|
||||
mPreferences->SetInt("fullscreen", 1, TPrefs::kGlobalIndex, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
mPreferences->SetInt("fullscreen", 0, TPrefs::kGlobalIndex, true);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00035928
|
||||
bool TSettings::ToggleFullScreen()
|
||||
{
|
||||
if (TPlatform::GetInstance()->IsFullscreen())
|
||||
{
|
||||
if (!TPlatform::GetInstance()->SetFullscreen(false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
mPreferences->SetInt("fullscreen", 0, TPrefs::kGlobalIndex, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!TPlatform::GetInstance()->SetFullscreen(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
mPreferences->SetInt("fullscreen", 1, TPrefs::kGlobalIndex, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// game @0x00035a1e
|
||||
void TSettings::ToggleSoundMute()
|
||||
{
|
||||
int user = mPreferences->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
int soundOff = mPreferences->GetInt("soundoff", 0, user);
|
||||
soundOff = (soundOff + 1) % 2;
|
||||
TGameState::GetInstance()->SetState(TGameState::kMute, soundOff);
|
||||
mPreferences->SetInt("soundoff", soundOff, user, true);
|
||||
BSGSoundMute(TGameState::GetInstance()->QueryMuteGame());
|
||||
}
|
||||
|
||||
// game @0x00035b6e
|
||||
void TSettings::SetCurrentGameMode(int gameMode)
|
||||
{
|
||||
if (gameMode >= eGameMode1 && gameMode < eMaxGameModes)
|
||||
{
|
||||
mGameMode = (eGameMode)gameMode;
|
||||
mHiscores->SetProperty(TPfHiscores::eGameMode, PFGAMEMODENAMES[gameMode]);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00035bd8
|
||||
void TSettings::ChangeCurrentUserName(str newName)
|
||||
{
|
||||
int user = mPreferences->GetInt("curuser", 0, TPrefs::kGlobalIndex);
|
||||
mPreferences->SetStr("name", newName, user, true);
|
||||
}
|
||||
|
||||
// game @0x00035ca6
|
||||
str TSettings::GetCurrentUserName()
|
||||
{
|
||||
int user = mPreferences->GetInt("curuser", 0, TPrefs::kGlobalIndex);
|
||||
return mPreferences->GetStr("name", "", user);
|
||||
}
|
||||
|
||||
// game @0x00035d7c
|
||||
str TSettings::GetUserName(int index)
|
||||
{
|
||||
return mPreferences->GetStr("name", "", index);
|
||||
}
|
||||
|
||||
// game @0x00035e0e
|
||||
int TSettings::GetNumUsers()
|
||||
{
|
||||
return mPreferences->GetNumUsers();
|
||||
}
|
||||
|
||||
// game @0x00035e20
|
||||
void TSettings::SetSoundForCurrentUser()
|
||||
{
|
||||
int user = mPreferences->GetInt("curuser", -1, TPrefs::kGlobalIndex);
|
||||
int soundLevel = mPreferences->GetInt("soundlevel", DEFAULT_SOUND_VOLUME, user);
|
||||
int musicLevel = mPreferences->GetInt("musiclevel", DEFAULT_MUSIC_VOLUME, user);
|
||||
int ambientLevel = mPreferences->GetInt("ambientlevel", DEFAULT_AMBIENT_VOLUME, user);
|
||||
BSGSetSoundLevel((float)soundLevel / 1000.0f);
|
||||
BSGSetMusicLevel((float)musicLevel / 1000.0f);
|
||||
BSGSetAmbientLevel((float)ambientLevel / 1000.0f);
|
||||
if (mPreferences->GetInt("soundoff", 0, user) == 1)
|
||||
{
|
||||
BSGSoundMute(true);
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x00035fda
|
||||
void TSettings::InitGameToSettings()
|
||||
{
|
||||
int fullScreen = mPreferences->GetInt("fullscreen", 1, TPrefs::kGlobalIndex);
|
||||
TPlatform::GetInstance()->SetDisplay(800, 600, fullScreen == 1);
|
||||
SetSoundForCurrentUser();
|
||||
}
|
||||
|
||||
// game @0x0003606c
|
||||
// Pops modal windows until the top one has no parent.
|
||||
void TSettings::QuitToMainMenu()
|
||||
{
|
||||
TWindowManager* windowManager = TWindowManager::GetInstance();
|
||||
while (windowManager->GetTopModalWindow() && windowManager->GetTopModalWindow()->GetParent())
|
||||
{
|
||||
windowManager->PopModal(windowManager->GetTopModalWindow()->GetID());
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000360ec
|
||||
void TSettings::SetCurrentUser(int userNum)
|
||||
{
|
||||
if (userNum < (int)mPreferences->GetNumUsers())
|
||||
{
|
||||
mPreferences->SetInt("curuser", userNum, TPrefs::kGlobalIndex, true);
|
||||
if (userNum >= 0)
|
||||
{
|
||||
mHiscores->SetProperty(TPfHiscores::ePlayerName, GetCurrentUserName().c_str());
|
||||
SetSoundForCurrentUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// game @0x000361dc
|
||||
// The new user (index = the old user count) gets the current user's sound settings, then becomes current.
|
||||
void TSettings::CreateNewUser(str userName)
|
||||
{
|
||||
int newUser = mPreferences->GetNumUsers();
|
||||
mPreferences->SetStr("name", userName, newUser, true);
|
||||
|
||||
int user = GetCurrentUser();
|
||||
int soundLevel = mPreferences->GetInt("soundlevel", DEFAULT_SOUND_VOLUME, user);
|
||||
int musicLevel = mPreferences->GetInt("musiclevel", DEFAULT_MUSIC_VOLUME, user);
|
||||
int ambientLevel = mPreferences->GetInt("ambientlevel", DEFAULT_AMBIENT_VOLUME, user);
|
||||
int soundOff = mPreferences->GetInt("soundoff", 0, user);
|
||||
|
||||
mPreferences->SetInt("soundlevel", soundLevel, newUser, true);
|
||||
mPreferences->SetInt("musiclevel", musicLevel, newUser, true);
|
||||
mPreferences->SetInt("ambientlevel", ambientLevel, newUser, true);
|
||||
mPreferences->SetInt("soundoff", soundOff, newUser, true);
|
||||
|
||||
SetCurrentUser(newUser);
|
||||
}
|
||||
|
||||
// game @0x0003649a
|
||||
TSettings::TSettings()
|
||||
{
|
||||
TScript* script = TWindowManager::GetInstance()->GetScript();
|
||||
ScriptRegisterMemberDirect(script, "ToggleFullScreen", this, TSettings::ToggleFullScreen);
|
||||
ScriptRegisterMemberDirect(script, "ToggleSoundMute", this, TSettings::ToggleSoundMute);
|
||||
ScriptRegisterMemberDirect(script, "SetCurrentGameMode", this, TSettings::SetCurrentGameMode);
|
||||
ScriptRegisterMemberDirect(script, "GetNumUsers", this, TSettings::GetNumUsers);
|
||||
ScriptRegisterMemberDirect(script, "CreateNewUser", this, TSettings::CreateNewUser);
|
||||
ScriptRegisterMemberDirect(script, "SetCurrentUser", this, TSettings::SetCurrentUser);
|
||||
ScriptRegisterMemberDirect(script, "ChangeCurrentUserName", this, TSettings::ChangeCurrentUserName);
|
||||
ScriptRegisterMemberDirect(script, "DeleteUser", this, TSettings::DeleteUser);
|
||||
ScriptRegisterMemberDirect(script, "IsNameInUse", this, TSettings::IsNameInUse);
|
||||
ScriptRegisterMemberDirect(script, "QuitToMainMenu", this, TSettings::QuitToMainMenu);
|
||||
ScriptRegisterMemberDirect(script, "GetCurrentUser", this, TSettings::GetCurrentUser);
|
||||
ScriptRegisterMemberDirect(script, "GetCurrentUserName", this, TSettings::GetCurrentUserName);
|
||||
ScriptRegisterMemberDirect(script, "GetUserName", this, TSettings::GetUserName);
|
||||
|
||||
mPreferences = new TPrefs(true);
|
||||
mHiscores = new TPfHiscores(true);
|
||||
SetCurrentGameMode(eGameMode1);
|
||||
SetCurrentUser(GetCurrentUser());
|
||||
}
|
||||
|
||||
// game @0x00036a8c
|
||||
TSettings* TSettings::CreateSettings()
|
||||
{
|
||||
delete gSettings;
|
||||
gSettings = new TSettings;
|
||||
return gSettings;
|
||||
}
|
||||
|
||||
// game @0x00036aea
|
||||
void TSettings::DeleteUser(int userNum)
|
||||
{
|
||||
mPreferences->DeleteUser(userNum);
|
||||
int newUser = userNum - 1;
|
||||
if (newUser < 0)
|
||||
{
|
||||
newUser = mPreferences->GetNumUsers() - 1;
|
||||
}
|
||||
SetCurrentUser(newUser);
|
||||
}
|
||||
|
||||
// game @0x00036b2c
|
||||
bool TSettings::IsNameInUse(str name)
|
||||
{
|
||||
int count = mPreferences->GetNumUsers();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (name == GetUserName(i))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
30
port/game/sseconv.h
Normal file
30
port/game/sseconv.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Port helper (no game counterpart): float -> integer conversions exactly as gcc 4.0 codes them for i386 with SSE
|
||||
// in the game's objects, where a plain C++ cast on the 64-bit host can give a different result outside the
|
||||
// target type's range.
|
||||
#ifndef GAME_SSECONV_H
|
||||
#define GAME_SSECONV_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// (uint32_t)double: minsd/maxsd clamp to [0, 4294967295] (a NaN takes the upper bound), 2^31 subtracted when the
|
||||
// unclamped value is >= 2^31 (cmplesd mask), cvttpd2dq, bit 31 restored. Constants in the game's __const, e.g.
|
||||
// @0x00192700 = {2147483648.0, 0.0, 4294967295.0, 0.0}. So < 0 -> 0, > 4294967295 -> 0xFFFFFFFF, NaN -> 0x80000000
|
||||
// (cvttpd2dq of 4294967295.0 is the integer indefinite).
|
||||
inline uint32_t SseDoubleToUInt32(double d)
|
||||
{
|
||||
bool big = (2147483648.0 <= d); // cmplesd
|
||||
double x = d;
|
||||
if (!(x < 4294967295.0)) x = 4294967295.0; // minsd x, 4294967295.0
|
||||
if (!(x > 0.0)) x = 0.0; // maxsd x, 0.0
|
||||
if (big) x -= 2147483648.0; // subsd (mask & 2^31)
|
||||
int32_t t = (x > -2147483649.0 && x < 2147483648.0) ? (int32_t)x : (int32_t)0x80000000u; // cvttpd2dq
|
||||
return (uint32_t)t ^ (big ? 0x80000000u : 0u);
|
||||
}
|
||||
|
||||
// (int32_t)double / (int32_t)float: cvttsd2si / cvttss2si; out of range and NaN give the integer indefinite.
|
||||
inline int32_t SseDoubleToInt32(double d)
|
||||
{
|
||||
return (d > -2147483649.0 && d < 2147483648.0) ? (int32_t)d : (int32_t)0x80000000u;
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue