Browse Source

debug spawn command with configurable monster count

pull/2843/head
obligaron 5 years ago committed by qndel
parent
commit
7d86991534
  1. 138
      Source/debug.cpp

138
Source/debug.cpp

@ -479,97 +479,106 @@ 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!";
std::string name(parameter.data());
if (name == "")
return "Give monster name!";
return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
}
std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c) { return std::tolower(c); });
std::string DebugCmdSpawnMonster(const string_view parameter)
{
if (currlevel == 0)
return "Do you want to kill the towners?!?";
auto &myPlayer = Players[MyPlayerId];
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, ' ');
}
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;
};
std::string singleWord;
while (std::getline(paramsStream, singleWord, ' ')) {
name.append(" ");
name.append(singleWord);
}
int counter = 0;
std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c) { return std::tolower(c); });
for (auto dir : left) {
Point pos = myPlayer.position.tile + dir;
if (!isTileOk(pos))
int mtype = -1;
for (int i = 0; i < 138; i++) {
auto mondata = MonstersData[i];
std::string monsterName(mondata.mName);
std::transform(monsterName.begin(), monsterName.end(), monsterName.begin(), [](unsigned char c) { return std::tolower(c); });
if (monsterName.find(name) == std::string::npos)
continue;
mtype = i;
break;
}
int mtype = -1;
for (int i = 0; i < 138; i++) {
auto mondata = MonstersData[i];
if (mtype == -1) {
for (int i = 0; i < 100; i++) {
auto mondata = UniqueMonstersData[i];
std::string monsterName(mondata.mName);
std::transform(monsterName.begin(), monsterName.end(), monsterName.begin(), [](unsigned char c) { return std::tolower(c); });
if (monsterName.find(name) == std::string::npos)
continue;
mtype = i;
mtype = mondata.mtype;
break;
}
}
if (mtype == -1) {
for (int i = 0; i < 100; i++) {
auto mondata = UniqueMonstersData[i];
std::string monsterName(mondata.mName);
std::transform(monsterName.begin(), monsterName.end(), monsterName.begin(), [](unsigned char c) { return std::tolower(c); });
if (monsterName.find(name) == std::string::npos)
continue;
mtype = mondata.mtype;
break;
}
if (mtype == -1)
return "Monster not found!";
int id = MAX_LVLMTYPES - 1;
bool found = false;
for (int i = 0; i < LevelMonsterTypeCount; i++) {
if (LevelMonsterTypes[i].mtype == mtype) {
id = i;
found = true;
break;
}
}
if (mtype == -1)
return "Monster not found!";
if (!found) {
LevelMonsterTypes[id].mtype = static_cast<_monster_id>(mtype);
InitMonsterGFX(id);
LevelMonsterTypes[id].mPlaceFlags |= PLACE_SCATTER;
LevelMonsterTypes[id].mdeadval = 1;
}
int id = MAX_LVLMTYPES - 1;
bool found = false;
auto &myPlayer = Players[MyPlayerId];
for (int i = 0; i < LevelMonsterTypeCount; i++) {
if (LevelMonsterTypes[i].mtype == mtype) {
id = i;
found = true;
break;
}
}
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;
};
if (!found) {
LevelMonsterTypes[id].mtype = static_cast<_monster_id>(mtype);
InitMonsterGFX(id);
LevelMonsterTypes[id].mPlaceFlags |= PLACE_SCATTER;
LevelMonsterTypes[id].mdeadval = 1;
}
int spawnedMonster = 0;
AddMonster(pos, dir, id, true);
for (auto dir : left) {
Point pos = myPlayer.position.tile + dir;
if (!isTileOk(pos))
continue;
if (++counter >= count)
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…
Cancel
Save