From 73d354b956aa4e9693391a177da1ca70302a4bca Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 18 Feb 2024 11:29:00 -0500 Subject: [PATCH] Bring back WRITETHINGS, with custom filename and UDMF support! --- src/m_cheat.c | 14 ++++- src/m_cheat.h | 2 +- src/netcode/d_netcmd.c | 2 +- src/p_setup.c | 127 +++++++++++++++++++++++++---------------- src/p_setup.h | 2 +- 5 files changed, 91 insertions(+), 56 deletions(-) diff --git a/src/m_cheat.c b/src/m_cheat.c index e61db2c2e..5eea4a69f 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -1424,14 +1424,22 @@ void OP_ObjectplaceMovement(player_t *player) // // Objectplace related commands. // -/*void Command_Writethings_f(void) +void Command_Writethings_f(void) { REQUIRE_INLEVEL; REQUIRE_SINGLEPLAYER; REQUIRE_OBJECTPLACE; - P_WriteThings(); -}*/ + if (COM_Argc() > 1) + { + P_WriteThings(COM_Argv(1)); + } + else + { + CONS_Printf(M_GetText("writethings : write out map things to a file, .txt or .lmp automatically appended.\n")); + return; + } +} void Command_ObjectPlace_f(void) { diff --git a/src/m_cheat.h b/src/m_cheat.h index f4ac01d84..564c6da77 100644 --- a/src/m_cheat.h +++ b/src/m_cheat.h @@ -26,7 +26,7 @@ void cht_Init(void); // ObjectPlace // void Command_ObjectPlace_f(void); -//void Command_Writethings_f(void); +void Command_Writethings_f(void); extern consvar_t cv_opflags, cv_ophoopflags, cv_mapthingnum, cv_speed; //extern consvar_t cv_snapto, cv_grid; diff --git a/src/netcode/d_netcmd.c b/src/netcode/d_netcmd.c index bb098e029..b746c30fb 100644 --- a/src/netcode/d_netcmd.c +++ b/src/netcode/d_netcmd.c @@ -908,7 +908,7 @@ void D_RegisterClientCommands(void) // ingame object placing COM_AddCommand("objectplace", Command_ObjectPlace_f, COM_LUA); - //COM_AddCommand("writethings", Command_Writethings_f); + COM_AddCommand("writethings", Command_Writethings_f, COM_LUA); CV_RegisterVar(&cv_speed); CV_RegisterVar(&cv_opflags); CV_RegisterVar(&cv_ophoopflags); diff --git a/src/p_setup.c b/src/p_setup.c index 1d985beb4..b0c39925e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -877,14 +877,32 @@ static void P_SpawnMapThings(boolean spawnemblems) P_SpawnEmeraldHunt(); } +static void P_WriteTextmap_Things(FILE *f, const mapthing_t *wmapthings); // proto + // Experimental groovy write function! -/*void P_WriteThings(void) +void P_WriteThings(const char *filepath) { size_t i, length; mapthing_t *mt; UINT8 *savebuffer, *savebuf_p; INT16 temp; + if (udmf) + { + FILE *f = fopen(va("%s.txt", filepath), "w"); + if (!f) + { + CONS_Alert(CONS_ERROR, M_GetText("Couldn't write to file %s\n"), filepath); + return; + } + + P_WriteTextmap_Things(f, mapthings); + fclose(f); + + CONS_Printf(M_GetText("%s.txt saved.\n"), filepath); + return; + } + savebuf_p = savebuffer = (UINT8 *)malloc(nummapthings * sizeof (mapthing_t)); if (!savebuf_p) @@ -908,12 +926,12 @@ static void P_SpawnMapThings(boolean spawnemblems) length = savebuf_p - savebuffer; - FIL_WriteFile(va("newthings%d.lmp", gamemap), savebuffer, length); + FIL_WriteFile(va("%s.lmp", filepath), savebuffer, length); free(savebuffer); savebuf_p = NULL; - CONS_Printf(M_GetText("newthings%d.lmp saved.\n"), gamemap); -}*/ + CONS_Printf(M_GetText("%s.lmp saved.\n"), filepath); +} // // MAP LOADING FUNCTIONS @@ -2144,6 +2162,60 @@ typedef struct mapthing_t *angleanchor; } sectorspecialthings_t; +static void P_WriteTextmap_Things(FILE *f, const mapthing_t *wmapthings) +{ + size_t i, j; + mtag_t firsttag; + + // Actual writing + for (i = 0; i < nummapthings; i++) + { + fprintf(f, "thing // %s\n", sizeu1(i)); + fprintf(f, "{\n"); + firsttag = Tag_FGet(&wmapthings[i].tags); + if (firsttag != 0) + fprintf(f, "id = %d;\n", firsttag); + if (wmapthings[i].tags.count > 1) + { + fprintf(f, "moreids = \""); + for (j = 1; j < wmapthings[i].tags.count; j++) + { + if (j > 1) + fprintf(f, " "); + fprintf(f, "%d", wmapthings[i].tags.tags[j]); + } + fprintf(f, "\";\n"); + } + fprintf(f, "x = %d;\n", wmapthings[i].x); + fprintf(f, "y = %d;\n", wmapthings[i].y); + if (wmapthings[i].z != 0) + fprintf(f, "height = %d;\n", wmapthings[i].z); + fprintf(f, "angle = %d;\n", wmapthings[i].angle); + if (wmapthings[i].pitch != 0) + fprintf(f, "pitch = %d;\n", wmapthings[i].pitch); + if (wmapthings[i].roll != 0) + fprintf(f, "roll = %d;\n", wmapthings[i].roll); + if (wmapthings[i].type != 0) + fprintf(f, "type = %d;\n", wmapthings[i].type); + if (wmapthings[i].spritexscale != FRACUNIT) + fprintf(f, "scalex = %f;\n", FIXED_TO_FLOAT(wmapthings[i].spritexscale)); + if (wmapthings[i].spriteyscale != FRACUNIT) + fprintf(f, "scaley = %f;\n", FIXED_TO_FLOAT(wmapthings[i].spriteyscale)); + if (wmapthings[i].scale != FRACUNIT) + fprintf(f, "mobjscale = %f;\n", FIXED_TO_FLOAT(wmapthings[i].scale)); + if (wmapthings[i].options & MTF_OBJECTFLIP) + fprintf(f, "flip = true;\n"); + for (j = 0; j < NUMMAPTHINGARGS; j++) + if (wmapthings[i].args[j] != 0) + fprintf(f, "arg%s = %d;\n", sizeu1(j), wmapthings[i].args[j]); + for (j = 0; j < NUMMAPTHINGSTRINGARGS; j++) + if (mapthings[i].stringargs[j]) + fprintf(f, "stringarg%s = \"%s\";\n", sizeu1(j), mapthings[i].stringargs[j]); + fprintf(f, "}\n"); + fprintf(f, "\n"); + } +} + static void P_WriteTextmap(void) { size_t i, j; @@ -2411,52 +2483,7 @@ static void P_WriteTextmap(void) } fprintf(f, "namespace = \"srb2\";\n"); - for (i = 0; i < nummapthings; i++) - { - fprintf(f, "thing // %s\n", sizeu1(i)); - fprintf(f, "{\n"); - firsttag = Tag_FGet(&wmapthings[i].tags); - if (firsttag != 0) - fprintf(f, "id = %d;\n", firsttag); - if (wmapthings[i].tags.count > 1) - { - fprintf(f, "moreids = \""); - for (j = 1; j < wmapthings[i].tags.count; j++) - { - if (j > 1) - fprintf(f, " "); - fprintf(f, "%d", wmapthings[i].tags.tags[j]); - } - fprintf(f, "\";\n"); - } - fprintf(f, "x = %d;\n", wmapthings[i].x); - fprintf(f, "y = %d;\n", wmapthings[i].y); - if (wmapthings[i].z != 0) - fprintf(f, "height = %d;\n", wmapthings[i].z); - fprintf(f, "angle = %d;\n", wmapthings[i].angle); - if (wmapthings[i].pitch != 0) - fprintf(f, "pitch = %d;\n", wmapthings[i].pitch); - if (wmapthings[i].roll != 0) - fprintf(f, "roll = %d;\n", wmapthings[i].roll); - if (wmapthings[i].type != 0) - fprintf(f, "type = %d;\n", wmapthings[i].type); - if (wmapthings[i].spritexscale != FRACUNIT) - fprintf(f, "scalex = %f;\n", FIXED_TO_FLOAT(wmapthings[i].spritexscale)); - if (wmapthings[i].spriteyscale != FRACUNIT) - fprintf(f, "scaley = %f;\n", FIXED_TO_FLOAT(wmapthings[i].spriteyscale)); - if (wmapthings[i].scale != FRACUNIT) - fprintf(f, "mobjscale = %f;\n", FIXED_TO_FLOAT(wmapthings[i].scale)); - if (wmapthings[i].options & MTF_OBJECTFLIP) - fprintf(f, "flip = true;\n"); - for (j = 0; j < NUMMAPTHINGARGS; j++) - if (wmapthings[i].args[j] != 0) - fprintf(f, "arg%s = %d;\n", sizeu1(j), wmapthings[i].args[j]); - for (j = 0; j < NUMMAPTHINGSTRINGARGS; j++) - if (mapthings[i].stringargs[j]) - fprintf(f, "stringarg%s = \"%s\";\n", sizeu1(j), mapthings[i].stringargs[j]); - fprintf(f, "}\n"); - fprintf(f, "\n"); - } + P_WriteTextmap_Things(f, wmapthings); for (i = 0; i < numvertexes; i++) { diff --git a/src/p_setup.h b/src/p_setup.h index f9e51024d..61c445c65 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -71,7 +71,7 @@ boolean P_AddFolder(const char *folderpath); boolean P_RunSOC(const char *socfilename); void P_LoadSoundsRange(UINT16 wadnum, UINT16 first, UINT16 num); void P_LoadMusicsRange(UINT16 wadnum, UINT16 first, UINT16 num); -//void P_WriteThings(void); +void P_WriteThings(const char *filepath); size_t P_PrecacheLevelFlats(void); void P_AllocMapHeader(INT16 i);