Package horizons :: Package util :: Module uhdbaccessor :: Class UhDbAccessor
[hide private]
[frames] | no frames]

Class UhDbAccessor

source code

dbreader.DbReader --+
                    |
                   UhDbAccessor

UhDbAccessor is the class that contains the sql code. It is meant to keep all the sql code in a central place, to make it reusable and maintainable.

It should be used as a utility to remove data access code from places where it doesn't belong, such as game logic.

Due to historic reasons, sql code is spread over the game code; for now, it is left at places, that are data access routines (e.g. unit/building class).

Instance Methods [hide private]
 
__init__(self, dbfile) source code
 
get_res_name(self, id)
Returns the translated name for a specific resource id.
source code
 
get_res_inventory_display(self, id) source code
 
get_res_value(self, id)
Returns the resource's value
source code
 
get_res(self, only_tradeable=False, only_inventory=False)
Returns a list of all resources.
source code
 
get_sound_file(self, soundname)
Returns the soundfile to the related sound name.
source code
 
get_related_building_ids(self, building_class_id)
Returns list of building ids related to building_class_id.
source code
 
get_related_building_ids_for_menu(self, building_class_id)
Returns list of building ids related to building_class_id, which should be shown in the build_related menu.
source code
 
get_inverse_related_building_ids(self, building_class_id)
Inverse of the above, gives the lumberjack to the tree.
source code
 
get_buildings_with_related_buildings(self)
Returns all buildings that have related buildings
source code
 
get_msg_visibility(self, msg_id_string)
Returns: int: for how long in seconds the message will stay visible
source code
 
get_msg_text(self, msg_id_string) source code
 
get_msg_icon_id(self, msg_id_string)
Returns: int: id
source code
 
get_msg_icon_path(self, msg_id_string)
Returns: str: path attribute to message icon suitable for ImageButton
source code
 
get_settler_name(self, level)
Returns the name of inhabitants for a specific tier.
source code
 
get_settler_house_name(self, level)
Returns name of the residential building for a specific tier
source code
 
get_settler_tax_income(self, level) source code
 
get_tier_inhabitants_max(self, level)
Returns the upper limit of inhabitants per house for a specific tier.
source code
 
get_tier_inhabitants_min(self, level)
Returns the lower limit of inhabitants per house for a specific tier.
source code
 
get_upper_happiness_limit(self) source code
 
get_lower_happiness_limit(self) source code
 
get_player_start_res(self)
Returns resources, that players should get at startup as dict: { res : amount }
source code
 
get_storage_building_capacity(self, storage_type)
Returns the amount that a storage building can store of every resource.
source code
 
get_random_ai_name(self, locale, used_names)
Returns a random name compatible with the given locale.
source code
 
get_random_tile_set(self, ground_id)
Returns a tile set for a tile of type ground_id
source code
 
get_translucent_buildings(self)
Returns building types that should become translucent on demand
source code
 
get_weapon_stackable(self, weapon_id)
Returns True if the weapon is stackable, False otherwise.
source code
 
get_weapon_attack_radius(self, weapon_id)
Returns weapon's attack radius modifier.
source code
 
get_unit_type_name(self, type_id)
Returns the name of a unit type identified by its type
source code
 
get_unit_tooltip(self, unit_id)
Tries to identify unit properties to display as tooltip.
source code
    Inherited from dbreader.DbReader
 
__call__(self, command, *args)
Executes a sql command.
source code
 
cached_query(self, command, *args)
Executes a sql command and saves its result in a dict.
source code
 
close(self)
Closes the db
source code
 
execute_many(self, command, parameters)
Executes a sql command for each sequence or mapping found in parameters.
source code
 
execute_script(self, script)
Executes a multiline script.
source code
Method Details [hide private]

__init__(self, dbfile)
(Constructor)

source code 
Parameters:
  • file - str containing the database file.
Overrides: dbreader.DbReader.__init__

get_res_name(self, id)

source code 

Returns the translated name for a specific resource id.

Parameters:
  • id - int resource's id, of which the name is returned

get_res_value(self, id)

source code 

Returns the resource's value

Parameters:
  • id - resource id
Returns:
float value

get_res(self, only_tradeable=False, only_inventory=False)

source code 

Returns a list of all resources.

Parameters:
  • only_tradeable - return only those you can trade.
  • only_inventory - return only those displayed in inventories.
Returns:
list of resource ids

get_sound_file(self, soundname)

source code 

Returns the soundfile to the related sound name.

Parameters:
  • sound - string, key in table sounds_special

get_related_building_ids(self, building_class_id)

source code 

Returns list of building ids related to building_class_id.

Parameters:
  • building_class_id - class of building, int @return list of building class ids
Decorators:
  • @decorators.cachedmethod

get_related_building_ids_for_menu(self, building_class_id)

source code 

Returns list of building ids related to building_class_id, which should be shown in the build_related menu.

Parameters:
  • building_class_id - class of building, int @return list of building class ids
Decorators:
  • @decorators.cachedmethod

get_inverse_related_building_ids(self, building_class_id)

source code 

Inverse of the above, gives the lumberjack to the tree.

Parameters:
  • building_class_id - class of building, int @return list of building class ids
Decorators:
  • @decorators.cachedmethod

get_buildings_with_related_buildings(self)

source code 

Returns all buildings that have related buildings

Decorators:
  • @decorators.cachedmethod

get_msg_visibility(self, msg_id_string)

source code 
Parameters:
  • msg_id_string - string id of the message
Returns:
int: for how long in seconds the message will stay visible

get_msg_text(self, msg_id_string)

source code 
Parameters:
  • msg_id_string - string id of the message

get_msg_icon_id(self, msg_id_string)

source code 
Parameters:
  • msg_id_string - string id of the message
Returns:
int: id

get_msg_icon_path(self, msg_id_string)

source code 
Parameters:
  • msg_id_string - string id of the message
Returns:
str: path attribute to message icon suitable for ImageButton

get_settler_name(self, level)

source code 

Returns the name of inhabitants for a specific tier.

Parameters:
  • level - int - which tier
Returns:
string - inhabitant name

get_settler_house_name(self, level)

source code 

Returns name of the residential building for a specific tier

Parameters:
  • level - int - which tier
Returns:
string - housing name

get_tier_inhabitants_max(self, level)

source code 

Returns the upper limit of inhabitants per house for a specific tier. Inhabitants will try to increase their tier upon exceeding this value.

Parameters:
  • level - int - which tier

get_tier_inhabitants_min(self, level)

source code 

Returns the lower limit of inhabitants per house for a specific tier. This limit coincides with the max. amount of the previous tier. Inhabitants will decrease their tier after falling below.

Parameters:
  • level - int - which tier

get_storage_building_capacity(self, storage_type)

source code 

Returns the amount that a storage building can store of every resource.

Parameters:
  • storage_type - building class id
Decorators:
  • @decorators.cachedmethod

get_random_ai_name(self, locale, used_names)

source code 

Returns a random name compatible with the given locale. If there are no unused names left, None is returned.

get_translucent_buildings(self)

source code 

Returns building types that should become translucent on demand

Decorators:
  • @decorators.cachedmethod

get_unit_tooltip(self, unit_id)

source code 

Tries to identify unit properties to display as tooltip. #TODO Should be extended later to also include movement speed, etc.