|
25 | 25 | #include "utils/string_utils.hpp" |
26 | 26 | #include "race/item_policy.hpp" |
27 | 27 | #include "modes/world.hpp" |
| 28 | +#include "modes/linear_world.hpp" |
28 | 29 | #include "items/item.hpp" |
29 | 30 | #include "items/powerup.hpp" |
30 | 31 | #include "items/powerup_manager.hpp" |
@@ -159,6 +160,7 @@ void ItemPolicy::applySectionRules(ItemPolicySection §ion, Kart *kart, int n |
159 | 160 | // Returns the section that was applied. Returns -1 if it tried to appply an unsupported section or if there are no sections |
160 | 161 | int ItemPolicy::applyRules(Kart *kart, int current_lap, int current_time, int total_laps_of_race) { |
161 | 162 | if (m_policy_sections.size() == 0) return -1; |
| 163 | + |
162 | 164 | for (unsigned i = 0; i < m_policy_sections.size(); i++) { |
163 | 165 | int next_section_start_laps = total_laps_of_race; |
164 | 166 | int prev_lap_item_amount = kart->m_item_amount_last_lap; |
@@ -192,6 +194,44 @@ int ItemPolicy::applyRules(Kart *kart, int current_lap, int current_time, int to |
192 | 194 | } |
193 | 195 | return -1; |
194 | 196 | } |
| 197 | + |
| 198 | +int ItemPolicy::getSectionForKart(Kart *kart) { |
| 199 | + if (!World::getWorld()->raceHasLaps()) |
| 200 | + return -1; |
| 201 | + |
| 202 | + LinearWorld *lin_world = dynamic_cast<LinearWorld*>(World::getWorld()); |
| 203 | + int current_lap = lin_world->getFinishedLapsOfKart(kart->getWorldKartId()); |
| 204 | + int current_time = World::getWorld()->getTime(); |
| 205 | + |
| 206 | + if (m_policy_sections.size() == 0) return -1; |
| 207 | + for (unsigned i = 0; i < m_policy_sections.size(); i++) { |
| 208 | + if (i+1 == m_policy_sections.size()) { |
| 209 | + return i; |
| 210 | + break; |
| 211 | + } else if (m_policy_sections[i].m_section_type == IP_TIME_BASED) { |
| 212 | + Log::error("ItemPolicy", "Time-implemented item policy sections are not implemented yet"); |
| 213 | + return i; |
| 214 | + break; |
| 215 | + } else if (m_policy_sections[i].m_section_type == IP_LAPS_BASED) { |
| 216 | + if (m_policy_sections[i+1].m_section_type == IP_TIME_BASED) { |
| 217 | + Log::error("ItemPolicy", "Time-implemented item policy sections are not implemented yet"); |
| 218 | + return i; |
| 219 | + break; |
| 220 | + } else if (m_policy_sections[i+1].m_section_type == IP_LAPS_BASED) { |
| 221 | + if (current_lap >= m_policy_sections[i].m_section_start && |
| 222 | + current_lap < m_policy_sections[i+1].m_section_start) |
| 223 | + { |
| 224 | + return i; |
| 225 | + break; |
| 226 | + } else { |
| 227 | + continue; |
| 228 | + } |
| 229 | + } |
| 230 | + } |
| 231 | + } |
| 232 | + return -1; |
| 233 | + |
| 234 | +} |
195 | 235 | //-------------------------------------------------- |
196 | 236 | static std::string fetch(std::vector<std::string>& strings, unsigned idx) { |
197 | 237 | if (idx >= strings.size()) |
|
0 commit comments