Exemple #1
0
    def generateRandom(proficiency=20):
        values = [0, 0, 0]
        for i in range(proficiency):
            n = r.randint(0, 2)
            while values[n] >= 8 and not r.random() < 0.1:
                n = r.randint(0, 2)

            values[n] += 1

        return CharacterAttributes(*values)
Exemple #2
0
    def __init__(self, pos, time, context, inevitable=False):
        participantNodes = context.getCloseLocations(
            pos,
            5,
            sort=lambda n: n.getAttachedContext(
                HistoryLocation).getLocationType().independant)

        startPart = None
        determination = 0
        for pn in participantNodes:
            p = pn.getAttachedContext(HistoryLocation)
            deter = p.getPersonality().determination + r.randint(-2, 2)
            if (deter > determination):
                startPart = p
                determination = deter
                break

        if not startPart:
            self.setSuccessful(False)
            return

        if not inevitable and startPart.getPersonality(
        ).warmonger >= r.randint(1, 15):
            self.setAlternateEvent(
                HEvBattle(pos, time, context, inevitable=True))
            return

        self.participants = [startPart]

        for p in participantNodes:
            part = p.getAttachedContext(HistoryLocation)
            if part == startPart:
                continue
            if (part.getMainAdmin() != self.participants[0].getMainAdmin() and
                    not part in startPart.getCurrentState().friendlyLocations):
                self.participants.append(p.getAttachedContext(HistoryLocation))
                break

        if len(self.participants) != 2:
            self.setSuccessful(False)
            return

        if abs(self.participants[0].getPos() -
               self.participants[1].getPos()) > 15:
            self.setSuccessful(False)
            return

        characters = []
        if startPart.getCurrentState().leader:
            characters = [startPart.getCurrentState().leader]

        super().__init__(pos, time, characters, context, self.participants)
        self.updateCharacters()
        self.updateLocations()
Exemple #3
0
    def __init__(self, pos, time, context):
        characters = context.getHistoryMap().getCharacters()
        r.shuffle(characters)

        for char in characters:

            if not (char.getAge(time) >=
                    char.getCurrentState().getRace().adultAge
                    and char.getCurrentState().alive
                    and len(char.getCurrentState().items) < r.randint(1, 3)
                    and not (not char.getCurrentState().occupation.warrior
                             and r.random() < 0.5)):
                continue

            boughtItem = None
            seller = None
            for c in char.getCurrentState().livingPlace.getCurrentCharacters(
                    time):
                if (c.getCurrentState().itemsOnSale and c != char
                        and c.getCurrentState().alive):

                    boughtItem = None
                    for item in c.getCurrentState().itemsOnSale:

                        if item.quality > char.getCurrentState(
                        ).occupationLevel + r.randint(-1, 1):
                            continue
                        if item.art and char.getCurrentState(
                        ).occupation.warrior:
                            continue

                        boughtItem = item
                        break

                    if boughtItem:
                        seller = c
                        break

            if not seller:
                continue
            self.seller = seller
            self.buyer = char
            self.item = boughtItem
            self.importantItem = r.random() < 0.5

            super().__init__(
                self.seller.getCurrentState().livingPlace.getPos(), time,
                [self.seller, self.buyer], context)
            self.updateCharacters()
            return

        self.setSuccessful(False)
        return
Exemple #4
0
    def __init__(self, pos, time, context):
        characters = context.getHistoryMap().getCharacters()
        r.shuffle(characters)

        char = None
        for c in characters:
            if (c.getAge(time) >= c.getCurrentState().getRace().adultAge
                    and c.getCurrentState().alive
                    and c.getCurrentState().traveling >= r.randint(1, 21)
                    and c.getCurrentState().getPersonality().determination >=
                    r.randint(1, 15)
                    and (not c.getCurrentState().leadershipPos)):

                char = c
                break

        if not char:
            self.setSuccessful(False)
            return

        possible = None
        if c.getCurrentState().traveling >= r.randint(1, 31):
            possible = context.getCloseLocations(
                pos,
                5,
                sort=lambda n: n.getAttachedContext(
                    HistoryLocation).getLocationType().livable)
        else:
            possible = context.getCloseLocations(
                pos,
                5,
                sort=lambda n: n.getAttachedContext(
                    HistoryLocation).getLocationType().independant)

        possibleLocs = []
        for p in possible:
            possibleLocs.append(p.getAttachedContext(HistoryLocation))

        if r.random() < 0.3:
            self.target = r.choice(possibleLocs)
        else:
            popCount = []
            self.target = max(possibleLocs,
                              key=lambda p: len(p.getCurrentCharacters(time)))

        self.prevLoc = char.getCurrentState().livingPlace
        super().__init__(self.target.getPos(), time, [char], context,
                         [self.target, self.prevLoc])
        self.updateCharacters()
        self.updateLocations()
Exemple #5
0
    def __init__(self, pos, time, context):
        self.location = None
        locations = context.getHistoryMap().getLocations()
        r.shuffle(locations)

        for l in locations:
            if not l.getCurrentState().existing:
                self.location = l
                break

        if not self.location:
            self.setSuccessful(False)
            return

        possFounderSource = context.getCloseLocations(
            self.location.getPos(),
            5,
            sort=lambda n: n.getAttachedContext(HistoryLocation
                                                ).getLocationType().livable)

        possFounders = []
        for p in possFounderSource:
            possFounders += p.getAttachedContext(
                HistoryLocation).getCurrentCharacters(time)

        founder = None
        legendarity = 0
        for f in possFounders:
            if (f.getAge(time) >= f.getCurrentState().getRace().adultAge
                    and (not f.getCurrentState().leadershipPos)
                    and f.getLegendarity() >= r.randint(4, 15)
                    and f.getCurrentState().getPersonality().determination >=
                    r.randint(1, 15) and f.getLegendarity() >= legendarity):

                founder = f
                legendarity = f.getLegendarity()

        if not founder:
            self.setSuccessful(False)
            return

        self.founder = founder
        self.founderHome = self.founder.getCurrentState().livingPlace

        super().__init__(self.location.getPos(), time, [self.founder], context,
                         [self.location, self.founderHome])
        self.updateLocations()
        self.updateCharacters()
Exemple #6
0
    def __init__(self, pos, time, context):
        newCharacter = HistoricCharacter(self)

        self.attributes = CharacterAttributes.generateRandom(r.randint(17, 20))
        if r.random() >= 0.1:
            self.race = context.getRacialMap().getClosest(
                pos).getObject().getName()
        else:
            self.race = r.choice(
                context.getRacialMap().getNodes()).getObject().getName()

        self.livingPlace = context.getClosestLocation(
            pos,
            sort=lambda n: n.getAttachedContext(HistoryLocation).
            getLocationType().livable).getAttachedContext(HistoryLocation)

        super().__init__(self.livingPlace.getPos(), time, [newCharacter],
                         context, [self.livingPlace])
        context.getHistoryMap().addCharacter(newCharacter)

        self.name = "Person" + str(
            context.getHistoryMap().getCharacters().index(newCharacter))
        self.personality = CharacterState.generatePersonality()

        self.updateCharacters()
        self.updateLocations()
Exemple #7
0
    def __init__(self, pos, time, context):
        self.location = None
        locations = context.getHistoryMap().getLocations()
        r.shuffle(locations)

        for l in locations:
            if not l.getCurrentState().existing:
                self.location = l
                break

        if not self.location:
            self.setSuccessful(False)
            return

        assert not self.location.getCurrentState().existing

        possible = context.getCloseLocations(
            self.location.getPos(),
            5,
            sort=lambda n: n.getAttachedContext(
                HistoryLocation).getLocationType().independant)
        self.admin = None
        for p in possible:
            if (p.getAttachedContext(HistoryLocation).getLocationType().size >=
                    self.location.getLocationType().size
                    and p.getAttachedContext(HistoryLocation).getPersonality(
                    ).determination >= r.randint(1, 10)):
                self.admin = p.getAttachedContext(HistoryLocation)
                break

        locs = [self.location, self.admin] if self.admin else [self.location]
        super().__init__(self.location.getPos(), time, [], context, locs)
        self.updateLocations()
def generateHistory(fineMap, racialMap, civilLocMap, generalLocMap, historyLen,
                    eventCellSize, maxCellEvents):

    unprocessedEvents = []
    historyMap = HistoryMap(fineMap.getMapSize())
    context = HistoricMapContext(fineMap, racialMap, civilLocMap,
                                 generalLocMap, historyMap)

    locCount = {}
    for civilLoc in civilLocMap.getNodes() + generalLocMap.getNodes():
        name = civilLoc.getObject().getName() + str(
            locCount.setdefault(civilLoc.getObject().getName(), 0))
        histLoc = HistoryLocation(civilLoc, context, r.random() < 0.3, name)
        historyMap.addLocation(histLoc)
        locCount[civilLoc.getObject().getName()] += 1

    for year in range(historyLen):
        cCount = 0
        for c in historyMap.getCharacters():
            if c.getCurrentState().alive:
                cCount += 1

        for x in range(round((fineMap.getMapSize() / eventCellSize).a)):
            for y in range(round((fineMap.getMapSize() / eventCellSize).b)):
                pos = Vector2.random(eventCellSize) + Vector2(
                    x, y) * eventCellSize
                eventCount = r.randint(
                    0,
                    min(maxCellEvents,
                        math.ceil(maxCellEvents * (cCount / 200) + 0.01)))
                i = 0
                while i < eventCount:

                    eventIndex = r.random() * sum(
                        HISTORIC_EVENT_CHANCES.values())

                    Event = None
                    for ev in HISTORIC_EVENTS:
                        eventIndex -= HISTORIC_EVENT_CHANCES[ev]
                        if eventIndex <= 0:
                            Event = ev
                            break

                    event = Event(pos, year, context)

                    while event.getAlternateEvent():
                        event = event.getAlternateEvent()

                    if not event.getSuccessful():
                        continue

                    historyMap.addEvent(event)

                    i += 1

    for loc in historyMap.getLocations():
        if not loc.getCurrentState().existing:
            loc.destroy(context)

    return historyMap
Exemple #9
0
    def __init__(self, pos, time, context):
        characters = context.getHistoryMap().getCharacters()
        r.shuffle(characters)

        char = None
        age = 0
        for c in characters:
            newAge = (time - c.getBirthTime())
            if newAge > age and c.getCurrentState().alive:
                age = newAge
                char = c

        if not char or age < r.randint(c.getCurrentState().getRace().oldAge,
                                       c.getCurrentState().getRace().maxAge):
            self.setSuccessful(False)
            return

        self.character = char
        self.location = char.getCurrentState().livingPlace
        self.items = char.getCurrentState().items

        super().__init__(char.getCurrentState().livingPlace.getPos(), time,
                         [char], context, [char.getCurrentState().livingPlace])
        self.updateCharacters()
        self.updateLocations()
Exemple #10
0
 def __init__(self, quality):
     global ITEM_NUMBER
     super().__init__(quality,
                      weapon=True,
                      attrMod=CharacterAttributes(quality + r.randint(0, 1),
                                                  0, 0))
     self.name = "Weapon" + str(ITEM_NUMBER)
     ITEM_NUMBER += 1
Exemple #11
0
    def __init__(self, pos, time, context):
        characters = context.getHistoryMap().getCharacters()
        r.shuffle(characters)
        self.character = None
        for c in characters:
            if (c.getCurrentState().alive and
                    c.getAge(time) >= c.getCurrentState().getRace().adultAge
                    and
                    c.getCurrentState().livingPlace.getCurrentState().leader
                    and not c.getCurrentState().leadershipPos):
                self.character = c
                break

        if not self.character:
            self.setSuccessful(False)
            return

        self.target = self.character.getCurrentState(
        ).livingPlace.getCurrentState().leader

        if ((not self.target.getPersonality().extreme) and
            (self.target.getPersonality().determination < r.randint(5, 15))):

            self.setSuccessful(False)
            return

        if (self.character.getPersonality().determination < r.randint(5, 15) or
                self.character.getPersonality().warmonger < r.randint(5, 15)):
            self.setSuccessful(False)
            return

        self.location = self.character.getCurrentState().livingPlace
        self.stolenItems = self.target.getCurrentState().items
        super().__init__(self.location.getPos(), time,
                         [self.character, self.target], context,
                         [self.location])
        self.updateCharacters()
        self.updateLocations()
Exemple #12
0
 def __init__(self):
     self.livingPlace = None
     self.alive = None
     self.name = ""
     self.attributes = None
     self.race = None
     self.occupation = CharacterOccupationPreset.NONE
     self.occupationLevel = 1
     self.leadershipPos = None
     self.noLeader = False
     self.traveling = r.randint(1,20)
     self.items = []
     self.itemsOnSale = []
     self.personalityTraits = []
Exemple #13
0
    def __init__(self, pos, time, context):
        self.character = None
        for c in context.getHistoryMap().getCharacters():
            if (c.getCurrentState().alive and
                    c.getAge(time) >= c.getCurrentState().getRace().adultAge
                    and c.getCurrentState().getAttributes().getMind() >=
                    r.randint(5, 12)
                    and c.getCurrentState().getPersonality().determination >=
                    r.randint(5, 15) and (not c.getCurrentState().noLeader) and
                (not c.getCurrentState().livingPlace.getCurrentState().leader)
                ):
                self.character = c
                break

        if not self.character:
            self.setSuccessful(False)
            return

        self.location = self.character.getCurrentState().livingPlace
        super().__init__(self.location.getPos(), time, [self.character],
                         context, [self.location])
        self.updateCharacters()
        self.updateLocations()
Exemple #14
0
    def __init__(self, pos, time, context):
        characters = context.getHistoryMap().getCharacters()
        r.shuffle(characters)
        self.character = None
        for c in characters:
            if (c.getCurrentState().alive
                    and c.getCurrentState().leadershipPos):
                self.character = c
                break

        if not self.character:
            self.setSuccessful(False)
            return

        if self.character.getPersonality().determination > r.randint(1, 8):
            self.setSuccessful(False)
            return

        self.location = self.character.getCurrentState().livingPlace
        super().__init__(self.location.getPos(), time, [self.character],
                         context, [self.location])
        self.updateCharacters()
        self.updateLocations()
Exemple #15
0
    def __init__(self, pos, time, context):
        characters = context.getHistoryMap().getCharacters()
        r.shuffle(characters)

        char = None
        for c in characters:
            if (c.getCurrentState().alive
                    and c.getCurrentState().occupation.craftsman
                    and len(c.getCurrentState().items) < 1
                    and c.getCurrentState().getAttributes().getMind() >=
                    r.randint(1, 14)):
                char = c
                break

        if not char:
            self.setSuccessful(False)
            return

        self.createdItem = char.getCurrentState().occupation.creationType(
            char.getCurrentState().occupationLevel)
        super().__init__(char.getCurrentState().livingPlace.getPos(), time,
                         [char], context)
        self.updateCharacters()
def generateHydraulicMap(mapSize, fineBiomes, sourceCellSize, sourceChance, iterationCount, smallStepLength, largeStepLength, mergeDistance):
    fineBiomeNodes = fineBiomes.getNodes()

    hydroGraph = MapGraph(0,mapSize)

    streamsInProcess = []

    #generate stream sources
    usedFineBiomes = []
    
    for x in range(sourceCellSize.a//2, mapSize.a, sourceCellSize.a):
        for y in range(sourceCellSize.b//2, mapSize.b, sourceCellSize.b):
            if r.random()<sourceChance:
                source = fineBiomes.getClosest(Vector2(x,y))
                
                if source in usedFineBiomes:
                    continue
                
                tags = source.getCollectiveTags()
                acceptable = False
                for tag in tags:
                    if tag.getName()=="mountainous" and tag.getWeight()>=1:
                        acceptable = True
                        break
                    if tag.getName()=="hilly" and tag.getWeight()>=0.5:
                        acceptable = True
                        break
                    if tag.getName()=="forested" and tag.getWeight()>=1:
                        acceptable = True
                        break
                    
                if not acceptable:
                    continue
                
                usedFineBiomes.append(source)
                streamsInProcess.append(HydraulicNode(source.getPos(),1, evaluateRiverTarget(source), isSource=True))

    #iterate stream extension

    for i in range(iterationCount):
        
        newStreams = []

        for stream in streamsInProcess:

            #try twice, once with large step, once with small step
            stepLength = smallStepLength
            for j in range(2):
                #ignore streams outside map
                posDiff = mapSize - stream.getPos()
                if posDiff.a<0 or posDiff.b<0 or posDiff.a>mapSize.a or posDiff.b>mapSize.b:
                    break

                #assign direction if not present
                if not stream.getDirection():
                    angles = []
                    angle = 0
                    while angle<1:
                        angles.append(angle)
                        angle+=0.1

                    r.shuffle(angles)
                    minScore = 1000
                    for angle in angles:
                        direction = Vector2.UNIT.rotate(angle).floatMultiply(stepLength)
                        pos = direction + stream.pos
                        score = evaluateRiverTarget(fineBiomes.getClosest(pos))
                        if score<stream.score and score<minScore :
                            stream.setDirection(direction)
                            minScore = score

                #generate possible next positions
                possiblePos = []

                angleStep = 0.02
                angleRange = 0.2

                angle = -angleRange
                while angle <=angleRange:
                    possAngle = angle + r.random()*angleStep

                    possPos = Vector2.UNIT.rotate(possAngle).floatMultiply(stepLength) + stream.getPos()

                    possiblePos.append(possPos)
                    angle += angleStep

                streamParents = stream.getParents()
                riverScore = {}
                for pos in possiblePos:
                    closest = fineBiomes.getClosest(pos)
                    riverScore[pos] = evaluateRiverTarget(closest)*(0.8+r.random()*0.4)
                    if closest in usedFineBiomes:
                        riverScore[pos] = 100

                #get highest scoring positions
                targetPos = max( possiblePos,key= lambda pos: stream.score-riverScore[pos] )

                #merge streams if close enough
                closestStream = hydroGraph.getClosest(targetPos)
                if closestStream:
                    closestDist = abs(closestStream.getPos() - targetPos)
                    for nstream in newStreams:
                        if abs(nstream.getPos() - targetPos) < closestDist:
                            closestStream = nstream
                            closestDist = abs(nstream.getPos() - targetPos)

                if (not closestStream in streamParents) and closestStream and (
                    abs(closestStream.getPos() - targetPos) < mergeDistance if not closestStream.stagnant else mergeDistance * max(1,min(1.7,1.7*closestStream.getPower()/5))):
                    
                    closestStream.addStreamInput(stream)
                    break

                #maybe set stream as stagnant if difference isn't large enough
##                if (stream.score-riverScore[pos])<r.random()*0.2-0.3 and (stream.length-2)%5==0 and r.random()<0.7:
##                    stream.stagnant = True

                if (stream.score-riverScore[pos])<r.random()*0.2-0.4 and stream.length>r.randint(3,8):
                    if j==0:
                        stepLength = largeStepLength
                        continue
                    else:
                        stream.stagnant = True
                        break

                #create next node
                newStream = HydraulicNode(targetPos, 0.05, riverScore[pos], targetPos-stream.getPos() )
                stream.addStreamOutput(newStream)
                newStreams.append(newStream)
                usedFineBiomes.append(fineBiomes.getClosest(targetPos))
                break
            
        for stream in streamsInProcess:
            hydroGraph.addNode(stream)
        streamsInProcess = newStreams


    #generate map graph data
    hydraulicObjects = {}
    for hydroObj in GetLoadedObjectClass("hydraulics"):
        hydraulicObjects[hydroObj.getName()] = hydroObj
        
    for node in hydroGraph.getNodes():
        node.generateMapGraphData(hydraulicObjects)
        

    return hydroGraph
Exemple #17
0
 def __init__(self, location, prio, description, name=""):
     self.description = rtt.generateText(description)
     self.prio = prio
     self.name = name + str(ru.randint(0, 100))
     super().__init__(location)
Exemple #18
0
    def __init__(self, pos, time, context, inevitable=False):
        participantNodes = context.getCloseLocations(
            pos,
            5,
            sort=lambda n: n.getAttachedContext(
                HistoryLocation).getLocationType().independant)

        startPart = None
        determination = 0
        for pn in participantNodes:
            p = pn.getAttachedContext(HistoryLocation)
            deter = p.getPersonality().determination + r.randint(-2, 2)
            if (deter > determination):
                startPart = p
                determination = deter
                break

        if not startPart:
            self.setSuccessful(False)
            return

        if not inevitable and startPart.getPersonality().warmonger < r.randint(
                1, 15):
            self.setAlternateEvent(
                HEvDiplomaticBattle(pos, time, context, inevitable=True))
            return

        self.participants = [startPart]

        self.reconquest = False

        lostLocations = []  #prevent conquest of own admin
        for l in startPart.getCurrentState().lostLocations:
            if l.getMainAdmin() != startPart.getMainAdmin():
                lostLocations.append(l)

        if lostLocations:
            self.reconquest = True
            self.participants.append(r.choice(lostLocations))
        else:
            for p in participantNodes:
                part = p.getAttachedContext(HistoryLocation)
                if part == startPart:
                    continue
                if ((part.getMainAdmin() !=
                     self.participants[0].getMainAdmin()) and
                    (not part
                     in startPart.getCurrentState().friendlyLocations)):

                    self.participants.append(
                        p.getAttachedContext(HistoryLocation))
                    break

        if len(self.participants) != 2:
            self.setSuccessful(False)
            return

        if abs(self.participants[0].getPos() -
               self.participants[1].getPos()) > 15:
            self.setSuccessful(False)
            return

        characters = []
        self.dyingCharacters = []
        for part in self.participants:
            for char in part.getCurrentCharacters(time):
                if (char.getAge(time) >=
                        char.getCurrentState().getRace().adultAge
                        and char.getCurrentState().occupation.warrior):
                    characters.append(char)
                    if char.getCurrentState().getAttributes().getBody(
                    ) < r.randint(1, 12):
                        self.dyingCharacters.append(char)

        for c in characters:
            while characters.count(c) > 1:
                characters.remove(c)

        winScore = [0, 0]
        i = 0
        for p in self.participants:
            winScore[i] += r.randint(0, 2)
            for c in p.getCurrentCharacters(time):
                if not c in self.dyingCharacters and c.getCurrentState(
                ).occupation.warrior:
                    winScore[i] += 1
            i += 1

        if winScore[0] > winScore[1]:
            self.winner = self.participants[0]
            self.loser = self.participants[1]
        else:
            self.winner = self.participants[1]
            self.loser = self.participants[0]

        self.conquest = False
        if abs(winScore[0] - winScore[1]) > r.randint(1, 3):
            self.conquest = True

        if self.conquest:
            self.formerAdmin = self.loser.getCurrentState().adminLocation
            if self.formerAdmin:
                self.participants.append(self.formerAdmin)

        self.traumata = {}
        for c in characters:
            if (not c in self.dyingCharacters
                    and c.getPersonality().determination < r.randint(5, 15)
                    and len(c.getCurrentState().personalityTraits) < 4
                    and c.getCurrentState().getAttributes().getMind() <
                    r.randint(1, 12)):

                trauma = r.choice(PersonalityTraits.TRAUMATIC_TRAITS)
                while trauma in c.getCurrentState().personalityTraits:
                    trauma = r.choice(PersonalityTraits.TRAUMATIC_TRAITS)
                self.traumata[c] = trauma

        self.spoils = []
        for c in self.dyingCharacters:
            self.spoils += c.getCurrentState().items

        self.aggressor = startPart.getCurrentState().leader
        if self.aggressor and not self.aggressor in characters:
            characters.append(self.aggressor)

        super().__init__(pos, time, characters, context, self.participants)
        self.updateCharacters()
        self.updateLocations()