Exemplo n.º 1
0
    def add_message(self,
                    type_,
                    diary=False,
                    journal=True,
                    turn_delta=0,
                    **kwargs):
        from the_tale.linguistics import logic

        if not diary and not self.is_active and not self.is_premium:
            # do not process journal messages for inactive heroes (and clear it if needed)
            self.messages.clear()
            return

        lexicon_key, externals, restrictions = logic.prepair_get_text(
            type_, kwargs)

        message_constructor = messages.MessageSurrogate.create

        if lexicon_key is None:
            message_constructor = messages.MessageSurrogate.create_fake

        message = message_constructor(
            key=lexicon_key if lexicon_key else type_,
            externals=externals,
            turn_delta=turn_delta,
            restrictions=restrictions,
            position=self.position.get_description() if diary else u'')

        self.push_message(message, diary=diary, journal=journal)
Exemplo n.º 2
0
    def get_message_surrogate(self, type, externals):
        from the_tale.linguistics.logic import prepair_get_text

        externals.update(self.substitution)

        lexicon_key, externals, restrictions = prepair_get_text(type, externals, quiet=True)

        if lexicon_key is None: return None

        return messages.MessageSurrogate.create(key=lexicon_key,
                                                externals=externals,
                                                restrictions=restrictions,
                                                position=self.hero.position.get_description())
Exemplo n.º 3
0
    def get_message_surrogate(self, type, externals):
        from the_tale.linguistics.logic import prepair_get_text

        externals.update(self.substitution)

        lexicon_key, externals, restrictions = prepair_get_text(type,
                                                                externals,
                                                                quiet=True)

        if lexicon_key is None: return None

        return messages.MessageSurrogate.create(
            key=lexicon_key,
            externals=externals,
            restrictions=restrictions,
            position=self.hero.position.get_description())
Exemplo n.º 4
0
    def add_message(self, type_, diary=False, journal=True, turn_delta=0, **kwargs):
        from the_tale.linguistics import logic

        if not diary and not self.is_active and not self.is_premium:
            # do not process journal messages for inactive heroes (and clear it if needed)
            self.journal.clear()
            return

        lexicon_key, externals, restrictions = logic.prepair_get_text(type_, kwargs)

        message_constructor = messages.MessageSurrogate.create

        if lexicon_key is None:
            message_constructor = messages.MessageSurrogate.create_fake

        message = message_constructor(key=lexicon_key if lexicon_key else type_,
                                      externals=externals,
                                      turn_delta=turn_delta,
                                      restrictions=restrictions,
                                      position=self.position.get_description() if diary else u'')

        self.push_message(message, diary=diary, journal=journal)
Exemplo n.º 5
0
def generate_history(name_forms, gender, race, honor, peacefulness, archetype, upbringing, first_death, age):
    from the_tale.linguistics import logic as linguistics_logic
    from the_tale.linguistics.lexicon.dictionary import noun
    from the_tale.linguistics.relations import TEMPLATE_RESTRICTION_GROUP
    from the_tale.linguistics.storage import restrictions_storage
    from the_tale.linguistics import objects as linguistics_objects

    name = noun(name_forms+['']*6, 'мр,од,ед' if gender.is_MALE else 'жр,од,ед')

    restrictions = (restrictions_storage.get_restriction(TEMPLATE_RESTRICTION_GROUP.GENDER, gender.value).id,
                    restrictions_storage.get_restriction(TEMPLATE_RESTRICTION_GROUP.RACE, race.value).id,
                    restrictions_storage.get_restriction(TEMPLATE_RESTRICTION_GROUP.HABIT_HONOR, honor.value).id,
                    restrictions_storage.get_restriction(TEMPLATE_RESTRICTION_GROUP.HABIT_PEACEFULNESS, peacefulness.value).id,
                    restrictions_storage.get_restriction(TEMPLATE_RESTRICTION_GROUP.ARCHETYPE, archetype.value).id,
                    restrictions_storage.get_restriction(TEMPLATE_RESTRICTION_GROUP.UPBRINGING, upbringing.value).id,
                    restrictions_storage.get_restriction(TEMPLATE_RESTRICTION_GROUP.FIRST_DEATH, first_death.value).id,
                    restrictions_storage.get_restriction(TEMPLATE_RESTRICTION_GROUP.AGE, age.value).id)

    hero_variable = linguistics_objects.UTGVariable(word=name, restrictions=restrictions)

    types = ['hero_history_birth',
             'hero_history_childhood',
             'hero_history_death']

    texts = []

    for type in types:
        lexicon_key, externals, restrictions = linguistics_logic.prepair_get_text(type, {'hero': hero_variable})

        text = linguistics_logic.render_text(lexicon_key=lexicon_key,
                                             externals=externals,
                                             restrictions=restrictions,
                                             quiet=True,
                                             with_nearest_distance=True,
                                             fake_text=lambda *argv, **kwargs: None)
        texts.append(text)

    return texts