import pygame
from pygame.locals import *
from random import *

class Civ(object): 
    def __init__(self,lmap,stadeMax=5,statusMax=4,pStade=10,pStatus=20):
        self.lmap = lmap
        self.stade = 1
        self.status = 1
        self.stadeMax = stadeMax
        self.statusMax = statusMax
        self.pStade = pStade #1 chance sur pStade d'évoluer de stade
        self.pStatus = pStatus #1 chance sur pStatus de partir de côté

    def evolve(self):
        #Random evolve from the current state to some next one
        if(self.status==1):
            if(randint(1,self.pStade)==1):
                self.stade += 1
                print("Evolved")
            else:
                if(randint(1,self.pStatus)==1):
                    self.status += 1
                    print("Degraded")
        else:
            if(randint(1,self.pStatus)==1):
                self.status += 1
                print("Degraded")

        if(self.stade>self.stadeMax): self.stade = self.stadeMax
        if(self.status>self.statusMax): self.status = self.statusMax

    def unEvolve(self,force=0):
        #Regression
        force = int(force/30)
        self.stade -= force
        self.status -= force
        if(self.stade<1): self.stade = 1
        if(self.status<1): self.status = 1
        print("Regressed "+str(force)+" ages")

    def isGood(self):
        #Return True if the current civ is good enough to win the game
        if(self.stade>=self.stadeMax-1): return True
        return False

    def isBad(self):
        #Return True if the current civ is bad enough to lose the game
        if(self.status>=self.statusMax): return True
        return False

    def getAge(self):
        #Retourne une liste des époques par leurs noms
        s = ""
        if(self.status==1): s += "Happy"
        if(self.status==2): s += "Balanced"
        if(self.status==3): s += "Dark"
        if(self.status==4): s += "Chaotic"
        s+= " "
        if(self.stade==1): s += "Prehistoric Age"
        if(self.stade==2): s += "Antiquity Age"
        if(self.stade==3): s += "Middle Age"
        if(self.stade==4): s += "Modern Age"
        if(self.stade==5): s += "Information Age"
        s += " : Year "+str(self.lmap.year)
        return s
