parameters: ()
docstring: Calculate RPs and prerequisites of every tech, in (prereqs, cost, time).
docstring_summary: Calculate RPs and prerequisites of every tech, in (prereqs, cost, time).
docstring_tokens: Calculate RPs and prerequisites of every tech in ( prereqs cost time ) .
function: def calculate_research_requirements():
      """Calculate RPs and prerequisites of every tech, in (prereqs, cost, time)."""
      empire = fo.getEmpire()
      research_reqs.clear()
  
      completed_techs = get_completed_techs()
      for tech_name in fo.techs():
          if tech_is_complete(tech_name):
              research_reqs[tech_name] = ([], 0, 0, 0)
              continue
          this_tech = fo.getTech(tech_name)
          prereqs = [
              preReq for preReq in this_tech.recursivePrerequisites(empire.empireID) if preReq not in completed_techs
          ]
          base_cost = this_tech.researchCost(empire.empireID)
          progress = empire.researchProgress(tech_name)
          cost = max(0.0, base_cost - progress)
          proportion_remaining = cost / max(base_cost, 1.0)
          this_time = this_tech.researchTime(fo.empireID())
          turns_needed = max(1, math.ceil(proportion_remaining * this_time))  # even if fully paid needs one turn
          per_turn_cost = float(base_cost) / max(1.0, this_time)
  
          # TODO: the following timing calc treats prereqs as inherently sequential; consider in parallel when able
          for prereq in prereqs:
              prereq_tech = fo.getTech(prereq)
              if not prereq_tech:
                  continue
              base_cost = prereq_tech.researchCost(empire.empireID)
              progress = empire.researchProgress(prereq)
              prereq_cost = max(0.0, base_cost - progress)
              proportion_remaining = prereq_cost / max(base_cost, 1.0)
              this_time = prereq_tech.researchTime(fo.empireID())
              turns_needed += max(1, math.ceil(proportion_remaining * this_time))
              cost += prereq_cost
          research_reqs[tech_name] = (prereqs, cost, turns_needed, per_turn_cost)
function_tokens: def calculate_research_requirements ( ) : empire = fo . getEmpire ( ) research_reqs . clear ( ) completed_techs = get_completed_techs ( ) for tech_name in fo . techs ( ) : if tech_is_complete ( tech_name ) : research_reqs [ tech_name ] = ( [ ] , 0 , 0 , 0 ) continue this_tech = fo . getTech ( tech_name ) prereqs = [ preReq for preReq in this_tech . recursivePrerequisites ( empire . empireID ) if preReq not in completed_techs ] base_cost = this_tech . researchCost ( empire . empireID ) progress = empire . researchProgress ( tech_name ) cost = max ( 0.0 , base_cost - progress ) proportion_remaining = cost / max ( base_cost , 1.0 ) this_time = this_tech . researchTime ( fo . empireID ( ) ) turns_needed = max ( 1 , math . ceil ( proportion_remaining * this_time ) ) # even if fully paid needs one turn per_turn_cost = float ( base_cost ) / max ( 1.0 , this_time ) # TODO: the following timing calc treats prereqs as inherently sequential; consider in parallel when able for prereq in prereqs : prereq_tech = fo . getTech ( prereq ) if not prereq_tech : continue base_cost = prereq_tech . researchCost ( empire . empireID ) progress = empire . researchProgress ( prereq ) prereq_cost = max ( 0.0 , base_cost - progress ) proportion_remaining = prereq_cost / max ( base_cost , 1.0 ) this_time = prereq_tech . researchTime ( fo . empireID ( ) ) turns_needed += max ( 1 , math . ceil ( proportion_remaining * this_time ) ) cost += prereq_cost research_reqs [ tech_name ] = ( prereqs , cost , turns_needed , per_turn_cost )