@@ -125,7 +125,7 @@ void ItemState::initItem(ItemType type, const Vec3& xyz, const Vec3& normal, int
125125 setDisappearCounter ();
126126} // initItem
127127
128- static int getRespawnTime (ItemState::ItemType type) {
128+ static int getRespawnTicks (ItemState::ItemType type) {
129129 auto & stk_config = STKConfig::get ();
130130 switch (type)
131131 {
@@ -169,73 +169,7 @@ void ItemState::update(int ticks)
169169 } // if collected
170170
171171 ItemPolicy *policy = RaceManager::get ()->getItemPolicy ();
172- if (policy->m_policy_sections .size () == 0 )
173- return ;
174-
175- int current_section = policy->m_leader_section ;
176-
177- if (current_section <= -1 )
178- current_section = 0 ;
179-
180- uint16_t rules_curr = policy->m_policy_sections [current_section].m_rules ;
181- uint16_t rules_prev;
182- if (current_section > 0 )
183- rules_prev = policy->m_policy_sections [current_section-1 ].m_rules ;
184- else
185- rules_prev = rules_curr;
186-
187- bool was_gum = (m_original_type==ITEM_BUBBLEGUM) || (m_type==ITEM_BUBBLEGUM_NOLOK) ||
188- (m_original_type==ITEM_BUBBLEGUM_SMALL) || (m_type==ITEM_BUBBLEGUM_SMALL_NOLOK);
189-
190- bool is_nitro = (m_type==ITEM_NITRO_SMALL) || (m_type==ITEM_NITRO_BIG);
191- bool was_nitro = (m_original_type==ITEM_NITRO_SMALL) || (m_original_type==ITEM_NITRO_BIG);
192-
193- bool forbid_prev = ((rules_prev & ItemPolicyRules::IPT_FORBID_BONUSBOX) && m_type==ITEM_BONUS_BOX) ||
194- ((rules_prev & ItemPolicyRules::IPT_FORBID_BANANA) && m_type==ITEM_BANANA) ||
195- ((rules_prev & ItemPolicyRules::IPT_FORBID_NITRO) && (is_nitro || was_nitro));
196-
197- bool forbid_curr = ((rules_curr & ItemPolicyRules::IPT_FORBID_BONUSBOX) && m_type==ITEM_BONUS_BOX) ||
198- ((rules_curr & ItemPolicyRules::IPT_FORBID_BANANA) && m_type==ITEM_BANANA) ||
199- ((rules_curr & ItemPolicyRules::IPT_FORBID_NITRO) && (is_nitro || was_nitro));
200-
201- int fuel_mode = std::get<0 >(RaceManager::get ()->getFuelAndQueueInfo ());
202- if (fuel_mode == 0 && m_type == ITEM_TYRE_CHANGE && m_compound == 123 ) // If we're a fuel tyre changer and fuel is off, don't spawn
203- forbid_curr = true ;
204-
205-
206- // Gums that were switched into nitro are NEVER forbidden
207- bool instant = false ;
208- if (was_gum && is_nitro) {
209- instant = true ;
210- } else {
211- instant = false ;
212- }
213-
214- auto & stk_config = STKConfig::get ();
215- // There's redundant cases here, but it is like this for maintainability
216- if (forbid_prev && forbid_curr)
217- m_ticks_till_return = stk_config->time2Ticks (99999 );
218- else if (!forbid_prev && forbid_curr)
219- m_ticks_till_return = stk_config->time2Ticks (99999 );
220- else if (forbid_prev && !forbid_curr) {
221- int respawn_ticks = getRespawnTime (m_type);
222- // If the ticks till return are abnormally high, set them back to normal.
223- // If we don't do it like this, it will set the ticks till return perpetually
224- // when transitioning from a section without to a section with this item type allowed.
225- if (m_ticks_till_return > 10 *respawn_ticks)
226- m_ticks_till_return = respawn_ticks;
227- }
228- else if (!forbid_prev && !forbid_curr) {
229- // Nothing to do
230- // This wouldn't be needed normally, but we do it in case of switched items
231- int respawn_ticks = getRespawnTime (m_type);
232- if (m_ticks_till_return > 10 *respawn_ticks && m_type != ITEM_EASTER_EGG)
233- m_ticks_till_return = respawn_ticks;
234- }
235- if (instant) {
236- m_ticks_till_return = 0 ;
237- }
238-
172+ m_ticks_till_return = policy->computeItemTicksTillReturn (m_original_type, m_type, getRespawnTicks (m_type), m_ticks_till_return);
239173} // update
240174
241175// ----------------------------------------------------------------------------
@@ -263,7 +197,7 @@ void ItemState::collected(const Kart *kart)
263197 }
264198 else
265199 {
266- m_ticks_till_return = getRespawnTime (m_type);
200+ m_ticks_till_return = getRespawnTicks (m_type);
267201 }
268202
269203 if (RaceManager::get ()->isBattleMode ())
0 commit comments