| 371 | } |
| 372 | |
| 373 | void Lab::update(unsigned int ticks, StateRef<Lab> lab, sp<GameState> state) |
| 374 | { |
| 375 | if (lab->current_project) |
| 376 | { |
| 377 | auto skill = lab->getTotalSkill(); |
| 378 | if (skill <= 0) |
| 379 | { |
| 380 | // If there's nobody assigned projects obviously don't progress |
| 381 | return; |
| 382 | } |
| 383 | // A little complication as we want to be correctly calculating progress in an integer when |
| 384 | // working with sub-single progress 'unit' time units. |
| 385 | // This also leaves any remaining ticks in the lab's ticks_since_last_progress, so they will |
| 386 | // get added onto the next project that lab undertakes at the first update. |
| 387 | unsigned ticks_per_progress_hour = TICKS_PER_HOUR / skill; |
| 388 | unsigned ticks_remaining_to_progress = ticks + lab->ticks_since_last_progress; |
| 389 | |
| 390 | unsigned progress_hours = 0; |
| 391 | |
| 392 | switch (lab->current_project->type) |
| 393 | { |
| 394 | case ResearchTopic::Type::Physics: |
| 395 | case ResearchTopic::Type::BioChem: |
| 396 | progress_hours = std::min(ticks_remaining_to_progress / ticks_per_progress_hour, |
| 397 | lab->current_project->man_hours - |
| 398 | lab->current_project->man_hours_progress); |
| 399 | break; |
| 400 | case ResearchTopic::Type::Engineering: |
| 401 | progress_hours = std::min(ticks_remaining_to_progress / ticks_per_progress_hour, |
| 402 | lab->current_project->man_hours * lab->getQuantity() - |
| 403 | lab->manufacture_man_hours_invested); |
| 404 | break; |
| 405 | default: |
| 406 | LogError("Unexpected lab type"); |
| 407 | } |
| 408 | |
| 409 | unsigned ticks_left = |
| 410 | ticks_remaining_to_progress - progress_hours * ticks_per_progress_hour; |
| 411 | lab->ticks_since_last_progress = ticks_left; |
| 412 | |
| 413 | switch (lab->current_project->type) |
| 414 | { |
| 415 | case ResearchTopic::Type::Physics: |
| 416 | case ResearchTopic::Type::BioChem: |
| 417 | lab->current_project->man_hours_progress += progress_hours; |
| 418 | if (lab->current_project->isComplete()) |
| 419 | { |
| 420 | // Produce a research remains item |
| 421 | StateRef<Base> thisBase; |
| 422 | for (auto &base : state->player_bases) |
| 423 | { |
| 424 | for (auto &facility : base.second->facilities) |
| 425 | { |
| 426 | if (facility->lab == lab) |
| 427 | { |
| 428 | thisBase = {state.get(), base.first}; |
| 429 | break; |
| 430 | } |
nothing calls this directly
no test coverage detected