Skip to content

Commit

Permalink
Reorganize all of the MM player data into a dedicated table (`player.…
Browse files Browse the repository at this point in the history
…mm`)

This "code rewrite" also includes minor bug fixes
  • Loading branch information
LeonardoTheMutant committed Nov 11, 2024
1 parent 2c6179a commit c8aa441
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 494 deletions.
27 changes: 14 additions & 13 deletions SRC/DEV_DOCS/List_of_Func_and_Const.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ These are the functions that are used in [`GAME.LUA`](../LUA/MAIN//GAME.LUA) (th

| Name | Return value | Description |
| --- | --- | --- |
| <code>**MM_InitPlayer**(*player_t* player)</code> | nil | Initialize the <code>player.mm</code> table with some MM userdata for the player. |
| <code>**MM_AssignRoles**()</code> | nil | The main role assigner function. Called durring `MapLoad` hook and when another player joins the game with a single player online.<br>Iterates through all players and gives them the role of **Murderer**, **Sheriff** or **Innocent** randomly. Then it tells the assigned role to each player personally. |
| <code>**MM_GetRoleMultiplier**()</code> | nil | Get the number of the required role duplicates. It is primarily used in <code>**MM_AssignRoles()**</code> to understand how many players should share **Murderer** or **Sheriff** roles. It is also used to adjust the map timelimit when a level starts. |
| <code>**MM_ChatprintGlobal**(*string* message_id, * var)</code> | nil | Works similarly to <code>**chatprint**()</code> but prints the message in player's language. Unlike <code>**chatprint**()</code> this function can print only the messages available in the multilingual <code>MM.text</code> table. Possible values for the arguments of this function are shown below in the [Constants](#constants) section (`WIN_*` constants). |
Expand All @@ -73,17 +74,17 @@ Functions for HUD rendering code
| --- | --- | --- |
| <code>**V_LoadPatch**(*drawer* v, *string* patchName)</code> | nil | Load the Patch into the memory (<code>MM.graphics[patchName]</code>). |
| <code>**V_LoadCharset**(*drawer* v, *string* name)</code> | nil | Load the Character Set into the memory (<code>MM.graphics.charset[chrset_prefix]</code>). <code>name</code> is the 5-sign (no more, no less) patch prefix. This function will try to load 128 (256 for SRB2 built-in sets) patches named as `XXXXX###` where XXXXX is <code>name</code> and ### is a 3-digit number from 0 to 255. |
| <code>**V_DrawStrASCII**(*drawer* v, *int* x, *int* y, *string* charset, *string* str, [*int* videoflags, [*bool* small?]])</code> | nil | An alternative to <code>**v.drawString()**</code>. This function supports text rendering in different character encodings. <code>charset</code> specifies the character set to use (the character set has to be preloaded into the memory with <code>**V_loadCharset()**</code>). <code>str</code> is the string to render. If <code>small?</code> is set to `true`, it will draw the string in half of the normal size<br>*Note:* Each character from the Extended ASCII range (0x80-0xFF) should be typed as an escape code of the character in <code>str</code> string |
| <code>**V_DrawStrASCII**(*drawer* v, *int* x, *int* y, *string* charset, *string* str, [*int* videoflags, [*bool* small?]])</code> | nil | An alternative to <code>**v.drawString()**</code>. This function supports text rendering in different character encodings. <code>charset</code> specifies the character set to use (the character set has to be preloaded into the memory with <code>**V_loadCharset()**</code>). <code>str</code> is the string to render. If <code>small?</code> is set to `true`, it will draw the string in half of the normal size<br>*Note:* Each character from the Extended ASCII range (0x80-0xFF) should be typed as an escape code of the character in <code>str</code> string. |
| <code>**V_DrawStrASCII_Center**(*drawer* v, *int* x, *int* y, *string* charset, *string* str, [*int* videoflags, [*bool* small?]])</code> | nil | Alternative to <code>**v.drawString()**</code> with the `"center"` alignment flag. Uses <code>**V_DrawStrASCII()**</code> to render the string relatively centered. The <code>x</code> coordinate is the center. |
| <code>**V_DrawStrASCII_Right**(*drawer* v, *int* x, *int* y, *string* charset, *string* str, [*int* videoflags, [*bool* small?]])</code> | nil | Alternative to <code>**v.drawString()**</code> with the `"right"` alignment flag. Uses <code>**V_DrawStrASCII()**</code> to render the string right-aligned. The <code>x</code> coordinate is the right edge of the string. |
| <code>**V_StrWidthASCII**(*string* str, [*int* videoflags, [*bool* small?]])</code> | *int* | Alternative to the <code>**v.stringWidth**()</code> but for <code>**V_DrawStrASCII**()</code> drawing function. Get the width of the string in pixels, arguments like <code>videoflags</code> or <code>scale</code> are also accounted in the final size |
| <code>**V_ConvertStringColor**(*string* str)</code> | *string* | Converts the SRB2 text coloring symbols in <code>str</code> to MM format. Used for <code>**V_DrawStrASCII()**</code> function as it uses a different text coloring format. **Murder Mystery string format** is explained [here](./MM_HUD_Library.md) |
| <code>**V_ConvertStringColor2**(*string* str)</code> | *string* | Converts the MM text coloring symbols in <code>str</code> to SRB2 format. Used for <code>**v.drawString()**</code> to render the MM-formatted strings. **Murder Mystery string format** is explained [here](./MM_HUD_Library.md) |
| <code>**V_StrWidthASCII**(*string* str, [*int* videoflags, [*bool* small?]])</code> | *int* | Alternative to the <code>**v.stringWidth**()</code> but for <code>**V_DrawStrASCII**()</code> drawing function. Get the width of the string in pixels, arguments like <code>videoflags</code> or <code>scale</code> are also accounted in the final size. |
| <code>**V_ConvertStringColor**(*string* str)</code> | *string* | Converts the SRB2 text coloring symbols in <code>str</code> to MM format. Used for <code>**V_DrawStrASCII()**</code> function as it uses a different text coloring format. **Murder Mystery string format** is explained [here](./MM_HUD_Library.md). |
| <code>**V_ConvertStringColor2**(*string* str)</code> | *string* | Converts the MM text coloring symbols in <code>str</code> to SRB2 format. Used for <code>**v.drawString()**</code> to render the MM-formatted strings. **Murder Mystery string format** is explained [here](./MM_HUD_Library.md). |
| <code>**V_DrawTextPatch**(*drawer* v, *int* x, *int* y, *int* xoff, *int* yoff, string[]* data, *int* flags)</code> | nil | Draws a patch using the <code>data</code> in a text form at (x, y) coordinates (with the offset set by <code>xoff</code> and <code>yoff</code>). <code>data</code> is a table of strings, each table element represents a row and each symbol in <code>data[row]</code> corresponds to the color value from the SRB2's palette. |
| <code>**V_TextPatchWidth**(*string[]* data)</code> | *int* | Returns the width of the Text Patch in pixels |
| <code>**V_TextPatch_SwapColor**(*string[]* data, *int* sourceColor, *int* targetColor)</code> | *string[]* | Swaps each <code>sourceColor</code> pixel to <code>targetColor</code> in a Patch. This function returns the Patch with the swapped colors |
| <code>**V_GetTextPatchOffsetX**(*string* language, *string* patchname)</code> | *int* | Get the Patch's <code>x</code> offset coordinate from <code>MM.text[language][patchname.."_INFO"]</code> field (if exists) |
| <code>**V_GetTextPatchOffsetY**(*string* language, *string* patchname)</code> | *int* | Get the Patch's <code>y</code> offset coordinate from <code>MM.text[language][patchname.."_INFO"]</code> field (if exists) |
| <code>**V_TextPatchWidth**(*string[]* data)</code> | *int* | Returns the width of the Text Patch in pixels. |
| <code>**V_TextPatch_SwapColor**(*string[]* data, *int* sourceColor, *int* targetColor)</code> | *string[]* | Swaps each <code>sourceColor</code> pixel to <code>targetColor</code> in a Patch. This function returns the Patch with the swapped colors. |
| <code>**V_GetTextPatchOffsetX**(*string* language, *string* patchname)</code> | *int* | Get the Patch's <code>x</code> offset coordinate from <code>MM.text[language][patchname.."_INFO"]</code> field (if exists). |
| <code>**V_GetTextPatchOffsetY**(*string* language, *string* patchname)</code> | *int* | Get the Patch's <code>y</code> offset coordinate from <code>MM.text[language][patchname.."_INFO"]</code> field (if exists). |
| <code>**V_ScrollTextPatch_Vertical**(*string[]* patch, *int* offset, *boolean* side)</code> | *string[]* | Scroll the Text Patch vertically by <code>offset</code> pixels. By default, the patch is scrolled from right to left but if </code>side</code> is set to `true` the scroll happends from left to right istead. |

### `MINIGAME.LUA`
Expand All @@ -101,15 +102,15 @@ Functions that are used in more than one script

| Name | Return value | Description |
| --- | --- | --- |
| <code>**PlayerCount**([*int* role])</code> | *int* | Get the total number of players online. If the <code>role</code> is specified return the total number of players who have the <code>role</code> |
| <code>**PlayersAlive**()</code> | *int* | Get the number of players who are still alive (aren't spectators) |
| <code>**MM_SpawnSHREML**(*int* x, *int* y, *int* z, [*player_t* player])</code> | nil | Spawn the Sheriff's Emerald at (x, y, z) position. <code>player</code> argument is optional and is used only go get the timezone the Emerald was spawned in |
| <code>**PlayerCount**([*int* role])</code> | *int* | Get the total number of players online. If the <code>role</code> is specified return the total number of players who have the <code>role</code>. |
| <code>**PlayersAlive**()</code> | *int* | Get the number of players who are still alive (aren't spectators). |
| <code>**MM_SpawnSHREML**(*int* x, *int* y, *int* z, [*int* timezone])</code> | nil | Spawn the Sheriff's Emerald at (x, y, z) position. <code>timezone</code> argument is optional and is used only go get the timezone the Emerald was spawned in. |
| <code>**P_GetSectorCeilingZAt**(*sector_t* sector, *int* x, *int* y)</code> | *fixed_t* | Returns the height of the sector ceiling at (x, y), works both for regular sectors and slopes. Ported from SRB2 source code |
| <code>**P_GetFOFTopZAt**(*ffloor_t* fof, *int* x, *int* y)</code> | *fixed_t* | Returns the top height of the FOF at (x, y). Ported from SRB2 source code |
| <code>**P_GetFOFBottomZAt**(*ffloor_t* fof, *int* x, *int* y)</code> | *fixed_t* | Returns the bottom height of the FOF at (x, y). Ported from SRB2 source code |
| <code>**isExtendedASCII**(*string* str)</code> | *boolean* | Returns `true` if the <code>str</code> contains a symbol from Extended ASCII Range (`0x80` - `0xFF`) |
| <code>**isStandartASCII**(*string* str)</code> | *boolean* | Returns `true` if all characters in <code>str</code> are from Standart (Printable) ASCII range (`0x20` - `0x7F`) |
| <code>**valid**(* arg)</code> | *boolean* | Simply checks if both <code>arg</code> and <code>arg.valid</code> are true |
| <code>**isStandartASCII**(*string* str)</code> | *boolean* | Returns `true` if all characters in <code>str</code> are from Standart (Printable) ASCII range (`0x20` - `0x7F`). |
| <code>**valid**(* arg)</code> | *boolean* | Simply checks if both <code>arg</code> and <code>arg.valid</code> are true. |
| <code>**SOC_IsTrue**(* arg)</code> | *boolean* | Returns `true` if the <code>arg</code> says so (<code>"true"</code> as string will return `true`). Useful only for boolean-based SOC arguments. |

# Constants
Expand Down
4 changes: 2 additions & 2 deletions SRC/INIT.LUA
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ rawset(_G, "WEPCFG_DISABLERED", 2)

--Customization API
MM.AddLang = function(langID,langTbl)
if (not langID) error("Invalid Language Index") end
if (not langTbl) error("Invalid Language Table.") end
assert(langID, "Invalid Language Index")
assert(langTbl, "Invalid Language Table.")
if (type(langID) ~= "string") error("Language ID should be string and contain 2-3 characters long") end
if (type(langTbl) ~= "table") error("Language Talbe shoulb be table.") end
for l in pairs(MM.text)
Expand Down
6 changes: 3 additions & 3 deletions SRC/LUA/ABILITIES.LUA
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ addHook("PlayerThink", function(p)
p.mindash = skins[s].mindash
p.maxdash = skins[s].maxdash
p.normalspeed = skins[s].normalspeed
p.sneak = false
p.mm.sneak = false

--"Everyone are regular persons" mode (MM_ABILITIES disabled)
elseif ((gametype == GT_LTMMURDERMYSTERY) and (not MM_ABILITIES.value))
Expand All @@ -28,12 +28,12 @@ addHook("PlayerThink", function(p)
p.maxdash = 2621440 --40*FU
if ((p.cmd.buttons & BT_SPIN)) --sneaking
p.normalspeed = 196608 --3*FU
p.sneak = true
p.mm.sneak = true
--if (not p.speed) then p.state = S_PLAY_STND end
else
if (SOC_IsTrue(mapheaderinfo[gamemap].slowwalkspeed)) then p.normalspeed = 917504 --14*FU
else p.normalspeed = 1572864 end --24*FU
p.sneak = false
p.mm.sneak = false
end
end

Expand Down
Loading

0 comments on commit c8aa441

Please sign in to comment.