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.
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
,
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"]
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
))
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
54 def convert_from(self
, load_version
):
55 super(Item
, self
).convert_from(load_version
)
56 if load_version
< 4.91: # < r5_pre
58 self
.type = g
.items
[self
.type.id]
61 super(Item
, self
).finish()
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:
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.
92 # See if we're done or not.