Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ported multiplying spawns from jc4 #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/commands/spawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,41 @@ class SpawnCommand : public ICommand
transform.m[3].y = aimpos.y + 1.0f;
transform.m[3].z = aimpos.z;

jc::CSpawnSystem::instance().Spawn(arguments, transform, [](const jc::spawned_objects &objects, void *) {
//
});
// figure out if the player wants to spawn more than one thing
if (arguments.find("*", 0) != std::string::npos) {
// identify the multiplier and turn it into something we can use, then create a string without it
// also identify the spacer to enable spawning of bigger things
// limiting the size of the substring limits max spawned entities, although the game seems to limit this
// itself
size_t multiplier_position = arguments.find("*", 0);
size_t spacer_position = arguments.find("/", 0);
std::string truncated_args = arguments.substr(0, multiplier_position - 1);

int multiplier = std::stoi(arguments.substr(multiplier_position + 1, 4));
int spacer = 5;

if (spacer_position != std::string::npos) {
spacer = std::stoi(arguments.substr(spacer_position + 1, std::string::npos));
}

int square_root = (int)(std::sqrt((double)multiplier) + 0.5f);
// do the actual spawning
for (int i = 0; i < multiplier; i++) {
// spawn things in as square a rectangle as possible
if ((i % square_root == 0) && (i != 0)) {
transform.m[3].x = transform.m[3].x + spacer;
transform.m[3].z = transform.m[3].z - (square_root * spacer);
} else {
transform.m[3].z = transform.m[3].z + spacer;
}
jc::CSpawnSystem::instance().Spawn(truncated_args, transform,
[](const jc::spawned_objects &objects, void *) {});
}

} else {

jc::CSpawnSystem::instance().Spawn(arguments, transform, [](const jc::spawned_objects &objects, void *) {});
}

return true;
}
Expand Down