From d8c21c57119660032c14ce46bca2f1168d12246f Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 29 Jun 2025 19:34:01 +0200 Subject: [PATCH] Add legacy mode inspired by the work of virtuallyfun/tenox7 Autodetect simcity.tcl in res/ and switch to legacy mode if it is found. Working with Simcity 2.17 ressources from for example Solaris. Sound is not yet working. --- src/sim/headers/sim.h | 1 + src/sim/sim.c | 1 + src/sim/w_tk.c | 23 ++++++++++++++++++++--- src/sim/w_update.c | 29 +++++++++++++++++++++-------- src/tk/tk.h | 2 ++ src/tk/tkcmds.c | 18 +++++++++++++++++- src/tk/tkwindow.c | 1 + 7 files changed, 63 insertions(+), 12 deletions(-) diff --git a/src/sim/headers/sim.h b/src/sim/headers/sim.h index f091977..9277b42 100644 --- a/src/sim/headers/sim.h +++ b/src/sim/headers/sim.h @@ -617,6 +617,7 @@ extern Sim *sim; extern int WireMode; extern int MultiPlayerMode; extern int SugarMode; +extern int LegacyMode; extern int sim_delay; extern int sim_skips; extern int sim_skip; diff --git a/src/sim/sim.c b/src/sim/sim.c index 21e4b41..60fef68 100644 --- a/src/sim/sim.c +++ b/src/sim/sim.c @@ -94,6 +94,7 @@ char *StartupName = NULL; int WireMode = 0; int MultiPlayerMode = 0; int SugarMode = 0; +int LegacyMode = 0; int TilesAnimated = 0; int DoAnimation = 1; int DoMessages = 1; diff --git a/src/sim/w_tk.c b/src/sim/w_tk.c index 991a201..686c7e8 100644 --- a/src/sim/w_tk.c +++ b/src/sim/w_tk.c @@ -793,7 +793,19 @@ void tk_main(void) sim = MakeNewSim(); - sprintf(initCmd, "source %s/micropolis.tcl", ResourceDir); + sprintf(initCmd, "%s/simcity.tcl", ResourceDir); + if (access(initCmd, R_OK) == 0) { + printf("Found %s, entering legacy mode.\n", initCmd); + LegacyMode = 1; + SugarMode = 0; + Eval("winfo-setlegacy"); + } + + if (!LegacyMode) { + sprintf(initCmd, "source %s/micropolis.tcl", ResourceDir); + } else { + sprintf(initCmd, "source %s/simcity.tcl", ResourceDir); + } filename2UNIX(initCmd); if (Eval(initCmd)) { sim_exit(1); // Just sets tkMustExit and ExitReturn @@ -810,8 +822,13 @@ void tk_main(void) { char buf[1024]; - sprintf(buf, "UIStartMicropolis {%s} {%s} {%s}", - HomeDir, ResourceDir, HostName); + if (!LegacyMode) { + sprintf(buf, "UIStartMicropolis {%s} {%s} {%s}", + HomeDir, ResourceDir, HostName); + } else { + sprintf(buf, "UIStartSimCity {%s} {%s} {} {%s}", + HomeDir, ResourceDir, HostName); + } filename2UNIX(buf); if (Eval(buf) != TCL_OK) { sim_exit(1); // Just sets tkMustExit and ExitReturn diff --git a/src/sim/w_update.c b/src/sim/w_update.c index 248a311..63c8ce0 100644 --- a/src/sim/w_update.c +++ b/src/sim/w_update.c @@ -195,9 +195,15 @@ updateDate(void) sprintf(str, "%s %d", dateStr[m], y); - sprintf(buf, - "UISetDate {%s} %d %d", - str, m, y); + if (!LegacyMode) { + sprintf(buf, + "UISetDate {%s} %d %d", + str, m, y); + } else { + sprintf(buf, + "UISetDate {%s}", + str); + } Eval(buf); } } @@ -278,11 +284,18 @@ void UpdateOptionsMenu(int options) { char buf[256]; - sprintf(buf, "UISetOptions %d %d %d %d %d %d %d %d", - (options&1)?1:0, (options&2)?1:0, - (options&4)?1:0, (options&8)?1:0, - (options&16)?1:0, (options&32)?1:0, - (options&64)?1:0, (options&128)?1:0); + if (!LegacyMode) { + sprintf(buf, "UISetOptions %d %d %d %d %d %d %d %d", + (options&1)?1:0, (options&2)?1:0, + (options&4)?1:0, (options&8)?1:0, + (options&16)?1:0, (options&32)?1:0, + (options&64)?1:0, (options&128)?1:0); + } else { + sprintf(buf, "UISetOptions %d %d %d %d %d %d", + (options&1)?1:0, (options&2)?1:0, + (options&4)?1:0, (options&8)?1:0, + (options&16)?1:0, (options&32)?1:0); + } Eval(buf); } diff --git a/src/tk/tk.h b/src/tk/tk.h index b70afb8..a102a6d 100644 --- a/src/tk/tk.h +++ b/src/tk/tk.h @@ -729,6 +729,8 @@ extern int Tk_UpdateCmd _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc, char **argv)); extern int Tk_WinfoCmd _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc, char **argv)); +extern int Tk_WinfoCmdSetLegacy _ANSI_ARGS_((ClientData clientData, + Tcl_Interp *interp, int argc, char **argv)); extern int Tk_WmCmd _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc, char **argv)); extern int Tcp_AcceptCmd _ANSI_ARGS_((ClientData clientData, diff --git a/src/tk/tkcmds.c b/src/tk/tkcmds.c index 14207ad..de83949 100644 --- a/src/tk/tkcmds.c +++ b/src/tk/tkcmds.c @@ -500,6 +500,22 @@ WaitWindowProc ( } } +static int LegacyMode = 0; + +int +Tk_WinfoCmdSetLegacy ( + ClientData clientData, /* Main window associated with + * interpreter. */ + Tcl_Interp *interp, /* Current interpreter. */ + int argc, /* Number of arguments. */ + char **argv /* Argument strings. */ +) +{ + LegacyMode = 1; + + return TCL_OK; +} + /* *---------------------------------------------------------------------- * @@ -750,7 +766,7 @@ Tk_WinfoCmd ( case PseudoColor: interp->result = "pseudocolor"; break; case GrayScale: interp->result = "grayscale"; break; case DirectColor: interp->result = "directcolor"; break; - case TrueColor: interp->result = "truecolor"; break; + case TrueColor: interp->result = LegacyMode?"pseudocolor":"truecolor"; break; case StaticColor: interp->result = "staticcolor"; break; case StaticGray: interp->result = "staticgray"; break; default: interp->result = "unknown"; break; diff --git a/src/tk/tkwindow.c b/src/tk/tkwindow.c index c7a7ed2..5f568e2 100644 --- a/src/tk/tkwindow.c +++ b/src/tk/tkwindow.c @@ -134,6 +134,7 @@ TkCmd commands[] = { {"tkwait", Tk_TkwaitCmd}, {"update", Tk_UpdateCmd}, {"winfo", Tk_WinfoCmd}, + {"winfo-setlegacy", Tk_WinfoCmdSetLegacy}, {"wm", Tk_WmCmd}, {"accept", Tcp_AcceptCmd}, {"shutdown", Tcp_ShutdownCmd}, -- 2.39.5