Opened 9 years ago

Closed 9 years ago

#3112 closed enhancement (fixed)

Change maximum map height

Reported by: sanderd17 Owned by: sanderd17
Priority: Should Have Milestone: Alpha 19
Component: Core engine Keywords:
Cc: Patch:

Description (last modified by sanderd17)

Problem:

Currently, it's not possible to make steep and high mountains on 0 A.D. maps. When the map is rather large, the height difference you can make is so small that map designers are even limited in creating a hilly area with a general slope.

Current state:

Currently, heightmaps are encoded as u16 values (so every point on the map has 216=65536 possible height values). 732 u16-values equals one meter in the game. So in total, the precision is 0.001366 meters, and the maximum height is 89.5 meters.

The u16-value to meters relation is defined in http://trac.wildfiregames.com/browser/ps/trunk/source/graphics/Terrain.h#L43 and can easily be adapted

Possible modifications:

Doubling or halving that precision are rather easy operations. Other products would probably come with more severe rounding errors, and have a bigger chance to change passable tiles into impassable, or the other way around.

So there are a few solutions:

factor 1 2 4 8
number of bits to shift 0 1 2 3
u16 values per meter 732 366 183 92
precision 0.001366 0.00273 0.00546 0.01087
maximum height 89.5 179 358 712

Drawbacks:

All map files will have to be modified for this to accomplish. Making the pmp files of A18 imcompatible with the new ones. However, it can be fixed by running a simple script on the map files. See the code below as an example (it would need parameters to be really functional).

Note however, that since the colour -> color change, map files of A18 and the future versions aren't compatible anymore anyway. But that change was just a simple search-and-replace. However, that chance could be included in this script too

#! /usr/bin/python3

import io
import os
import re

# example file, the actual script should loop over multiple files,
# or take the files from CLI parameters
fileName = "Death Canyon - Invasion Force"

with open(fileName + ".pmp", "rb") as f1, open(fileName + ".pmp~", "wb") as f2:
	# 4 bytes PSMP to start the file 
	f2.write(f1.read(4))

	# 4 bytes to encode the version of the file format
	# TODO: bump version number
	version = int.from_bytes(f1.read(4), byteorder='little')
	f2.write((version).to_bytes(4, byteorder='little'))

	# 4 bytes a for file size (which shouldn't change) 
	f2.write(f1.read(4))

	# 4 bytes to encode the map size
	mapSize = int.from_bytes(f1.read(4), byteorder='little')
	f2.write(mapSize.to_bytes(4, byteorder='little'))

	# reduce all heights using the shift '>>' operator
	for i in range(0, (mapSize*16+1)*(mapSize*16+1)):
		height = int.from_bytes(f1.read(2), byteorder='little')
		f2.write((height >> 3).to_bytes(2, byteorder='little'))
	
	# copy the rest of the file
	byte = f1.read(1)
	while byte != b"":
		f2.write(byte)
		byte = f1.read(1)

	f2.close()
	f1.close()

# replace the old file, comment to see both files
os.remove(fileName + ".pmp") # Windows doesn't allow renames on existing files
os.rename(fileName + ".pmp~", fileName + ".pmp")

The other drawback is that the precision lessens, so some tiles might go from being passable to impassable, or the other way around, due to rounding. However, the difference will only be a few mm. So the map had to be made with huge precision before this would happen.

Random map support:

Most random maps should work if their scale is synchronised with the engine. Specifically http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/maps/random/rmgen/library.js#L11

However, some maps don't work, these should be fixed:

  • Belgian Uplands -> Unplayable due to steep terrain
  • Schwarzwald -> Unplayable due to steep terrain
  • Islands -> Fixed in r16456
  • Neareastern Badlands -> No problems on further investigation

Change History (4)

comment:1 by sanderd17, 9 years ago

Description: modified (diff)

comment:2 by sanderd17, 9 years ago

Description: modified (diff)

comment:3 by sanderd17, 9 years ago

Description: modified (diff)

comment:4 by sanderd17, 9 years ago

Owner: set to sanderd17
Resolution: fixed
Status: newclosed

In 16478:

Allow heightmaps to be 8 times as high by lessening precisions. Includes conversion script and modified standard maps. Bump the map version number. Fixes #3112

Note: See TracTickets for help on using tickets.