# HG changeset patch # User Jeremy Thurgood # Date 1336418663 -7200 # Node ID 373c57ab4140bc8ae399d14e9fb8999241898622 # Parent a2980cc9a0604feaae9ef070b65dbfadfe12f7b5 Product -> Schematic. diff -r a2980cc9a060 -r 373c57ab4140 gamelib/gamestate.py --- a/gamelib/gamestate.py Mon May 07 21:23:54 2012 +0200 +++ b/gamelib/gamestate.py Mon May 07 21:24:23 2012 +0200 @@ -37,7 +37,7 @@ def get_available_equipment(self): """Return a list of equipment we can produce and afford""" available = [x for x in self.lab.science - if x.SCIENCE_TYPE == 'product' and x.COST <= self.money] + if x.SCIENCE_TYPE == 'schematic' and x.COST <= self.money] return available def get_available_missions(self): diff -r a2980cc9a060 -r 373c57ab4140 gamelib/lab.py --- a/gamelib/lab.py Mon May 07 21:23:54 2012 +0200 +++ b/gamelib/lab.py Mon May 07 21:24:23 2012 +0200 @@ -2,7 +2,7 @@ from random import random, choice -from gamelib import research, products +from gamelib import research, schematics from gamelib.game_base import get_subclasses @@ -13,7 +13,7 @@ def __init__(self, init_data=None): self.science = [] self.new_research = get_subclasses(research.ResearchArea) - self.new_products = get_subclasses(products.Product) + self.new_schematics = get_subclasses(schematics.Schematic) if init_data is not None: # Load stored state. @@ -24,7 +24,7 @@ def _load_data(self, init_data): sciences = init_data['science'].copy() - for science in self.new_products + self.new_research: + for science in self.new_schematics + self.new_research: # Check if this science is one we should know. points = sciences.pop(science.save_name(), None) if points is not None: @@ -38,10 +38,10 @@ return {'science': dict(s.save_data() for s in self.science)} def _choose_initial_science(self): - # We always get all starting products. - for product in self.new_products[:]: - if product.STARTING_PRODUCT: - self._gain_science(product()) + # We always get all starting schematics. + for schematic in self.new_schematics[:]: + if schematic.STARTING_PRODUCT: + self._gain_science(schematic()) # We get three random sciences with no prerequisites. new_science = [] @@ -50,15 +50,15 @@ self._gain_science(science) new_science.append(science) - # Add a point to each of our sciences, and see if we get products. + # Add a point to each of our sciences, and see if we get schematics. self.spend_points(new_science, 0) def _gain_science(self, science): self.science.append(science) if isinstance(science, research.ResearchArea): self.new_research.remove(type(science)) - elif isinstance(science, products.Product): - self.new_products.remove(type(science)) + elif isinstance(science, schematics.Schematic): + self.new_schematics.remove(type(science)) def spend_points(self, things, basic_research): breakthroughs = [] @@ -69,7 +69,7 @@ assert thing.can_spend(self) thing.spend_point() - # Next, check for product breakthroughs and upgrades + # Next, check for schematic breakthroughs and upgrades for thing in things: if isinstance(thing, research.ResearchArea): breakthroughs.extend(self.apply_area_research(thing)) @@ -98,12 +98,12 @@ total_points += my_science.points return total_points - base_points >= extra - def find_new_products(self): - available_products = [] - for product_class in self.new_products: - if self.meet_requirements(product_class): - available_products.append(product_class) - return available_products + def find_new_schematics(self): + available_schematics = [] + for schematic_class in self.new_schematics: + if self.meet_requirements(schematic_class): + available_schematics.append(schematic_class) + return available_schematics def find_new_research(self): available_research = [] @@ -113,10 +113,10 @@ return available_research def apply_area_research(self, research): - options = [product for product in self.find_new_products() - if type(research) in [p[0] for p in product.PREREQUISITES]] - breakthroughs = [product for product in options - if random() < product.ACQUISITION_CHANCE] + options = [schema for schema in self.find_new_schematics() + if type(research) in [p[0] for p in schema.PREREQUISITES]] + breakthroughs = [schematic for schematic in options + if random() < schematic.ACQUISITION_CHANCE] if breakthroughs: breakthrough = choice(breakthroughs)() self._gain_science(breakthrough) diff -r a2980cc9a060 -r 373c57ab4140 gamelib/missions.py --- a/gamelib/missions.py Mon May 07 21:23:54 2012 +0200 +++ b/gamelib/missions.py Mon May 07 21:24:23 2012 +0200 @@ -3,7 +3,7 @@ from random import random -from products import HAND_WEAPON, VEHICLE, PATHOGEN, DOOMSDAY_DEVICE +from schematics import HAND_WEAPON, VEHICLE, PATHOGEN, DOOMSDAY_DEVICE MAJOR_SETBACK, FAILURE, SUCCESS, MAJOR_SUCCESS, GAME_WIN = range(5) diff -r a2980cc9a060 -r 373c57ab4140 gamelib/products.py --- a/gamelib/products.py Mon May 07 21:23:54 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -from gamelib import research -from gamelib.game_base import Science - - -# Kinds of product. -HAND_WEAPON = 'hand weapon' -VEHICLE = 'vehicle' -DOOMSDAY_DEVICE = 'doomsday device' -PATHOGEN = 'pathogen' - - -class Product(Science): - ACQUISITION_CHANCE = 0.8 - COST = None - UPGRADE_REQUIREMENT = 1 - STARTING_PRODUCT = False - SCIENCE_TYPE = 'product' - CATEGORIES = () - - def can_spend(self, lab): - extra = self.UPGRADE_REQUIREMENT * self.points + 1 - return lab.meet_requirements(self, extra) - - def is_a(self, category): - return category in self.CATEGORIES - - -class MachineGun(Product): - NAME = "Machine gun" - COST = 100 - CATEGORIES = (HAND_WEAPON,) - STARTING_PRODUCT = True - - def __init__(self, points=0): - self.points = 1 - - def spend_point(self): - raise NotImplementedError() - - def can_spend(self, lab): - return False - - -class LightningGun(Product): - NAME = "Lightning gun" - COST = 300 - CATEGORIES = (HAND_WEAPON,) - PREREQUISITES = ( - (research.Tesla, 1), - ) - - -class TeslaTank(Product): - NAME = "Tesla tank" - COST = 1000 - CATEGORIES = (VEHICLE,) - PREREQUISITES = ( - (research.Tesla, 3), - ) - - -class DoomsdayVirus(Product): - NAME = "Doomsday virus" - COST = 100000 - CATEGORIES = (DOOMSDAY_DEVICE, PATHOGEN) - PREREQUISITES = ( - (research.Biogenetics, 5), - ) diff -r a2980cc9a060 -r 373c57ab4140 gamelib/schematics.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/schematics.py Mon May 07 21:24:23 2012 +0200 @@ -0,0 +1,68 @@ +from gamelib import research +from gamelib.game_base import Science + + +# Kinds of schematic. +HAND_WEAPON = 'hand weapon' +VEHICLE = 'vehicle' +DOOMSDAY_DEVICE = 'doomsday device' +PATHOGEN = 'pathogen' + + +class Schematic(Science): + ACQUISITION_CHANCE = 0.8 + COST = None + UPGRADE_REQUIREMENT = 1 + STARTING_PRODUCT = False + SCIENCE_TYPE = 'schematic' + CATEGORIES = () + + def can_spend(self, lab): + extra = self.UPGRADE_REQUIREMENT * self.points + 1 + return lab.meet_requirements(self, extra) + + def is_a(self, category): + return category in self.CATEGORIES + + +class MachineGun(Schematic): + NAME = "Machine gun" + COST = 100 + CATEGORIES = (HAND_WEAPON,) + STARTING_PRODUCT = True + + def __init__(self, points=0): + self.points = 1 + + def spend_point(self): + raise NotImplementedError() + + def can_spend(self, lab): + return False + + +class LightningGun(Schematic): + NAME = "Lightning gun" + COST = 300 + CATEGORIES = (HAND_WEAPON,) + PREREQUISITES = ( + (research.Tesla, 1), + ) + + +class TeslaTank(Schematic): + NAME = "Tesla tank" + COST = 1000 + CATEGORIES = (VEHICLE,) + PREREQUISITES = ( + (research.Tesla, 3), + ) + + +class DoomsdayVirus(Schematic): + NAME = "Doomsday virus" + COST = 100000 + CATEGORIES = (DOOMSDAY_DEVICE, PATHOGEN) + PREREQUISITES = ( + (research.Biogenetics, 5), + ) diff -r a2980cc9a060 -r 373c57ab4140 gamelib/tests/test_lab.py --- a/gamelib/tests/test_lab.py Mon May 07 21:23:54 2012 +0200 +++ b/gamelib/tests/test_lab.py Mon May 07 21:24:23 2012 +0200 @@ -1,7 +1,7 @@ from unittest import TestCase from gamelib.lab import Lab -from gamelib import research, products +from gamelib import research, schematics LAB_DATA = { @@ -25,11 +25,11 @@ all_sciences.add(type(science)) self.assertTrue(len(all_sciences) > 3) - def test_find_new_products(self): + def test_find_new_schematics(self): lab = Lab(LAB_DATA) - new_products = lab.find_new_products() - self.assertTrue(products.TeslaTank in new_products) - self.assertTrue(products.DoomsdayVirus not in new_products) + new_schematics = lab.find_new_schematics() + self.assertTrue(schematics.TeslaTank in new_schematics) + self.assertTrue(schematics.DoomsdayVirus not in new_schematics) def test_find_new_research(self): lab = Lab(LAB_DATA) @@ -41,8 +41,8 @@ # Check that we save what we loaded. lab = Lab(LAB_DATA) self.assertEqual(LAB_DATA, lab.save_data()) - # Add a product and check that it gets saved as well. - lab._gain_science(products.LightningGun()) + # Add a schematic and check that it gets saved as well. + lab._gain_science(schematics.LightningGun()) new_science = dict( - LAB_DATA['science'].items() + [('product.LightningGun', 0)]) + LAB_DATA['science'].items() + [('schematic.LightningGun', 0)]) self.assertEqual({'science': new_science}, lab.save_data())