| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design) |
| 5 | * Copyright (c) 2017-2020, The LegacyClonk Team and contributors |
| 6 | * |
| 7 | * Distributed under the terms of the ISC license; see accompanying file |
| 8 | * "COPYING" for details. |
| 9 | * |
| 10 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 11 | * See accompanying file "TRADEMARK" for details. |
| 12 | * |
| 13 | * To redistribute this file separately, substitute the full license texts |
| 14 | * for the above references. |
| 15 | */ |
| 16 | |
| 17 | /* Some useful wrappers to globals */ |
| 18 | |
| 19 | #include <C4Include.h> |
| 20 | #include <C4Wrappers.h> |
| 21 | |
| 22 | #include <C4Random.h> |
| 23 | #include <C4Object.h> |
| 24 | |
| 25 | // Materials |
| 26 | |
| 27 | int32_t PixCol2MatOld(uint8_t pixc) |
| 28 | { |
| 29 | if (pixc < GBM) return MNone; |
| 30 | pixc &= 63; // Substract GBM, ignore IFT |
| 31 | if (pixc > Game.Material.Num * C4M_ColsPerMat - 1) return MNone; |
| 32 | return pixc / C4M_ColsPerMat; |
| 33 | } |
| 34 | |
| 35 | int32_t PixCol2MatOld2(uint8_t pixc) |
| 36 | { |
| 37 | int32_t iMat = (pixc & 0x7f) - 1; |
| 38 | // if above MVehic, don't forget additional vehicle-colors |
| 39 | if (iMat <= MVehic) return iMat; |
| 40 | // equals middle vehicle-color |
| 41 | if (iMat == MVehic + 1) return MVehic; |
| 42 | // above: range check |
| 43 | iMat -= 2; if (iMat >= Game.Material.Num) return MNone; |
| 44 | return iMat; |
| 45 | } |
| 46 | |
| 47 | // Graphics Resource |
| 48 | |
| 49 | #define GfxR (&(Game.GraphicsResource)) |
| 50 | |
| 51 | // Messages |
| 52 | |
| 53 | void GameMsgObject(const char *szText, C4Object *pTarget, int32_t iFCol) |
| 54 | { |
| 55 | Game.Messages.New(iType: C4GM_Target, szText, pTarget, iPlayer: NO_OWNER, iX: 0, iY: 0, bCol: static_cast<uint8_t>(iFCol)); |
| 56 | } |
| 57 | |
| 58 | void GameMsgObjectPlayer(const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iFCol) |
| 59 | { |
| 60 | Game.Messages.New(iType: C4GM_TargetPlayer, szText, pTarget, iPlayer, iX: 0, iY: 0, bCol: static_cast<uint8_t>(iFCol)); |
| 61 | } |
| 62 | |
| 63 | void GameMsgGlobal(const char *szText, int32_t iFCol) |
| 64 | { |
| 65 | Game.Messages.New(iType: C4GM_Global, szText, pTarget: nullptr, iPlayer: ANY_OWNER, iX: 0, iY: 0, bCol: static_cast<uint8_t>(iFCol)); |
| 66 | } |
| 67 | |
| 68 | void GameMsgPlayer(const char *szText, int32_t iPlayer, int32_t iFCol) |
| 69 | { |
| 70 | Game.Messages.New(iType: C4GM_GlobalPlayer, szText, pTarget: nullptr, iPlayer, iX: 0, iY: 0, bCol: static_cast<uint8_t>(iFCol)); |
| 71 | } |
| 72 | |
| 73 | void GameMsgObjectDw(const char *szText, C4Object *pTarget, uint32_t dwClr) |
| 74 | { |
| 75 | Game.Messages.New(iType: C4GM_Target, szText, pTarget, iPlayer: NO_OWNER, iX: 0, iY: 0, dwClr); |
| 76 | } |
| 77 | |
| 78 | // Players |
| 79 | |
| 80 | int32_t ValidPlr(int32_t plr) |
| 81 | { |
| 82 | return Game.Players.Valid(iPlayer: plr); |
| 83 | } |
| 84 | |
| 85 | int32_t Hostile(int32_t plr1, int32_t plr2) |
| 86 | { |
| 87 | return Game.Players.Hostile(iPlayer1: plr1, iPlayer2: plr2); |
| 88 | } |
| 89 | |
| 90 | // StdCompiler |
| 91 | |
| 92 | void StdCompilerWarnCallback(void *pData, const char *szPosition, const char *szError) |
| 93 | { |
| 94 | const char *szName = reinterpret_cast<const char *>(pData); |
| 95 | if (!szPosition || !*szPosition) |
| 96 | DebugLog(level: spdlog::level::warn ,fmt: "{} (in {})" , args&: szError, args&: szName); |
| 97 | else |
| 98 | DebugLog(level: spdlog::level::warn, fmt: "{} (in {}, {})" , args&: szError, args&: szPosition, args&: szName); |
| 99 | } |
| 100 | |