| 1916 | } |
| 1917 | |
| 1918 | void BattleUnit::update(GameState &state, unsigned int ticks) |
| 1919 | { |
| 1920 | bool realTime = state.current_battle->mode == Battle::Mode::RealTime; |
| 1921 | |
| 1922 | // Animate |
| 1923 | body_animation_ticks_static += ticks; |
| 1924 | |
| 1925 | // Destroyed or retreated units do not exist in the battlescape |
| 1926 | if (destroyed || retreated) |
| 1927 | { |
| 1928 | return; |
| 1929 | } |
| 1930 | |
| 1931 | // Update Items |
| 1932 | bool updatedShield = false; |
| 1933 | for (auto &item : agent->equipment) |
| 1934 | { |
| 1935 | if (item->type->type == AEquipmentType::Type::DisruptorShield && |
| 1936 | item->ammo < item->getPayloadType()->max_ammo) |
| 1937 | { |
| 1938 | if (updatedShield) |
| 1939 | { |
| 1940 | continue; |
| 1941 | } |
| 1942 | updatedShield = true; |
| 1943 | } |
| 1944 | item->update(state, ticks); |
| 1945 | } |
| 1946 | |
| 1947 | // Update Missions |
| 1948 | if (!this->missions.empty()) |
| 1949 | this->missions.front()->update(state, *this, ticks); |
| 1950 | |
| 1951 | // [Update the Unit itself] |
| 1952 | |
| 1953 | if (realTime) |
| 1954 | { |
| 1955 | // Miscellaneous state updates, as well as unit's stats |
| 1956 | updateStateAndStats(state, ticks); |
| 1957 | // Unit regeneration |
| 1958 | updateRegen(state, ticks); |
| 1959 | } |
| 1960 | // Unit cloak - even in TB unit returns to cloaked after firing based on time |
| 1961 | updateCloak(state, ticks); |
| 1962 | // Unit events - was under fire, was requested to give way etc. |
| 1963 | updateEvents(state); |
| 1964 | // Idling: Auto-movement, auto-body change when idling |
| 1965 | updateIdling(state); |
| 1966 | // Crying: Enemies emit sounds periodically |
| 1967 | updateCrying(state); |
| 1968 | // Main bulk - update movement, body, hands and turning |
| 1969 | { |
| 1970 | bool wasUsingLift = usingLift; |
| 1971 | usingLift = false; |
| 1972 | |
| 1973 | // If not running we will consume these twice as fast, if prone thrice as |
| 1974 | unsigned int moveTicksRemaining = |
| 1975 | ticks * agent->modified_stats.getMovementSpeed() * BASE_MOVETICKS_CONSUMPTION_RATE; |
nothing calls this directly
no test coverage detected