Ejemplo n.º 1
0
    def clearCensus(self):
        self.poweredZoneCount = 0
        self.unpoweredZoneCount = 0
        self.roadTotal = 0
        self.railTotal = 0
        self.resPop = 0
        self.comPop = 0
        self.indPop = 0
        self.resZoneCount = 0
        self.comZoneCount = 0
        self.indZoneCount = 0
        self.hospitalCount = 0
        self.churchCount = 0
        self.policeCount = 0
        self.fireStationCount = 0
        self.stadiumCount = 0
        self.firePop = 0
        self.coalCount = 0
        self.nuclearCount = 0
        self.seaportCount = 0
        self.airportCount = 0
        self.powerPlants = []

        self.fireStMap = create2dArray(self.smWidth, self.smHeight, 0)
        self.policeMap = create2dArray(self.smWidth, self.smHeight, 0)
Ejemplo n.º 2
0
    def clearCensus(self):
        self.poweredZoneCount = 0
        self.unpoweredZoneCount = 0
        self.roadTotal = 0
        self.railTotal = 0
        self.resPop = 0
        self.comPop = 0
        self.indPop = 0
        self.resZoneCount = 0
        self.comZoneCount = 0
        self.indZoneCount = 0
        self.hospitalCount = 0
        self.churchCount = 0
        self.policeCount = 0
        self.fireStationCount = 0
        self.stadiumCount = 0
        self.firePop = 0
        self.coalCount = 0
        self.nuclearCount = 0
        self.seaportCount = 0
        self.airportCount = 0
        self.powerPlants = []

        self.fireStMap = create2dArray(self.smWidth, self.smHeight, 0)
        self.policeMap = create2dArray(self.smWidth, self.smHeight, 0)
Ejemplo n.º 3
0
    def resetEng(self, eng):
        self._engine = eng
        self.animated = dict()
        self.visibleAnimated = dict()
        del self.domain
        self.domain = vertexdomain.create_domain(*('v2i', 't3f'))
        self.nullDomain = vertexdomain.create_domain(*('v2i', 't3f'))

        if self.regions is not None:
            for row in xrange(self.rows):
                for column in xrange(self.columns):
                    self.regions[row][column].delete()

        if eng is None:
            return
        self.rows = int(math.ceil(float(eng.getWidth()) / self.regionSize))
        self.columns = int(math.ceil(float(eng.getHeight()) / self.regionSize))

        self.regions = create2dArray(self.rows, self.columns)
        self.regionsVisible = create2dArray(self.rows, self.columns, True)
        for row in xrange(self.rows):
            for column in xrange(self.columns):
                texCoords = []
                vertices = []
                sX = row * self.regionSize
                sY = column * self.regionSize
                for x in xrange(sX, sX + self.regionSize):
                    for y in xrange(sY, sY + self.regionSize):
                        x1 = int(x * TILESIZE)
                        y1 = int(y * TILESIZE)
                        x2 = int(x1 + TILESIZE)
                        y2 = int(y1 + TILESIZE)
                        if eng.testBounds(x, y):
                            vertices.extend([x1, y1, x2, y1, x2, y2, x1, y2])
                            tImg = self.tileImagesLoader.getTileImage(
                                eng.getTile(x, y))
                            try:
                                texCoords.extend(tImg.tex_coords)
                            except AttributeError:
                                assert isinstance(tImg, TileAnimation)
                                texCoords.extend(
                                    tImg.frames[0].image.tex_coords)
                                self.visibleAnimated[(x, y)] = tImg
                        else:
                            vertices.extend([0, 0, 0, 0, 0, 0, 0, 0])
                            texCoords.extend([
                                0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
                            ])
                self.regions[row][column] = self._add(
                    len(vertices) // 2, vertices, texCoords)
Ejemplo n.º 4
0
 def __init__(self):
     self.offsetX = 0  # ?
     self.offsetY = 0  # ?
     self.tiles = create2dArray(0, 0, CLEAR)
     self.sounds = []
     self.toolResult = ToolResult.NONE
     self.cost = 0
Ejemplo n.º 5
0
 def __init__(self):
     self.offsetX = 0  # ?
     self.offsetY = 0  # ?
     self.tiles = create2dArray(0, 0, CLEAR)
     self.sounds = []
     self.toolResult = ToolResult.NONE
     self.cost = 0
Ejemplo n.º 6
0
    def resetEng(self, eng):
        self._engine = eng
        self.animated = dict()
        self.visibleAnimated = dict()
        del self.domain
        self.domain = vertexdomain.create_domain(*('v2i', 't3f'))
        self.nullDomain = vertexdomain.create_domain(*('v2i', 't3f'))

        if self.regions is not None:
            for row in xrange(self.rows):
                for column in xrange(self.columns):
                    self.regions[row][column].delete()

        if eng is None:
            return
        self.rows = int(math.ceil(float(eng.getWidth()) / self.regionSize))
        self.columns = int(math.ceil(float(eng.getHeight()) / self.regionSize))

        self.regions = create2dArray(self.rows, self.columns)
        self.regionsVisible = create2dArray(self.rows, self.columns, True)
        for row in xrange(self.rows):
            for column in xrange(self.columns):
                texCoords = []
                vertices = []
                sX = row * self.regionSize
                sY = column * self.regionSize
                for x in xrange(sX, sX + self.regionSize):
                    for y in xrange(sY, sY + self.regionSize):
                        x1 = int(x * TILESIZE)
                        y1 = int(y * TILESIZE)
                        x2 = int(x1 + TILESIZE)
                        y2 = int(y1 + TILESIZE)
                        if eng.testBounds(x, y):
                            vertices.extend([x1, y1, x2, y1, x2, y2, x1, y2])
                            tImg = self.tileImagesLoader.getTileImage(eng.getTile(x, y))
                            try:
                                texCoords.extend(tImg.tex_coords)
                            except AttributeError:
                                assert isinstance(tImg, TileAnimation)
                                texCoords.extend(tImg.frames[0].image.tex_coords)
                                self.visibleAnimated[(x, y)] = tImg
                        else:
                            vertices.extend([0, 0, 0, 0, 0, 0, 0, 0])
                            texCoords.extend([0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])
                self.regions[row][column] = self._add(len(vertices) // 2, vertices, texCoords)
Ejemplo n.º 7
0
    def resetEng(self, eng):
        self.viewportGroup.setFocus(0, 0)
        self.toolPreview = None
        self.deletePowerIndicators()
        self.deleteToolCursor()

        self.tileMapRenderer.resetEng(eng)

        if eng is not None:
            eng.push_handlers(self)
            self.mapWidth = eng.getWidth()
            self.mapHeight = eng.getHeight()
            self.viewportGroup.setMapSize(self.mapWidth * TILESIZE, self.mapHeight * TILESIZE)
            self.noPowerIndicators = create2dArray(self.mapWidth, self.mapHeight, None)
Ejemplo n.º 8
0
    def popDenScan(self):

        xTot = 0
        yTot = 0
        zoneCount = 0
        width = self.getWidth()
        height = self.getHeight()
        tem = create2dArray((height + 1) // 2, (width + 1) // 2)

        for x in xrange(width):
            for y in xrange(height):
                tile = self.getTile(x, y)
                if isZoneCenter(tile):
                    den = self.computePopDen(x, y, tile) * 8
                    #print "density: " + str(den)
                    if den > 254:
                        den = 254
                    tem[y//2][x//2] = den
                    xTot += x
                    yTot += y
                    zoneCount += 1

        '''print "--------------------------------"
        print "before"
        print tem'''

        tem = self.doSmooth(tem)
        tem = self.doSmooth(tem)
        tem = self.doSmooth(tem)

        '''print "--------------------------------"
        print "after"
        print tem'''

        for x in xrange((width + 1) // 2):
            for y in xrange((height + 1) // 2):
                #print x,y,2*tem[y][x]
                self.popDensity[y][x] = 2 * tem[y][x]
                #print self.popDensity[y][x]

        self.distIntMarket()

        if zoneCount != 0:
            self.centerMassX = xTot // zoneCount
            self.centerMassY = yTot // zoneCount
        else:
            self.centerMassX = (width + 1) // 2
            self.centerMassY = (height + 1) // 2
Ejemplo n.º 9
0
    def powerScan(self):
        self.powerMap = create2dArray(self.getHeight(), self.getWidth(), False)

        maxPower = self.coalCount * 700 + self.nuclearCount * 2000
        numPower = 0

        while len(self.powerPlants) != 0:
            loc = self.powerPlants.pop()
            aDir = 4
            while True:
                numPower += 1
                if numPower > maxPower:
                    self.cityMessage("general", "BROWNOUTS_REPORT")
                    return
                r, loc = self.movePowerLocation(loc, aDir)
                self.powerMap[loc.y][loc.x] = True

                conNum = 0
                theDir = 0
                while theDir < 4 and conNum < 2:
                    ''' test for conductive tiles in direction(theDir) '''
                    xSave = loc.x
                    ySave = loc.y
                    rv = False
                    r, loc = self.movePowerLocation(loc, theDir)
                    if r:
                        t = self.getTile(loc.x, loc.y)
                        spec = tiles.get(t)
                        conducts =  spec is not None and spec.canConduct
                        rv = (
                            conducts and
                            t != NUCLEAR and
                            t != POWERPLANT and
                            not self.hasPower(loc.x, loc.y))
                    loc.x = xSave
                    loc.y = ySave
                    r = rv

                    if r:
                        conNum += 1
                        aDir = theDir
                    theDir += 1

                if conNum > 1:
                    self.powerPlants.append(CityLocation(loc.x, loc.y))
                if conNum == 0:
                    break
Ejemplo n.º 10
0
    def popDenScan(self):

        xTot = 0
        yTot = 0
        zoneCount = 0
        width = self.getWidth()
        height = self.getHeight()
        tem = create2dArray((height + 1) // 2, (width + 1) // 2)

        for x in xrange(width):
            for y in xrange(height):
                tile = self.getTile(x, y)
                if isZoneCenter(tile):
                    den = self.computePopDen(x, y, tile) * 8
                    #print "density: " + str(den)
                    if den > 254:
                        den = 254
                    tem[y // 2][x // 2] = den
                    xTot += x
                    yTot += y
                    zoneCount += 1
        '''print "--------------------------------"
        print "before"
        print tem'''

        tem = self.doSmooth(tem)
        tem = self.doSmooth(tem)
        tem = self.doSmooth(tem)
        '''print "--------------------------------"
        print "after"
        print tem'''

        for x in xrange((width + 1) // 2):
            for y in xrange((height + 1) // 2):
                #print x,y,2*tem[y][x]
                self.popDensity[y][x] = 2 * tem[y][x]
                #print self.popDensity[y][x]

        self.distIntMarket()

        if zoneCount != 0:
            self.centerMassX = xTot // zoneCount
            self.centerMassY = yTot // zoneCount
        else:
            self.centerMassX = (width + 1) // 2
            self.centerMassY = (height + 1) // 2
Ejemplo n.º 11
0
    def powerScan(self):
        self.powerMap = create2dArray(self.getHeight(), self.getWidth(), False)

        maxPower = self.coalCount * 700 + self.nuclearCount * 2000
        numPower = 0

        while len(self.powerPlants) != 0:
            loc = self.powerPlants.pop()
            aDir = 4
            while True:
                numPower += 1
                if numPower > maxPower:
                    self.cityMessage("general", "BROWNOUTS_REPORT")
                    return
                r, loc = self.movePowerLocation(loc, aDir)
                self.powerMap[loc.y][loc.x] = True

                conNum = 0
                theDir = 0
                while theDir < 4 and conNum < 2:
                    ''' test for conductive tiles in direction(theDir) '''
                    xSave = loc.x
                    ySave = loc.y
                    rv = False
                    r, loc = self.movePowerLocation(loc, theDir)
                    if r:
                        t = self.getTile(loc.x, loc.y)
                        spec = tiles.get(t)
                        conducts = spec is not None and spec.canConduct
                        rv = (conducts and t != NUCLEAR and t != POWERPLANT
                              and not self.hasPower(loc.x, loc.y))
                    loc.x = xSave
                    loc.y = ySave
                    r = rv

                    if r:
                        conNum += 1
                        aDir = theDir
                    theDir += 1

                if conNum > 1:
                    self.powerPlants.append(CityLocation(loc.x, loc.y))
                if conNum == 0:
                    break
Ejemplo n.º 12
0
    def smoothTerrain(qTem):
        QWX = len(qTem[0])
        QWY = len(qTem)

        mem = create2dArray(QWY, QWX, 0)
        for y in xrange(QWY):
            for x in xrange(QWX):
                z = 0
                if x > 0:
                    z += qTem[y][x - 1]
                if x + 1 < QWX:
                    z += qTem[y][x + 1]
                if y > 0:
                    z += qTem[y - 1][x]
                if y + 1 < QWY:
                    z += qTem[y + 1][x]
                mem[y][x] = z // 4 + qTem[y][x] // 2

        return mem
Ejemplo n.º 13
0
    def smoothTerrain(qTem):
        QWX = len(qTem[0])
        QWY = len(qTem)

        mem = create2dArray(QWY, QWX, 0)
        for y in xrange(QWY):
            for x in xrange(QWX):
                z = 0
                if x > 0:
                    z += qTem[y][x-1]
                if x + 1 < QWX:
                    z += qTem[y][x+1]
                if y > 0:
                    z += qTem[y-1][x]
                if y + 1 < QWY:
                    z += qTem[y+1][x]
                mem[y][x] = z // 4 + qTem[y][x] // 2

        return mem
Ejemplo n.º 14
0
    def doSmooth(tem):
        h = len(tem)
        w = len(tem[0])
        tem2 = create2dArray(h, w, 0)

        for y in xrange(h):
            for x in xrange(w):
                z = tem[y][x]
                if x > 0:
                    z += tem[y][x - 1]
                if x + 1 < w:
                    z += tem[y][x + 1]
                if y > 0:
                    z += tem[y - 1][x]
                if y + 1 < h:
                    z += tem[y + 1][x]
                z /= 4
                if z > 255:
                    z = 255
                tem2[y][x] = z
        return tem2
Ejemplo n.º 15
0
    def doSmooth(tem):
        h = len(tem)
        w = len(tem[0])
        tem2 = create2dArray(h, w, 0)

        for y in xrange(h):
            for x in xrange(w):
                z = tem[y][x]
                if x > 0:
                    z += tem[y][x-1]
                if x + 1 < w:
                    z += tem[y][x+1]
                if y > 0:
                    z += tem[y-1][x]
                if y + 1 < h:
                    z += tem[y+1][x]
                z /= 4
                if z > 255:
                    z = 255
                tem2[y][x] = z
        return tem2
Ejemplo n.º 16
0
    def ptlScan(self):
        qX = (self.getWidth() + 3) // 4
        qY = (self.getHeight() + 3) // 4
        qTem = create2dArray(qY, qX, 0)

        landValueTotal = 0
        landValueCount = 0

        HWLDX = (self.getWidth() + 1) // 2
        HWLDY = (self.getHeight() + 1) // 2
        tem = create2dArray(HWLDY, HWLDX, 0)
        for x in xrange(HWLDX):
            for y in xrange(HWLDY):
                pLevel = 0
                lvFlag = 0
                zx = 2 * x
                zy = 2 * y

                for mx in xrange(zx, zx + 2):
                    for my in xrange(zy, zy + 2):
                        tile = self.getTile(mx, my)
                        if tile != DIRT:
                            if tile < RUBBLE:  # natural land features
                                qTem[y//2][x//2] += 15
                                continue
                            pLevel += getPollutionValue(tile)
                            if isConstructed(tile):
                                lvFlag += 1

                if pLevel < 0:
                    pLevel = 250

                if pLevel > 255:
                    pLevel = 255

                tem[y][x] = pLevel

                if lvFlag != 0:
                    # land value equation

                    dis = 34 - self.getDisCC(x, y)
                    dis *= 4
                    dis += self.terrainMem[y//2][x//2]
                    dis -= self.pollutionMem[y][x]
                    if self.crimeMem[y][x] > 190:
                        dis -= 20
                    if dis > 250:
                        dis = 250
                    if dis < 1:
                        dis = 1
                    self.landValueMem[y][x] = dis
                    landValueTotal += dis
                    landValueCount += 1
                else:
                    self.landValueMem[y][x] = 0

        if landValueCount != 0:
            self.landValueAverage = landValueTotal // landValueCount
        else:
            self.landValueAverage = 0

        tem = self.doSmooth(tem)
        tem = self.doSmooth(tem)

        pCount = 0
        pTotal = 0
        pMax = 0

        for x in xrange(HWLDX):
            for y in xrange(HWLDY):
                z = tem[y][x]
                self.pollutionMem[y][x] = z

                if z != 0:
                    pCount += 1
                    pTotal += z

                    if z > pMax or (z == pMax and randint(0, 3) == 0):
                        pMax = z
                        self.pollutionMaxLocationX = 2 * x
                        self.pollutionMaxLocationY = 2 * y

        if pCount != 0:
            self.pollutionAverage = pTotal // pCount
        else:
            self.pollutionAverage = 0

        self.terrainMem = self.smoothTerrain(qTem)
Ejemplo n.º 17
0
    def __init__(self, width=None, height=None):
        self.register_event_type("on_map_changed")
        self.register_event_type("on_evaluation_changed")
        self.register_event_type("on_date_changed")
        self.register_event_type("on_demand_changed")
        self.register_event_type("on_funds_changed")
        self.register_event_type("on_census_changed")
        self.register_event_type("on_power_indicator_changed")
        self.register_event_type("on_city_message")
        self.register_event_type("on_options_changed")
        self.register_event_type("on_city_sound")

        if width == None:
            width = self.DEFAULT_WIDTH
        if height == None:
            height = self.DEFAULT_HEIGHT
        ''' mapdata is stored as [column][row] '''
        self.map = create2dArray(height, width)
        self.updatedTiles = list()
        self.powerMap = create2dArray(self.getHeight(), self.getWidth(), False)
        self.noPowerIndicators = create2dArray(width, height, False)

        halfWidth = (width + 1) // 2
        halfHeight = (height + 1) // 2
        self.landValueMem = create2dArray(halfHeight, halfWidth, 0)
        self.pollutionMem = create2dArray(halfHeight, halfWidth, 0)
        self.crimeMem = create2dArray(halfHeight, halfWidth, 0)
        self.popDensity = create2dArray(halfHeight, halfWidth, 0)
        self.trfDensity = create2dArray(halfHeight, halfWidth, 0)

        quarterWidth = (width + 3) // 4
        quarterHeight = (height + 3) // 4
        self.terrainMem = create2dArray(quarterHeight, quarterWidth, 0)

        self.smWidth = (width + 7) // 8
        self.smHeight = (height + 7) // 8
        self.rateOGMem = create2dArray(self.smHeight, self.smWidth, 0)
        self.fireStMap = create2dArray(self.smHeight, self.smWidth, 0)
        self.policeMap = create2dArray(self.smHeight, self.smWidth, 0)
        self.policeMapEffect = create2dArray(self.smHeight, self.smWidth, 0)
        self.fireRate = create2dArray(self.smHeight, self.smWidth, 0)
        self.comRate = create2dArray(self.smHeight, self.smWidth, 0)

        self.centerMassX = halfWidth
        self.centerMassY = halfHeight
        ''' misc engine vars '''
        self.history = History()

        self.budget = CityBudget()
        self.budget.funds = 20000
        self.autoBulldoze = False
        self.autoBudget = False
        self.noDisasters = True

        self.newPower = False

        self.fCycle = 0  # counts simulation steps (mod 1024)
        self.sCycle = 0  # same as cityTime, except mod 1024
        self.aCycle = 0  # animation cycle (mod 960)

        self.cityTime = 0  # 1 week game time per "cityTime"
        self.totalPop = 0
        self.lastCityPop = 0

        self.pollutionMaxLocationX = 0
        self.pollutionMaxLocationY = 0

        self.needHospital = 0  # -1 too many already, 0 just right, 1 not enough
        self.needChurch = 0  # -1 too many already, 0 just right, 1 not enough

        self.crimeAverage = 0
        self.pollutionAverage = 0
        self.landValueAverage = 0
        self.trafficAverage = 0

        self.resValve = 0  # ranges between -2000 and 2000, updated by setValves
        self.comValve = 0  # ranges between -1500 and 1500
        self.indValve = 0  # same as comvalve
        self.resCap = False
        self.comCap = False
        self.indCap = False
        self.crimeRamp = 0
        self.polluteRamp = 0

        self.TAX_TABLE = [
            200, 150, 120, 100, 80, 50, 30, 0, -10, -40, -100, -150, -200,
            -250, -300, -350, -400, -450, -500, -550
        ]

        self.cityTax = 7
        self.roadPercent = 1.0
        self.policePercent = 1.0
        self.firePrecent = 1.0

        self.taxEffect = 7
        self.roadEffect = 32
        self.policeEffect = 1000
        self.fireEffect = 1000

        self.cashFlow = 0

        self.VALVERATE = 2
        self.CENSUSRATE = 4
        self.TAXFREQ = 48

        self.gameLevel = 0

        self.clearCensus()
        self.initTileBehaviours()
Ejemplo n.º 18
0
    def ptlScan(self):
        qX = (self.getWidth() + 3) // 4
        qY = (self.getHeight() + 3) // 4
        qTem = create2dArray(qY, qX, 0)

        landValueTotal = 0
        landValueCount = 0

        HWLDX = (self.getWidth() + 1) // 2
        HWLDY = (self.getHeight() + 1) // 2
        tem = create2dArray(HWLDY, HWLDX, 0)
        for x in xrange(HWLDX):
            for y in xrange(HWLDY):
                pLevel = 0
                lvFlag = 0
                zx = 2 * x
                zy = 2 * y

                for mx in xrange(zx, zx + 2):
                    for my in xrange(zy, zy + 2):
                        tile = self.getTile(mx, my)
                        if tile != DIRT:
                            if tile < RUBBLE:  # natural land features
                                qTem[y // 2][x // 2] += 15
                                continue
                            pLevel += getPollutionValue(tile)
                            if isConstructed(tile):
                                lvFlag += 1

                if pLevel < 0:
                    pLevel = 250

                if pLevel > 255:
                    pLevel = 255

                tem[y][x] = pLevel

                if lvFlag != 0:
                    # land value equation

                    dis = 34 - self.getDisCC(x, y)
                    dis *= 4
                    dis += self.terrainMem[y // 2][x // 2]
                    dis -= self.pollutionMem[y][x]
                    if self.crimeMem[y][x] > 190:
                        dis -= 20
                    if dis > 250:
                        dis = 250
                    if dis < 1:
                        dis = 1
                    self.landValueMem[y][x] = dis
                    landValueTotal += dis
                    landValueCount += 1
                else:
                    self.landValueMem[y][x] = 0

        if landValueCount != 0:
            self.landValueAverage = landValueTotal // landValueCount
        else:
            self.landValueAverage = 0

        tem = self.doSmooth(tem)
        tem = self.doSmooth(tem)

        pCount = 0
        pTotal = 0
        pMax = 0

        for x in xrange(HWLDX):
            for y in xrange(HWLDY):
                z = tem[y][x]
                self.pollutionMem[y][x] = z

                if z != 0:
                    pCount += 1
                    pTotal += z

                    if z > pMax or (z == pMax and randint(0, 3) == 0):
                        pMax = z
                        self.pollutionMaxLocationX = 2 * x
                        self.pollutionMaxLocationY = 2 * y

        if pCount != 0:
            self.pollutionAverage = pTotal // pCount
        else:
            self.pollutionAverage = 0

        self.terrainMem = self.smoothTerrain(qTem)
Ejemplo n.º 19
0
    def expandTo(self, dx, dy):
        if self.tiles is None or len(self.tiles) == 0:
            self.tiles = create2dArray(1, 1, CLEAR)
            self.offsetX = -dx
            self.offsetY = -dy
            return

        for i in xrange(len(self.tiles)):
            orig = self.tiles[i]

            if self.offsetX + dx >= len(orig):
                newLen = self.offsetX + dx + 1
                new = [CLEAR] * newLen
                for i2 in xrange(len(orig)):
                    new[i2] = orig[i2]
                for i2 in xrange(len(orig) + 1, newLen):
                    new[i2] = CLEAR
                self.tiles[i] = new
            elif self.offsetX + dx < 0:
                # TODO (change roads ref) when roads connect together and fixTile() goes
                # left of tool starting X this branch happens
                addl = -(self.offsetX + dx)
                newLen = len(orig) + addl
                new = [CLEAR] * newLen
                for i2 in xrange(len(orig)):
                    new[i2 + addl] = orig[i2]
                for i2 in xrange(addl):
                    new[i2] = CLEAR
                self.tiles[i] = new

        if self.offsetX + dx < 0:
            add1 = -(self.offsetX + dx)
            self.offsetX += add1

        width = len(self.tiles[0])
        if self.offsetY + dy >= len(self.tiles):
            # just increase size, copy array adding clear as post padding

            newLen = self.offsetY + dy + 1
            newTiles = create2dArray(newLen, width, CLEAR)

            for y in xrange(len(self.tiles)):
                for x in xrange(len(self.tiles[0])):
                    newTiles[y][x] = self.tiles[y][x]

            for y in xrange(len(self.tiles) + 1, len(newTiles)):
                for x in xrange(len(newTiles[0])):
                    newTiles[y][x] = CLEAR
            self.tiles = newTiles

        if self.offsetY + dy < 0:
            # when roads connect together and fixTile() goes
            # above of tool starting Y this branch happens
            addl = -(self.offsetY + dy)
            newLen = len(self.tiles) + addl
            newTiles = create2dArray(newLen, width, CLEAR)

            for y in xrange(len(self.tiles)):
                for x in xrange(len(self.tiles[0])):
                    newTiles[y + addl][x] = self.tiles[y][x]

            for y in xrange(addl):
                for x in xrange(len(newTiles[0])):
                    newTiles[y][x] = CLEAR

            self.tiles = newTiles
            self.offsetY += addl
Ejemplo n.º 20
0
    def __init__(self, width=None, height=None):
        self.register_event_type("on_map_changed")
        self.register_event_type("on_evaluation_changed")
        self.register_event_type("on_date_changed")
        self.register_event_type("on_demand_changed")
        self.register_event_type("on_funds_changed")
        self.register_event_type("on_census_changed")
        self.register_event_type("on_power_indicator_changed")
        self.register_event_type("on_city_message")
        self.register_event_type("on_options_changed")
        self.register_event_type("on_city_sound")

        if width == None:
            width = self.DEFAULT_WIDTH
        if height == None:
            height = self.DEFAULT_HEIGHT
        ''' mapdata is stored as [column][row] '''
        self.map = create2dArray(height, width)
        self.updatedTiles = list()
        self.powerMap = create2dArray(self.getHeight(), self.getWidth(), False)
        self.noPowerIndicators = create2dArray(width, height, False)

        halfWidth = (width + 1) // 2
        halfHeight = (height + 1) // 2
        self.landValueMem = create2dArray(halfHeight, halfWidth, 0)
        self.pollutionMem = create2dArray(halfHeight, halfWidth, 0)
        self.crimeMem = create2dArray(halfHeight, halfWidth, 0)
        self.popDensity = create2dArray(halfHeight, halfWidth, 0)
        self.trfDensity = create2dArray(halfHeight, halfWidth, 0)

        quarterWidth = (width + 3) // 4
        quarterHeight = (height + 3) // 4
        self.terrainMem = create2dArray(quarterHeight, quarterWidth, 0)

        self.smWidth = (width + 7) // 8
        self.smHeight = (height + 7) // 8
        self.rateOGMem = create2dArray(self.smHeight, self.smWidth, 0)
        self.fireStMap = create2dArray(self.smHeight, self.smWidth, 0)
        self.policeMap = create2dArray(self.smHeight, self.smWidth, 0)
        self.policeMapEffect = create2dArray(self.smHeight, self.smWidth, 0)
        self.fireRate = create2dArray(self.smHeight, self.smWidth, 0)
        self.comRate = create2dArray(self.smHeight, self.smWidth, 0)

        self.centerMassX = halfWidth
        self.centerMassY = halfHeight

        ''' misc engine vars '''
        self.history = History()

        self.budget = CityBudget()
        self.budget.funds = 20000
        self.autoBulldoze = False
        self.autoBudget = False
        self.noDisasters = True

        self.newPower = False

        self.fCycle = 0  # counts simulation steps (mod 1024)
        self.sCycle = 0  # same as cityTime, except mod 1024
        self.aCycle = 0  # animation cycle (mod 960)

        self.cityTime = 0  # 1 week game time per "cityTime"
        self.totalPop = 0
        self.lastCityPop = 0

        self.pollutionMaxLocationX = 0
        self.pollutionMaxLocationY = 0

        self.needHospital = 0  # -1 too many already, 0 just right, 1 not enough
        self.needChurch = 0  # -1 too many already, 0 just right, 1 not enough

        self.crimeAverage = 0
        self.pollutionAverage = 0
        self.landValueAverage = 0
        self.trafficAverage = 0

        self.resValve = 0  # ranges between -2000 and 2000, updated by setValves
        self.comValve = 0  # ranges between -1500 and 1500
        self.indValve = 0  # same as comvalve
        self.resCap = False
        self.comCap = False
        self.indCap = False
        self.crimeRamp = 0
        self.polluteRamp = 0

        self.TAX_TABLE = [200,150,120,100,80,50,30,0,-10,-40,-100,
                          -150,-200,-250,-300,-350,-400,-450,-500,-550]

        self.cityTax = 7
        self.roadPercent = 1.0
        self.policePercent = 1.0
        self.firePrecent = 1.0

        self.taxEffect = 7
        self.roadEffect = 32
        self.policeEffect = 1000
        self.fireEffect = 1000

        self.cashFlow = 0


        self.VALVERATE = 2
        self.CENSUSRATE = 4
        self.TAXFREQ = 48

        self.gameLevel = 0

        self.clearCensus()
        self.initTileBehaviours()
Ejemplo n.º 21
0
    def expandTo(self, dx, dy):
        if self.tiles is None or len(self.tiles) == 0:
            self.tiles = create2dArray(1, 1, CLEAR)
            self.offsetX = -dx
            self.offsetY = -dy
            return

        for i in xrange(len(self.tiles)):
            orig = self.tiles[i]

            if self.offsetX + dx >= len(orig):
                newLen = self.offsetX + dx + 1
                new = [CLEAR] * newLen
                for i2 in xrange(len(orig)):
                    new[i2] = orig[i2]
                for i2 in xrange(len(orig) + 1, newLen):
                    new[i2] = CLEAR
                self.tiles[i] = new
            elif self.offsetX + dx < 0:
                # TODO (change roads ref) when roads connect together and fixTile() goes
                # left of tool starting X this branch happens
                addl = -(self.offsetX + dx)
                newLen = len(orig) + addl
                new = [CLEAR] * newLen
                for i2 in xrange(len(orig)):
                    new[i2 + addl] = orig[i2]
                for i2 in xrange(addl):
                    new[i2] = CLEAR
                self.tiles[i] = new

        if self.offsetX + dx < 0:
            add1 = -(self.offsetX + dx)
            self.offsetX += add1

        width = len(self.tiles[0])
        if self.offsetY + dy >= len(self.tiles):
            # just increase size, copy array adding clear as post padding

            newLen = self.offsetY + dy + 1
            newTiles = create2dArray(newLen, width, CLEAR)

            for y in xrange(len(self.tiles)):
                for x in xrange(len(self.tiles[0])):
                    newTiles[y][x] = self.tiles[y][x]

            for y in xrange(len(self.tiles) + 1, len(newTiles)):
                for x in xrange(len(newTiles[0])):
                    newTiles[y][x] = CLEAR
            self.tiles = newTiles

        if self.offsetY + dy < 0:
            # when roads connect together and fixTile() goes
            # above of tool starting Y this branch happens
            addl = -(self.offsetY + dy)
            newLen = len(self.tiles) + addl
            newTiles = create2dArray(newLen, width, CLEAR)

            for y in xrange(len(self.tiles)):
                for x in xrange(len(self.tiles[0])):
                    newTiles[y + addl][x] = self.tiles[y][x]

            for y in xrange(addl):
                for x in xrange(len(newTiles[0])):
                    newTiles[y][x] = CLEAR

            self.tiles = newTiles
            self.offsetY += addl