Ejemplo n.º 1
0
def get_trait_bypass_value(name, default, sentinel):
    """Fetch a bypassed trait value or return the default from OptionsDB.

    In OptionsDB a section AI.config.trait can contain default trait
    values for all of the AIs or specific AIs which will override the
    default value passed into this function.

    If there is an XML element in config.xml/persistent_config.xml
    AI.config.trait.<name of trait here>.force
    with a non zero value

    ,then the value of AI.config.trait.<name of trait here>.<AI ID number here>

    will be checked.  If it is not the sentinel value (typically -1) the it
    will be returned as the trait's value.

    Otherwise the value of
    AI.config.trait.<name of trait here>.all
    is checked.  Again if it is not the sentinel value it will ovverride
    the returned value for trait.

    If trait is not overriden by one of the above values, then the
    default is used.

    Here is an example section providing override values aggression and the
    empire-id trait.

    <mAI>
      <config>
        <trait>
          <aggression>
            <force>1</force>
            <all>4</all>
            <AI_0>5</AI_0>
            <AI_1>4</AI_1>
            <AI_2>3</AI_2>
            <AI_3>2</AI_3>
            <AI_4>1</AI_4>
            <AI_5>0</AI_5>
          </aggression>
          <empire-id>
            <force>1</force>
            <AI_0>5</AI_0>
            <AI_1>4</AI_1>
            <AI_2>3</AI_2>
            <AI_3>2</AI_3>
            <AI_4>1</AI_4>
            <AI_5>0</AI_5>
          </empire-id>
        </trait>
      </config>
    </mAI>

    :param name: Name of the trait.
    :type name: string
    :param default: Default value of the trait.
    :type default: int
    :param sentinel: A value indicating no valid value.
    :type sentinel: int
    :return: The trait
    :rtype: Trait

    """

    force_option = "AI.config.trait.%s.force" % (name, )
    if not fo.getOptionsDBOptionBool(force_option):
        return default

    per_id_option = "AI.config.trait.%s.%s" % (name, fo.playerName())
    all_id_option = "AI.config.trait.%s.all" % (name, )

    trait = fo.getOptionsDBOptionInt(per_id_option)
    if trait is None or trait == sentinel:
        trait = fo.getOptionsDBOptionInt(all_id_option)

    if trait is None or trait == sentinel:
        trait = default
    else:
        print "%s trait bypassed and set to %s for %s" % (name, repr(trait),
                                                          fo.playerName())
    return trait
Ejemplo n.º 2
0
def get_trait_bypass_value(name: str, default: int, sentinel: int) -> int:
    """Fetch a bypassed trait value or return the default from OptionsDB.

    In OptionsDB a section ai.config.trait can contain default trait
    values for all of the AIs or specific AIs which will override the
    default value passed into this function.

    If there is an XML element in config.xml/persistent_config.xml
    ai.trait.<name of trait here>.force.enabled
    with a non zero value

    ,then the value of ai.trait.<name of trait here>.ai_<AI ID number here>

    will be checked.  If it is not the sentinel value (typically -1) the it
    will be returned as the trait's value.

    Otherwise the value of
    ai.trait.<name of trait here>.default
    is checked.  Again if it is not the sentinel value it will ovverride
    the returned value for trait.

    If trait is not overriden by one of the above values, then the
    default is used.

    Here is an example section providing override values aggression and the
    empire-id trait.

    <ai>
      <trait>
        <aggression>
          <force>
            <enabled>1</enabled>
          </force>
          <default>4</default>
          <ai_0>5</ai_0>
          <ai_1>4</ai_1>
          <ai_2>3</ai_2>
          <ai_3>2</ai_3>
          <ai_4>1</ai_4>
          <ai_5>0</ai_5>
        </aggression>
        <empire-id>
          <force>
            <enabled>1</enabled>
          </force>
          <ai_0>5</ai_0>
          <ai_1>4</ai_1>
          <ai_2>3</ai_2>
          <ai_3>2</ai_3>
          <ai_4>1</ai_4>
          <ai_5>0</ai_5>
        </empire-id>
      </trait>
    </ai>

    :param name: Name of the trait.
    :param default: Default value of the trait.
    :param sentinel: A value indicating no valid value.
    :return: The trait
    """

    force_option = "ai.trait.%s.force.enabled" % (name.lower(), )
    if not fo.getOptionsDBOptionBool(force_option):
        return default

    per_id_option = "ai.trait.%s.%s" % (name.lower(), fo.playerName().lower())
    all_id_option = "ai.trait.%s.default" % (name.lower(), )

    trait = fo.getOptionsDBOptionInt(per_id_option)
    if trait is None or trait == sentinel:
        trait = fo.getOptionsDBOptionInt(all_id_option)

    if trait is None or trait == sentinel:
        trait = default
    else:
        debug("%s trait bypassed and set to %s for %s", name, repr(trait),
              fo.playerName())
    return trait
Ejemplo n.º 3
0
def get_trait_bypass_value(name, default, sentinel):
    """Fetch a bypassed trait value or return the default from OptionsDB.

    In OptionsDB a section AI.config.trait can contain default trait
    values for all of the AIs or specific AIs which will override the
    default value passed into this function.

    If there is an XML element in config.xml/persistent_config.xml
    AI.config.trait.<name of trait here>.force
    with a non zero value

    ,then the value of AI.config.trait.<name of trait here>.<AI ID number here>

    will be checked.  If it is not the sentinel value (typically -1) the it
    will be returned as the trait's value.

    Otherwise the value of
    AI.config.trait.<name of trait here>.all
    is checked.  Again if it is not the sentinel value it will ovverride
    the returned value for trait.

    If trait is not overriden by one of the above values, then the
    default is used.

    Here is an example section providing override values aggression and the
    empire-id trait.

    <mAI>
      <config>
        <trait>
          <aggression>
            <force>1</force>
            <all>4</all>
            <AI_0>5</AI_0>
            <AI_1>4</AI_1>
            <AI_2>3</AI_2>
            <AI_3>2</AI_3>
            <AI_4>1</AI_4>
            <AI_5>0</AI_5>
          </aggression>
          <empire-id>
            <force>1</force>
            <AI_0>5</AI_0>
            <AI_1>4</AI_1>
            <AI_2>3</AI_2>
            <AI_3>2</AI_3>
            <AI_4>1</AI_4>
            <AI_5>0</AI_5>
          </empire-id>
        </trait>
      </config>
    </mAI>

    :param name: Name of the trait.
    :type name: string
    :param default: Default value of the trait.
    :type default: int
    :param sentinel: A value indicating no valid value.
    :type sentinel: int
    :return: The trait
    :rtype: Trait

    """

    force_option = "AI.config.trait.%s.force" % (name,)
    if not fo.getOptionsDBOptionBool(force_option):
        return default

    per_id_option = "AI.config.trait.%s.%s" % (name, fo.playerName())
    all_id_option = "AI.config.trait.%s.all" % (name,)

    trait = fo.getOptionsDBOptionInt(per_id_option)
    if trait is None or trait == sentinel:
        trait = fo.getOptionsDBOptionInt(all_id_option)

    if trait is None or trait == sentinel:
        trait = default
    else:
        print "%s trait bypassed and set to %s for %s" % (name, repr(trait), fo.playerName())
    return trait