Loading

Paste #pn1c10m0z

  1. diff --git a/src/road.cpp b/src/road.cpp
  2. index 399971c..3f0d436 100644
  3. --- a/src/road.cpp
  4. +++ b/src/road.cpp
  5. @@ -247,3 +247,54 @@ bool RoadTypeIdentifier::UnpackIfValid(uint32 data)
  6.     assert(ret);
  7.     return result;
  8.  }
  9. +
  10. +/**
  11. + * Returns the available RoadSubTypes for the provided RoadType
  12. + * @param rt the RoadType to filter
  13. + * @param c the company to check the roadtype against
  14. + * @param only_existing whether to return only currently introduced vehicles or also future ones
  15. + * @returns the existing RoadSubTypes
  16. + */
  17. +RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool only_existing = false)
  18. +{
  19. +   RoadSubTypes known_roadsubtypes = ROADSUBTYPES_NONE;
  20. +   RoadSubTypes available_roadsubtypes = ROADSUBTYPES_NONE;
  21. +
  22. +   /* Road is always visible and available. */
  23. +   if (rt == ROADTYPE_ROAD) known_roadsubtypes |= ROADSUBTYPES_NORMAL; // TODO
  24. +
  25. +   /* Find used roadtypes */
  26. +   Engine *e;
  27. +   FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
  28. +       /* Check if the subtype can be used in the current climate */
  29. +       if (!HasBit(e->info.climates,  _settings_game.game_creation.landscape)) continue;
  30. +
  31. +       RoadTypeIdentifier rtid = e->GetRoadType();
  32. +       if (rtid.basetype != rt) continue;
  33. +
  34. +       known_roadsubtypes |= GetRoadTypeInfo(rtid)->introduces_roadtypes;
  35. +   }
  36. +
  37. +   if (!only_existing) {
  38. +       /* Get the date introduced roadtypes as well. */
  39. +       known_roadsubtypes = AddDateIntroducedRoadTypes(rt, known_roadsubtypes, MAX_DAY);
  40. +   }
  41. +
  42. +   const Company *company = Company::GetIfValid(c);
  43. +
  44. +   /* If it's not used ever, don't show it to the user. */
  45. +   RoadTypeIdentifier rtid;
  46. +   FOR_ALL_SORTED_ROADTYPES(rtid, rt) {
  47. +       if (!HasBit(known_roadsubtypes, rtid.subtype)) continue;
  48. +
  49. +       if (company != NULL) {
  50. +           if (only_existing && !HasBit(company->avail_roadtypes[rtid.basetype], rtid.subtype)) {
  51. +               continue;
  52. +           }
  53. +       }
  54. +
  55. +       SetBit(available_roadsubtypes, rtid.subtype);
  56. +   }
  57. +  
  58. +   return available_roadsubtypes;
  59. +}

Version history

Revision # Author Created at
p84xottja Anonymous 18 Feb 2017, 15:49:52 UTC Diff

Comments