コード例 #1
0
ファイル: army.py プロジェクト: matteli/histemul
    def update(self, date):
        if self.way and self.next_province != self.way[-1]: #change way since last update
            self.next_province = self.way[-1]
            self.time_walking = 0

        if self.time_walking >= self.location.size: #enter a new province
            self.time_walking -= self.location.size
            province = self.next_province
            self.location = province
            self.way.pop()
            if self.way:
                self.next_province = self.way[-1]
            else:
                self.next_province = None
                self.attitude = 'normal'

            #when enter a new province, look if there is enemy or already a battle
            person = self.for_the
            battle = province.battle

            if not battle:
                war = None
                enemies = []
                for army_in_province in province.armies:
                    if not war:
                        war = person.in_war_against(army_in_province.for_the)['war']
                        enemies.append(army_in_province)
                    else:
                        w = person.in_war_against(army_in_province.for_the)[0]['war']
                        if w == war:
                            enemies.append(army_in_province)
                if enemies: #enemy so battle
                    self.stop()
                    Battle.new(war, province, [self], enemies)

            else:
                war = battle.war
                if person in war.aggressors:
                    self.stop()
                    battle.add_aggressor(self)
                if person in war.defenders:
                    self.stop()
                    battle.add_defender(self)

        if self.next_province:
            self.time_walking += 500 * self.location.land.walkable
        else:
            self.time_walking = 0

        #morale
        if self.attitude == 'normal':
            if self.morale < 95:
                self.morale += 5
            else:
                self.morale = 100
        
        self.save()