def _roll_temp(self, avg, op, mod, table): '''Look up temp variation from table.''' roll = drm() + mod # todo: replace with table lookup func for i, var, newmod in table: if i > roll: return op(avg, var), newmod
def _roll_duration(base, mod): '''Look up precipitation duration from table.''' roll = drm() + mod for row in precipitation_duration_table: if roll <= row[0]: return row[base] return precipitation_duration_table[-1][base]
def _roll_inches(base, mod): '''Look up precipitation inches from table.''' roll = drm() + mod for row in precipitation_inches_table: if roll <= row[0]: return row[base] return precipitation_inches_table[-1][base]
def _calc_precipitation(self, prev_day, chance, cloud_table): '''Is it raining? :param chance: % chance of precipitation :param cloud_table: data from month table ''' if prev_day and prev_day.precipitation_end > 24: self.precipitation = prev_day.precipitation self.precipitation_start = 1 self.precipitation_end = prev_day.precipitation_end - 24 self.precipitation_mods = prev_day.precipitation_mods self.wind = prev_day.wind # todo roll my own wind cloud_mod = 30 else: roll = drm() + chance if roll > 100: self.precipitation = None while self.precipitation is None: # Note: sets start/end. self.precipitation, self.wind = self._roll_precipitation() cloud_mod = 30 else: self.precipitation = None self.precipitation_start = 0 self.precipitation_end = 0 self.precipitation_mods = (0, 0, 0, 0) self.wind = self._roll_wind(1, -10) # clear cloud_mod = 0 # Cloud cover roll = d100() + cloud_mod if roll <= cloud_table[0]: self.cloud = 'Clear' elif roll <= cloud_table[1]: self.cloud = 'Partly' else: self.cloud = 'Cloudy'
def _roll_wind(self, base, storm_mod): '''Look up wind speed from table.''' roll = drm() + storm_mod + self.wind_mod # Only modify non-storm winds. if base == 1: roll += self.wind_mod for row in wind_table: if roll <= row[0]: return row[base] return wind_table[0][base]