from siege.util import RegionVector, Vector


def Simulate(game, world, realm, data):
    # Figure out starting area stuff
    conflictRealm = game.conflict.realms[realm.uid]
    startCenter = Vector(realm.startArea.x, realm.startArea.y)
    startRegion = conflictRealm.regions[conflictRealm.getRegionUid(startCenter)]
    startPosition = getRegionPosition(realm, startRegion)
    for region in conflictRealm.regions:
        position = getRegionPosition(realm, region)
        level = min(int(abs(position.x - startPosition.x) + abs(position.y - startPosition.y) * 1.5), 5)
        region.becomeHostile()
        for _ in xrange(level):
            region.updateTimer.reset()
            region.update(conflictRealm, 0)


def getRegionPosition(realm, region):
    return RegionVector(region.uid / realm.size.regionHeight, region.uid % realm.size.regionHeight)
