Version updates for 0.30c.
[singularity-git.git] / code / item.py
blob5254af7231bd0559965a229680d398c5c91ef46d
1 #file: item.py
2 #Copyright (C) 2005,2006,2008 Evil Mr Henry, Phil Bordelon, and FunnyMan3595
3 #This file is part of Endgame: Singularity.
5 #Endgame: Singularity is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Endgame: Singularity is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Endgame: Singularity; if not, write to the Free Software
17 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #This file contains the item class.
21 import buyable
23 class ItemClass(buyable.BuyableClass):
24 def __init__(self, name, description, cost, prerequisites, item_type,
25 item_qual, buildable):
26 super(ItemClass, self).__init__(name, description, cost, prerequisites,
27 type="item")
29 self.item_type = item_type
30 self.item_qual = item_qual
31 self.buildable = buildable
32 if self.buildable == ["all"]:
33 self.buildable = ["N AMERICA", "S AMERICA", "EUROPE", "ASIA",
34 "AFRICA", "ANTARCTIC", "OCEAN", "MOON", "FAR REACHES",
35 "TRANSDIMENSIONAL", "AUSTRALIA"]
36 if self.buildable == ["pop"]:
37 self.buildable = ["N AMERICA", "S AMERICA", "EUROPE", "ASIA",
38 "AFRICA", "AUSTRALIA"]
40 def get_info(self):
41 import g
42 basic_text = super(ItemClass, self).get_info()
43 if self.item_type == "cpu":
44 return basic_text.replace("---", "Generates %s CPU.\n---" %
45 g.add_commas(self.item_qual))
46 return basic_text
48 class Item(buyable.Buyable):
49 def __init__(self, item_type, base=None, count=1):
50 super(Item, self).__init__(item_type, count)
51 self.item_qual = item_type.item_qual
52 self.base = base
54 def convert_from(self, load_version):
55 super(Item, self).convert_from(load_version)
56 if load_version < 4.91: # < r5_pre
57 import g
58 self.type = g.items[self.type.id]
60 def finish(self):
61 super(Item, self).finish()
62 if self.base:
63 if self.type.item_type == "cpu":
64 self.base.raw_cpu = self.item_qual * self.count
65 self.base.recalc_cpu()
67 def __iadd__(self, other):
68 if isinstance(other, Item) and self.base == other.base \
69 and self.type == other.type:
70 if other.count == 0:
71 return self
73 # Calculate what's been paid and what is left to be paid.
74 total_cost_paid = self.cost_paid + other.cost_paid
75 self.total_cost += other.total_cost
77 # Labor takes as long as the less complete item would need.
78 total_cost_paid[buyable.labor] = min(self.cost_paid[buyable.labor],
79 other.cost_paid[buyable.labor])
80 self.total_cost[buyable.labor] = other.total_cost[buyable.labor]
82 # Set what we've paid (and hence what we have left to pay).
83 self.cost_paid = total_cost_paid
85 # Increase the size of this stack.
86 self.count += other.count
88 # Tell the base it has no CPU for now.
89 self.base.raw_cpu = 0
90 self.base.recalc_cpu
92 # See if we're done or not.
93 self.done = False
94 self.work_on(0, 0, 0)
96 return self
97 else:
98 return NotImplemented