void Path::Remove( Vec2i point ) { if( IsChocked( point ) ) { for( Charges::iterator it = chocks.begin(); it != chocks.end(); ++it ) { if( it->point == point ) { charges.erase( it ); return; } } } else if( IsCharged( point ) ) { for( Charges::iterator it = charges.begin(); it != charges.end(); ++it ) { if( it->point == point ) { charges.erase( it ); return; } } } else if( HasObj( point ) ) { for( Objects::iterator it = objects.begin(); it != objects.end(); ++it ) { if( (*it)->GetGridPos() == point ) { objects.erase( it ); return; } } } else { points.erase( point ); } }
const RPG::EnemyAction* Game_Enemy::ChooseRandomAction() { if (IsCharged()) { return &normal_atk; } const std::vector<RPG::EnemyAction>& actions = enemy->actions; std::vector<int> valid; int32_t highest_rating = 0; for (int i = 0; i < (int) actions.size(); ++i) { const RPG::EnemyAction& action = actions[i]; if (IsActionValid(action)) { valid.push_back(i); highest_rating = std::max(highest_rating, action.rating); } } int total = 0; for (auto it = valid.begin(); it != valid.end();) { if (actions[*it].rating < highest_rating - 9) { it = valid.erase(it); } else { total += actions[*it].rating; ++it; } } if (total == 0) { return nullptr; } int which = Utils::GetRandomNumber(0, total - 1); for (std::vector<int>::const_iterator it = valid.begin(); it != valid.end(); ++it) { const RPG::EnemyAction& action = actions[*it]; if (which >= action.rating) { which -= action.rating; continue; } return &action; } return nullptr; }