MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / update

Method update

game/state/battle/battleunitmission.cpp:1550–1699  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1548}
1549
1550void BattleUnitMission::update(GameState &state, BattleUnit &u, unsigned int ticks, bool finished)
1551{
1552 switch (this->type)
1553 {
1554 case Type::Jump:
1555 if (!jumped && !u.falling && u.atGoal && u.facing == u.goalFacing &&
1556 u.facing == targetFacing &&
1557 (u.current_body_state == u.target_body_state ||
1558 targetBodyState == BodyState::Jumping) &&
1559 u.target_body_state == targetBodyState)
1560 {
1561 // Jumping cost assumed same as walking into tile
1562 int cost = STANDART_MOVE_TU_COST;
1563 if (!spendAgentTUs(state, u, cost, true))
1564 {
1565 return;
1566 }
1567 u.launch(state, jumpTarget, targetBodyState);
1568 jumped = true;
1569 }
1570 return;
1571 case Type::GotoLocation:
1572 {
1573 if (finished)
1574 {
1575 if (allowRunningAway)
1576 {
1577 if (u.tileObject->getOwningTile()->getHasExit(u.isLarge()))
1578 {
1579 u.retreat(state);
1580 }
1581 }
1582 }
1583 return;
1584 }
1585 case Type::Snooze:
1586 {
1587 if (ticks >= timeToSnooze)
1588 {
1589 this->timeToSnooze = 0;
1590 }
1591 else
1592 {
1593 this->timeToSnooze -= ticks;
1594 }
1595 return;
1596 }
1597 case Type::ThrowItem:
1598 // Half way there - throw the item!
1599 if (item && u.current_body_state == BodyState::Throwing &&
1600 u.target_body_state == BodyState::Throwing)
1601 {
1602 // Ensure item still belongs to agent
1603 if (item->ownerAgent == u.agent)
1604 {
1605 item->ownerAgent->removeEquipment(state, item);
1606 item->ownerUnit = {&state, u.id};
1607 item->throwItem(state, targetLocation, velocityXY, velocityZ);

Callers

nothing calls this directly

Calls 15

pickRandomFunction · 0.85
randBoundsExclusiveFunction · 0.85
launchMethod · 0.80
getHasExitMethod · 0.80
getOwningTileMethod · 0.80
isLargeMethod · 0.80
retreatMethod · 0.80
startMovingMethod · 0.80
isConsciousMethod · 0.80
resetGoalMethod · 0.80
endMethod · 0.80
emptyMethod · 0.80

Tested by

no test coverage detected