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

Class Producer

source code

component.Component --+
                      |
                     Producer

Class for objects, that produce something.

Instance Methods [hide private]
 
__init__(self, auto_init=True, start_finished=False, productionlines=None, utilization_calculator=None, is_mine_for=None, settler_upgrade_lines=None, **kwargs)
Used for initialization code that does not require any other components.
source code
 
__init(self) source code
 
initialize(self)
This is called by the ComponentHolder after it set the instance.
source code
 
get_production_lines_by_level(self, level) source code
 
create_production(self, id, load=False) source code
 
create_production_line(self, id)
Creates a production line instance, this is meant only for data transfer and READONLY use! If you want to use production lines for anything else, go the proper way of the production class.
source code
 
add_production_by_id(self, production_line_id)
Convenience method.
source code
 
update_capacity_utilization(self)
Called by the scheduler to update the utilization regularly
source code
 
capacity_utilization(self) source code
 
capacity_utilization_below(self, limit) source code
 
load(self, db, worldid)
This does on load what __init() and initalize() together do on constructions at runtime.
source code
 
save(self, db)
Will do nothing, but will be always called in componentholder code, even if not implemented.
source code
 
add_production(self, production) source code
 
_production_finished(self, production)
Gets called when a production finishes.
source code
 
finish_production_now(self)
Cheat, makes current production finish right now (and produce the resources).
source code
 
has_production_line(self, prod_line_id)
Checks if this instance has a production with a certain production line id
source code
 
remove_production(self, production)
Removes a production instance.
source code
 
remove_production_by_id(self, prod_line_id)
Convenience method.
source code
 
alter_production_time(self, modifier, prod_line_id=None)
Multiplies the original production time of all production lines by modifier
source code
 
remove(self)
Removes component and reference to instance
source code
 
_get_current_state(self)
Returns the current state of the producer.
source code
 
get_productions(self)
Returns all productions, inactive and active ones, as list
source code
 
get_production_lines(self)
Returns all production lines that have been added.
source code
 
_get_production(self, prod_line_id)
Returns a production of this producer by a production line id.
source code
 
is_active(self, production=None)
Checks if a production, or the at least one production if production is None, is active
source code
 
set_active(self, production=None, active=True)
Pause or unpause a production (aka set it active/inactive).
source code
 
_add_status_icon(self, icon) source code
 
_update_decommissioned_icon(self)
Add or remove decommissioned icon.
source code
 
toggle_active(self, production=None) source code
 
_on_production_change(self)
Makes the instance act according to the producers current state
source code
 
get_status_icons(self) source code
 
__str__(self) source code
 
get_production_progress(self)
Returns the current progress of the active production.
source code
 
__set_utilization(self, utilization) source code
    Inherited from component.Component
 
__gt__(self, other) source code
 
__lt__(self, other) source code
 
session(self) source code
Class Methods [hide private]
 
get_instance(cls, arguments=None)
This function is used to instantiate classes from yaml data.
source code
Class Variables [hide private]
  log = logging.getLogger("world.production")
  NAME = "producer"
hash(x)
  DEPENDENCIES = [StorageComponent]
  utilization_mapping = {'FieldUtilization': FieldUtilization, '...
  produces_resource = True
  production_class = Production
Method Details [hide private]

__init__(self, auto_init=True, start_finished=False, productionlines=None, utilization_calculator=None, is_mine_for=None, settler_upgrade_lines=None, **kwargs)
(Constructor)

source code 

Used for initialization code that does not require any other components. This is always called first, on construction and on load.

Parameters:
  • productionline - yaml-dict for prod line data. Must not be changed since it is cached.
  • utilization_calculator - one of utilization_mapping
  • settler_upgrade_lines - data for settler upgrades. can one day be generalized to other upgrades
  • auto_init - bool. If True, the producer automatically adds one production for each production_line.
Overrides: component.Component.__init__

initialize(self)

source code 

This is called by the ComponentHolder after it set the instance. Use this to initialize any needed infrastructure. When this is called, it is guaranteed that all other components this one has a dependency on have been added, but initalize may not have been called on them, only __init__. It is only called after construction, not on load().

Overrides: component.Component.initialize
(inherited documentation)

create_production(self, id, load=False)

source code 
Parameters:
  • id - production line id
  • load - whether the production is used for loading.

add_production_by_id(self, production_line_id)

source code 

Convenience method.

Parameters:
  • production_line_id - Production line from db

capacity_utilization(self)

source code 
Decorators:
  • @property

load(self, db, worldid)

source code 

This does on load what __init() and initalize() together do on constructions at runtime. Has to set up everything that is not setup in __init__(). Note that on loading __init__() is called with the data needed by the component through get_instance(), but initialize() is not, so any work needed for loading as well should be moved to a separate method and called here.

Overrides: component.Component.load
(inherited documentation)

save(self, db)

source code 

Will do nothing, but will be always called in componentholder code, even if not implemented.

Overrides: component.Component.save
(inherited documentation)

_production_finished(self, production)

source code 

Gets called when a production finishes. Intercepts call, adds info and forwards it

finish_production_now(self)

source code 

Cheat, makes current production finish right now (and produce the resources). Useful to make trees fully grown at game start.

remove_production(self, production)

source code 

Removes a production instance.

Parameters:
  • production - Production instance

remove_production_by_id(self, prod_line_id)

source code 

Convenience method. Assumes, that this production line id has been added to this instance.

Parameters:
  • prod_line_id - production line id to remove

alter_production_time(self, modifier, prod_line_id=None)

source code 

Multiplies the original production time of all production lines by modifier

Parameters:
  • modifier - a numeric value
  • prod_line_id - id of production line to alter. None means every production line

remove(self)

source code 

Removes component and reference to instance

Overrides: component.Component.remove
(inherited documentation)

_get_current_state(self)

source code 

Returns the current state of the producer. It is the most important state of all productions combined. Check the PRODUCTION.STATES constant for list of states and their importance.

get_production_lines(self)

source code 

Returns all production lines that have been added.

Returns:
a list of prodline ids

_get_production(self, prod_line_id)

source code 

Returns a production of this producer by a production line id.

Returns:
instance of Production or None

set_active(self, production=None, active=True)

source code 

Pause or unpause a production (aka set it active/inactive). see also: is_active, toggle_active

Parameters:
  • production - instance of Production. if None, we do it to all productions.
  • active - whether to set it active or inactive

get_instance(cls, arguments=None)
Class Method

source code 

This function is used to instantiate classes from yaml data. Override this if the component has more than just a basic constructor with primitive types (takes custom classes as arguments, e.g. Storages)

Overrides: component.Component.get_instance
(inherited documentation)

Class Variable Details [hide private]

utilization_mapping

Value:
{'FieldUtilization': FieldUtilization, 'FullUtilization': FullUtilizat\
ion}