Keep generic job phases and checked ID allocation consistent across loads
This commit is contained in:
1 parent
ccd50ec40c
commit
4f4c038051
4 files changed
+90
-3
No files matched your search
@@ -429,12 +429,15 @@ AgentId World::spawn_agent(GridPosition position) {
|
||||
if (!is_walkable(position)) {
|
||||
throw std::invalid_argument("agent spawn cell is not walkable");
|
||||
}
|
||||
const AgentId id = next_agent_id_++;
|
||||
const AgentId id = next_agent_id_;
|
||||
const auto successor = Void::Numeric::checked_add(id, AgentId{1});
|
||||
if (id == 0 || !successor) throw std::overflow_error("resident identities exhausted");
|
||||
Agent agent;
|
||||
agent.id = id;
|
||||
agent.position = position;
|
||||
if (hunger_enabled_) agent.hunger = initial_hunger(id);
|
||||
agents_.push_back(std::move(agent));
|
||||
next_agent_id_ = *successor;
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -445,8 +448,11 @@ JobId World::add_job(GridPosition position, std::uint32_t work_required) {
|
||||
if (work_required == 0) {
|
||||
throw std::invalid_argument("work duration must be greater than zero");
|
||||
}
|
||||
const JobId id = next_job_id_++;
|
||||
const JobId id = next_job_id_;
|
||||
const auto successor = Void::Numeric::checked_add(id, JobId{1});
|
||||
if (id == 0 || !successor) throw std::overflow_error("job identities exhausted");
|
||||
jobs_.push_back(WorkJob{id, position, work_required, work_required, JobState::Available});
|
||||
next_job_id_ = *successor;
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user