Package horizons :: Package world :: Package production :: Module production :: Class Production
[hide private]
[frames] | no frames]

Class Production

source code

util.changelistener.ChangeListener --+
                                     |
                                    Production

Class for production to be used by ResourceHandler. Controls production and starts it by watching the assigned building's inventory, which is virtually the only "interface" to the building. This ensures independence and encapsulation from the building code.

A Production is active by default, but you can pause it.

Before we can start production, we check certain assertions, i.e. if we have all the resources, that the production takes and if there is enough space to store the produced goods.

It has basic states, which are useful for e.g. setting animation. Changes in state can be observed via ChangeListener interface.

Instance Methods [hide private]
 
__init__(self, inventory, owner_inventory, prod_id, prod_data, start_finished=False, load=False, **kwargs) source code
 
save(self, db, owner_id)
owner_id: worldid of the owner of the producer object that owns this production
source code
 
load(self, db, worldid) source code
 
remove(self) source code
 
get_production_line_id(self)
Returns id of production line
source code
 
get_consumed_resources(self)
Res that are consumed here.
source code
 
get_produced_resources(self)
Res that are produced here.
source code
 
get_production_time(self) source code
 
get_produced_units(self)
@return dict of produced units {unit_id: amount}
source code
 
changes_animation(self)
Returns whether the production should change the animation
source code
 
get_state(self)
Returns the Production's current state
source code
 
get_animating_state(self)
Returns the production's current state, but only if it effects the animation, else None
source code
 
toggle_pause(self) source code
 
is_paused(self) source code
 
pause(self, pause=True) source code
 
finish_production_now(self)
Makes the production finish now
source code
 
alter_production_time(self, modifier)
@see ProductionLine.alter_production_time
source code
 
get_state_history_times(self, ignore_pause)
Returns the part of time 0 <= x <= 1 the production has been in a state during the last history_length ticks.
source code
 
get_age(self) source code
 
get_unstorable_produced_res(self)
Returns all produced res for whose there is no space
source code
 
_get_producing_callback(self)
Returns the callback used during the process of producing (state: producing)
source code
 
_get_first_relevant_tick(self, ignore_pause)
Returns the first tick that is relevant for production utilization calculation
source code
 
_clean_state_history(self)
remove the part of the state history that is too old to matter
source code
 
_changed(self)
Calls every listener when an object changed
source code
 
_check_inventory(self)
Called when assigned building's inventory changed in some way
source code
 
_start_production(self)
Actually start production.
source code
 
_produce(self)
Called when there are enough res in the inventory for starting production
source code
 
_finished_producing(self, continue_producing=True, **kwargs)
Called when the production finishes.
source code
 
_add_listeners(self, check_now=False)
Listen for changes in the inventory from now on.
source code
 
_remove_listeners(self) source code
 
_give_produced_res(self)
Put produces goods to the inventory
source code
 
_check_available_res(self)
Checks if all required resources are there.
source code
 
_remove_res_to_expend(self)
Removes the resources from the inventory, that production takes.
source code
 
_check_for_space_for_produced_res(self)
Checks if there is enough space in the inventory for the res, we want to produce.
source code
 
__str__(self) source code
    Inherited from util.changelistener.ChangeListener
 
add_change_listener(self, listener, call_listener_now=False, no_duplicates=False) source code
 
add_remove_listener(self, listener, no_duplicates=False)
A listener that listens for removal of the object
source code
 
clear_change_listeners(self)
Removes all change listeners
source code
 
discard_change_listener(self, listener)
Remove listener if it's there
source code
 
discard_remove_listener(self, listener) source code
 
end(self) source code
 
has_change_listener(self, listener) source code
 
has_remove_listener(self, listener) source code
 
remove_change_listener(self, listener) source code
 
remove_remove_listener(self, listener) source code
Class Variables [hide private]
  log = logging.getLogger('world.production')
  uses_gold = False
  keep_original_prod_line = False
Method Details [hide private]

__init__(self, inventory, owner_inventory, prod_id, prod_data, start_finished=False, load=False, **kwargs)
(Constructor)

source code 
Parameters:
  • inventory - interface to the world, take res from here and put output back there
  • owner_inventory - same as inventory, but for gold. Usually the players'.
  • prod_id - int id of the production line
  • prod_data - ?
  • start_finished - Whether to start at the final state of a production
  • load - set to True if this production is supposed to load a saved production
Overrides: util.changelistener.ChangeListener.__init__

load(self, db, worldid)

source code 
Overrides: util.changelistener.ChangeListener.load

remove(self)

source code 
Overrides: util.changelistener.ChangeListener.remove

get_consumed_resources(self)

source code 

Res that are consumed here. Returns dict {res:amount}. Interface for _prod_line.

get_produced_resources(self)

source code 

Res that are produced here. Returns dict {res:amount}. Interface for _prod_line.

_get_first_relevant_tick(self, ignore_pause)

source code 

Returns the first tick that is relevant for production utilization calculation

Parameters:
  • ignore_pause - whether to ignore the time spent in the pause state

_changed(self)

source code 

Calls every listener when an object changed

Overrides: util.changelistener.ChangeListener._changed
(inherited documentation)

_start_production(self)

source code 

Actually start production. Sets self to producing state

_check_available_res(self)

source code 

Checks if all required resources are there.

Returns:
bool, True if we can start production

_check_for_space_for_produced_res(self)

source code 

Checks if there is enough space in the inventory for the res, we want to produce. @return bool, True if everything can fit.