debug spawn command with configurable monster count
This commit is contained in:
parent
d47d2e3030
commit
7d86991534
1 changed files with 73 additions and 65 deletions
|
|
@ -479,34 +479,36 @@ std::string DebugCmdLevelSeed(const string_view parameter)
|
|||
return fmt::format("Seedinfo for level {}\nseed: {}\nMid1: {}\nMid2: {}\nMid3: {}\nEnd: {}", currlevel, glSeedTbl[currlevel], glMid1Seed[currlevel], glMid2Seed[currlevel], glMid3Seed[currlevel], glEndSeed[currlevel]);
|
||||
}
|
||||
|
||||
std::string DebugSpawnMonster(const string_view parameter, int count)
|
||||
bool is_number(const std::string &s)
|
||||
{
|
||||
if (ActiveMonsterCount >= MAXMONSTERS)
|
||||
return "Too many monsters!";
|
||||
return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
|
||||
}
|
||||
|
||||
std::string name(parameter.data());
|
||||
if (name == "")
|
||||
return "Give monster name!";
|
||||
std::string DebugCmdSpawnMonster(const string_view parameter)
|
||||
{
|
||||
if (currlevel == 0)
|
||||
return "Do you want to kill the towners?!?";
|
||||
|
||||
std::stringstream paramsStream(parameter.data());
|
||||
std::string name;
|
||||
int count = 1;
|
||||
if (std::getline(paramsStream, name, ' ')) {
|
||||
count = atoi(name.c_str());
|
||||
if (count > 0)
|
||||
name.clear();
|
||||
else
|
||||
count = 1;
|
||||
std::getline(paramsStream, name, ' ');
|
||||
}
|
||||
|
||||
std::string singleWord;
|
||||
while (std::getline(paramsStream, singleWord, ' ')) {
|
||||
name.append(" ");
|
||||
name.append(singleWord);
|
||||
}
|
||||
|
||||
std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
|
||||
auto &myPlayer = Players[MyPlayerId];
|
||||
|
||||
auto isTileOk = [](Point position) {
|
||||
if (dPlayer[position.x][position.y] != 0 || dMonster[position.x][position.y] != 0)
|
||||
return false;
|
||||
if (!IsTileWalkable(position))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
int counter = 0;
|
||||
|
||||
for (auto dir : left) {
|
||||
Point pos = myPlayer.position.tile + dir;
|
||||
if (!isTileOk(pos))
|
||||
continue;
|
||||
|
||||
int mtype = -1;
|
||||
for (int i = 0; i < 138; i++) {
|
||||
auto mondata = MonstersData[i];
|
||||
|
|
@ -551,25 +553,32 @@ std::string DebugSpawnMonster(const string_view parameter, int count)
|
|||
LevelMonsterTypes[id].mdeadval = 1;
|
||||
}
|
||||
|
||||
AddMonster(pos, dir, id, true);
|
||||
auto &myPlayer = Players[MyPlayerId];
|
||||
|
||||
if (++counter >= count)
|
||||
auto isTileOk = [](Point position) {
|
||||
if (dPlayer[position.x][position.y] != 0 || dMonster[position.x][position.y] != 0)
|
||||
return false;
|
||||
if (!IsTileWalkable(position))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
int spawnedMonster = 0;
|
||||
|
||||
for (auto dir : left) {
|
||||
Point pos = myPlayer.position.tile + dir;
|
||||
if (!isTileOk(pos))
|
||||
continue;
|
||||
|
||||
AddMonster(pos, dir, id, true);
|
||||
spawnedMonster += 1;
|
||||
if (spawnedMonster >= count)
|
||||
break;
|
||||
}
|
||||
|
||||
return "Tickle tickle, here comes my pickle.";
|
||||
}
|
||||
|
||||
std::string DebugCmdSpawnMonsterSingle(const string_view parameter)
|
||||
{
|
||||
return DebugSpawnMonster(parameter, 1);
|
||||
}
|
||||
|
||||
std::string DebugCmdSpawnMonsterMany(const string_view parameter)
|
||||
{
|
||||
return DebugSpawnMonster(parameter, 8);
|
||||
}
|
||||
|
||||
std::vector<DebugCmdItem> DebugCmdList = {
|
||||
{ "help", "Prints help overview or help for a specific command.", "({command})", &DebugCmdHelp },
|
||||
{ "give gold", "Fills the inventory with gold.", "", &DebugCmdGiveGoldCheat },
|
||||
|
|
@ -595,8 +604,7 @@ std::vector<DebugCmdItem> DebugCmdList = {
|
|||
{ "cursorcoords", "Toggles showing cursor coords.", "", &DebugCmdShowCursorCoords },
|
||||
{ "grid", "Toggles showing grid.", "", &DebugCmdShowGrid },
|
||||
{ "seedinfo", "Show seed infos for current level.", "", &DebugCmdLevelSeed },
|
||||
{ "mon", "Spawns monster {name}.", "{name}", &DebugCmdSpawnMonsterSingle },
|
||||
{ "mmon", "Spawns up to 8 monsters {name}.", "{name}", &DebugCmdSpawnMonsterMany },
|
||||
{ "spawn", "Spawns monster {name}.", "({count}) {name}", &DebugCmdSpawnMonster },
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue