The planets have aligned…

Holy cow. I happened to check out CivFanatics today and found some exciting info: According to Civilization IV lead programmer Soren Johnson, Civ IV is going to be scriptable with Python!! I am certain that I find this much more exciting than you, my readership, but since this is my blog, I had to gush about it.

In other news, I haven’t done much on my game in the last few days. Here is a snippet of code I put together for creating a matrix with one type of element on the edges and another type inside.

def edgeMatrix(width, height, edge='E', interior='I'):
    """Create a matrix with different elements on the edges"""
    em = []
    for x in range(height):
        em.append([])
        for y in range(width):
            if x in (0, height-1):
                em[x].append(edge)
            elif y in (0, width-1):
                em[x].append(edge)
            else:
                em[x].append(interior)
    return em

Here is an example from the interactive interpreter:

>>>matrix = edgeMatrix(8,8, 'ext', 'int')
>>>for row in matrix: print row

['ext', 'ext', 'ext', 'ext', 'ext', 'ext', 'ext', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'ext', 'ext', 'ext', 'ext', 'ext', 'ext', 'ext']
>>>

That function should help with my grid/map creation routines. Seriously.

cw

One Response to “The planets have aligned…”

  1. the occasional occurrence » Blog Archive » Civ4 Says:

    [...] I haven’t been into modding Civ for years, but a new release coupled with Python scripting support might change my mind. I can’t wait to see how much of the game is exposed to Python scriptability. I know I blogged about it before, but the combo of Python and Civ is just ridiculously perfect. [...]

Leave a Reply