mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Also add a console command to enable map compatibility mode
This commit is contained in:
parent
b9cdacbb37
commit
81aeb30654
|
@ -669,6 +669,7 @@ set_glob(GAME_SHARED GLOB src/game
|
|||
localization.h
|
||||
mapbugs.cpp
|
||||
mapbugs.h
|
||||
mapbugs_list.h
|
||||
mapitems.cpp
|
||||
mapitems.h
|
||||
teamscore.cpp
|
||||
|
|
|
@ -43,6 +43,7 @@ CMapBugs GetMapBugs(const char *pName, int Size, int Crc)
|
|||
{
|
||||
CMapDescription Map = {pName, Size, Crc};
|
||||
CMapBugs Result;
|
||||
Result.m_Extra = 0;
|
||||
for(unsigned int i = 0; i < sizeof(MAP_BUGS) / sizeof(MAP_BUGS[0]); i++)
|
||||
{
|
||||
if(Map == MAP_BUGS[i].m_Map)
|
||||
|
@ -60,27 +61,59 @@ bool CMapBugs::Contains(int Bug) const
|
|||
CMapBugsInternal *pInternal = (CMapBugsInternal *)m_pData;
|
||||
if(!pInternal)
|
||||
{
|
||||
return false;
|
||||
return IsBugFlagSet(Bug, m_Extra);
|
||||
}
|
||||
return IsBugFlagSet(Bug, pInternal->m_BugFlags);
|
||||
}
|
||||
|
||||
int CMapBugs::Update(const char *pBug)
|
||||
{
|
||||
CMapBugsInternal *pInternal = (CMapBugsInternal *)m_pData;
|
||||
int Bug = -1;
|
||||
if(false) {}
|
||||
#define MAPBUG(constname, string) else if(str_comp(pBug, string) == 0) { Bug = constname; }
|
||||
#include "mapbugs_list.h"
|
||||
#undef MAPBUG
|
||||
if(Bug == -1)
|
||||
{
|
||||
return MAPBUGUPDATE_NOTFOUND;
|
||||
}
|
||||
if(pInternal)
|
||||
{
|
||||
return MAPBUGUPDATE_OVERRIDDEN;
|
||||
}
|
||||
m_Extra |= BugToFlag(Bug);
|
||||
return MAPBUGUPDATE_OK;
|
||||
}
|
||||
|
||||
void CMapBugs::Dump() const
|
||||
{
|
||||
CMapBugsInternal *pInternal = (CMapBugsInternal *)m_pData;
|
||||
if(!pInternal)
|
||||
unsigned int Flags;
|
||||
if(pInternal)
|
||||
{
|
||||
Flags = pInternal->m_BugFlags;
|
||||
}
|
||||
else if(m_Extra)
|
||||
{
|
||||
Flags = m_Extra;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
char aBugs[NUM_BUGS + 1] = {0};
|
||||
for(int i = 0; i < NUM_BUGS; i++)
|
||||
{
|
||||
aBugs[i] = IsBugFlagSet(i, pInternal->m_BugFlags) ? 'X' : 'O';
|
||||
aBugs[i] = IsBugFlagSet(i, Flags) ? 'X' : 'O';
|
||||
}
|
||||
|
||||
dbg_msg("mapbugs", "enabling map compatibility mode %s", aBugs);
|
||||
dbg_msg("mapbugs", "map='%s' map_size=%d map_crc=%08x",
|
||||
pInternal->m_Map.m_pName,
|
||||
pInternal->m_Map.m_Size,
|
||||
pInternal->m_Map.m_Crc);
|
||||
if(pInternal)
|
||||
{
|
||||
dbg_msg("mapbugs", "map='%s' map_size=%d map_crc=%08x",
|
||||
pInternal->m_Map.m_pName,
|
||||
pInternal->m_Map.m_Size,
|
||||
pInternal->m_Map.m_Crc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,17 +3,28 @@
|
|||
|
||||
enum
|
||||
{
|
||||
BUG_GRENADE_DOUBLEEXPLOSION=0,
|
||||
#define MAPBUG(constname, string) constname,
|
||||
#include "mapbugs_list.h"
|
||||
#undef MAPBUG
|
||||
NUM_BUGS,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MAPBUGUPDATE_OK,
|
||||
MAPBUGUPDATE_NOTFOUND,
|
||||
MAPBUGUPDATE_OVERRIDDEN,
|
||||
};
|
||||
|
||||
class CMapBugs
|
||||
{
|
||||
friend CMapBugs GetMapBugs(const char *pName, int Size, int Crc);
|
||||
void *m_pData;
|
||||
unsigned int m_Extra;
|
||||
|
||||
public:
|
||||
bool Contains(int Bug) const;
|
||||
int Update(const char *pBug);
|
||||
void Dump() const;
|
||||
};
|
||||
|
||||
|
|
1
src/game/mapbugs_list.h
Normal file
1
src/game/mapbugs_list.h
Normal file
|
@ -0,0 +1 @@
|
|||
MAPBUG(BUG_GRENADE_DOUBLEEXPLOSION, "grenade-doubleexplosion@ddnet.tw")
|
|
@ -2027,6 +2027,38 @@ void CGameContext::ConTuneSetZoneMsgLeave(IConsole::IResult *pResult, void *pUse
|
|||
}
|
||||
}
|
||||
|
||||
void CGameContext::ConMapbug(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
const char *pMapBugName = pResult->GetString(0);
|
||||
|
||||
if(pSelf->m_pController)
|
||||
{
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "mapbugs", "can't add map bugs after the game started");
|
||||
return;
|
||||
}
|
||||
|
||||
switch(pSelf->m_MapBugs.Update(pMapBugName))
|
||||
{
|
||||
case MAPBUGUPDATE_OK:
|
||||
break;
|
||||
case MAPBUGUPDATE_OVERRIDDEN:
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "mapbugs", "map-internal setting overridden by database");
|
||||
break;
|
||||
case MAPBUGUPDATE_NOTFOUND:
|
||||
{
|
||||
char aBuf[64];
|
||||
str_format(aBuf, sizeof(aBuf), "unknown map bug '%s', ignoring", pMapBugName);
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "mapbugs", aBuf);
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
dbg_assert(0, "unreachable");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CGameContext::ConSwitchOpen(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
|
@ -2479,6 +2511,7 @@ void CGameContext::OnConsoleInit()
|
|||
Console()->Register("tune_zone_reset", "?i[zone]", CFGFLAG_SERVER, ConTuneResetZone, this, "reset zone tuning in zone x or in all zones");
|
||||
Console()->Register("tune_zone_enter", "i[zone] s[message]", CFGFLAG_SERVER|CFGFLAG_GAME, ConTuneSetZoneMsgEnter, this, "which message to display on zone enter; use 0 for normal area");
|
||||
Console()->Register("tune_zone_leave", "i[zone] s[message]", CFGFLAG_SERVER|CFGFLAG_GAME, ConTuneSetZoneMsgLeave, this, "which message to display on zone leave; use 0 for normal area");
|
||||
Console()->Register("mapbug", "s[mapbug]", CFGFLAG_SERVER|CFGFLAG_GAME, ConMapbug, this, "Enable map compatibility mode using the specified bug (example: grenade-doublexplosion@ddnet.tw)");
|
||||
Console()->Register("switch_open", "i['0'|'1']", CFGFLAG_SERVER|CFGFLAG_GAME, ConSwitchOpen, this, "Whether a switch is open by default (otherwise closed)");
|
||||
Console()->Register("pause_game", "", CFGFLAG_SERVER, ConPause, this, "Pause/unpause game");
|
||||
Console()->Register("change_map", "?r[map]", CFGFLAG_SERVER|CFGFLAG_STORE, ConChangeMap, this, "Change map");
|
||||
|
@ -2531,7 +2564,6 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
int MapCrc;
|
||||
Server()->GetMapInfo(aMapName, sizeof(aMapName), &MapSize, &MapCrc);
|
||||
m_MapBugs = GetMapBugs(aMapName, MapSize, MapCrc);
|
||||
m_MapBugs.Dump();
|
||||
|
||||
// reset everything here
|
||||
//world = new GAMEWORLD;
|
||||
|
@ -2589,6 +2621,8 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
|
||||
LoadMapSettings();
|
||||
|
||||
m_MapBugs.Dump();
|
||||
|
||||
m_pController = new CGameControllerDDRace(this);
|
||||
((CGameControllerDDRace*)m_pController)->m_Teams.Reset();
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ class CGameContext : public IGameServer
|
|||
static void ConTuneResetZone(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConTuneSetZoneMsgEnter(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConTuneSetZoneMsgLeave(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConMapbug(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConSwitchOpen(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConPause(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConChangeMap(IConsole::IResult *pResult, void *pUserData);
|
||||
|
|
|
@ -11,6 +11,24 @@ TEST(MapBugs, Contains)
|
|||
EXPECT_FALSE(GetMapBugs("dm1", 5805, 0xf2159e6e).Contains(BUG_GRENADE_DOUBLEEXPLOSION));
|
||||
}
|
||||
|
||||
TEST(MapBugs, Update)
|
||||
{
|
||||
{
|
||||
CMapBugs Binary = GetMapBugs("Binary", 2022597, 0x0ae3a3d5);
|
||||
EXPECT_EQ(Binary.Update("grenade-doubleexplosion@ddnet.tw"), MAPBUGUPDATE_OVERRIDDEN);
|
||||
EXPECT_EQ(Binary.Update("doesntexist@invalid"), MAPBUGUPDATE_NOTFOUND);
|
||||
EXPECT_TRUE(Binary.Contains(BUG_GRENADE_DOUBLEEXPLOSION));
|
||||
}
|
||||
{
|
||||
CMapBugs Dm1 = GetMapBugs("dm1", 5805, 0xf2159e6e);
|
||||
EXPECT_FALSE(Dm1.Contains(BUG_GRENADE_DOUBLEEXPLOSION));
|
||||
EXPECT_EQ(Dm1.Update("doesntexist@invalid"), MAPBUGUPDATE_NOTFOUND);
|
||||
EXPECT_FALSE(Dm1.Contains(BUG_GRENADE_DOUBLEEXPLOSION));
|
||||
EXPECT_EQ(Dm1.Update("grenade-doubleexplosion@ddnet.tw"), MAPBUGUPDATE_OK);
|
||||
EXPECT_TRUE(Dm1.Contains(BUG_GRENADE_DOUBLEEXPLOSION));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MapBugs, Dump)
|
||||
{
|
||||
GetMapBugs("Binary", 2022597, 0x0ae3a3d5).Dump();
|
||||
|
|
Loading…
Reference in a new issue