More macro typechecking. A terrain code is now a recognized actual type.

This commit is contained in:
Eric S. Raymond 2008-02-12 11:16:54 +00:00
parent ba9102f882
commit ef4a692367
5 changed files with 34 additions and 25 deletions

View file

@ -158,18 +158,18 @@
[/store_unit]
#enddef
#define RECALLMACRO THING
#define RECALLMACRO DESCRIPTION
[unstore_unit]
variable=temp{THING}
variable=temp{DESCRIPTION}
[/unstore_unit]
[recall]
role=temp{THING}
role=temp{DESCRIPTION}
[/recall]
[recall]
description={THING}
description={DESCRIPTION}
[/recall]
[clear_variable]
name=temp{THING}
name=temp{DESCRIPTION}
[/clear_variable]
#enddef

View file

@ -233,12 +233,12 @@
[/terrain_graphics]
#enddef
#define TERRAIN_OVERLAY_PROB LETTER FLAG PROB IMAGESTEM
#define TERRAIN_OVERLAY_PROB TERRAIN_PATTERN FLAG PROB IMAGESTEM
[terrain_graphics]
[tile]
x=0
y=0
type={LETTER}
type={TERRAIN_PATTERN}
[image]
layer=-1000
name={IMAGESTEM}

View file

@ -17,15 +17,16 @@
[/terrain_graphics]
#enddef
# Attaches an image to a single terrain tile, with a given probability.
# example: {TERRAIN_BASE_PROBABILITY g grassland-rocks 20}
# Attaches an image to all terrain types matching
# a specified pattern, with a given probability.
# Example: {TERRAIN_BASE_PROBABILITY Gg grassland-rocks 20}
#define TERRAIN_BASE_PROB_FL LETTER IMAGESTEM PROB FLAG LAYER
#define TERRAIN_BASE_PROB_FL TERRAIN_PATTERN IMAGESTEM PROB FLAG LAYER
[terrain_graphics]
[tile]
x=0
y=0
type="{LETTER}"
type="{TERRAIN_PATTERN}"
[image]
layer={LAYER}
name={IMAGESTEM}
@ -42,21 +43,21 @@
# example: {TERRAIN_BASE g grassland}
# Should be last on the list: when a terrain has been placed, no other one can.
#define TERRAIN_BASE_FL LETTER IMAGESTEM FLAG LAYER
{TERRAIN_BASE_PROB_FL ({LETTER}) {IMAGESTEM} 100 {FLAG} {LAYER}}
#define TERRAIN_BASE_FL TERRAIN_PATTERN IMAGESTEM FLAG LAYER
{TERRAIN_BASE_PROB_FL ({TERRAIN_PATTERN}) {IMAGESTEM} 100 {FLAG} {LAYER}}
#enddef
#define TERRAIN_BASE_PROB LETTER IMAGESTEM PROB
{TERRAIN_BASE_PROB_FL ({LETTER}) {IMAGESTEM} {PROB} base -1000}
#define TERRAIN_BASE_PROB TERRAIN_PATTERN IMAGESTEM PROB
{TERRAIN_BASE_PROB_FL ({TERRAIN_PATTERN}) {IMAGESTEM} {PROB} base -1000}
#enddef
#define TERRAIN_BASE LETTER IMAGESTEM
{TERRAIN_BASE_FL ({LETTER}) {IMAGESTEM} base -1000}
#define TERRAIN_BASE TERRAIN_PATTERN IMAGESTEM
{TERRAIN_BASE_FL ({TERRAIN_PATTERN}) {IMAGESTEM} base -1000}
#enddef
#define TERRAIN_BASE_PROB_OV LETTER IMAGESTEM PROB
{TERRAIN_BASE_PROB_FL ({LETTER}) {IMAGESTEM} {PROB} overlay -80}
#define TERRAIN_BASE_PROB_OV TERRAIN_PATTERN IMAGESTEM PROB
{TERRAIN_BASE_PROB_FL ({TERRAIN_PATTERN}) {IMAGESTEM} {PROB} overlay -80}
#enddef
#define TERRAIN_BASE_OV LETTER IMAGESTEM
{TERRAIN_BASE_FL ({LETTER}) {IMAGESTEM} overlay -80}
#define TERRAIN_BASE_OV TERRAIN_PATTERN IMAGESTEM
{TERRAIN_BASE_FL ({TERRAIN_PATTERN}) {IMAGESTEM} overlay -80}
#enddef
#define TERRAIN_BASE_DEFAULT IMAGESTEM

View file

@ -69,7 +69,7 @@
# This utility macro disables standard transitions on a given terrain type. It
# is used for castles and keeps, as those have custom transitions.
#define DISABLE_TRANSITIONS LETTER
#define DISABLE_TRANSITIONS TERRAIN_PATTERN
[terrain_graphics]
map="
, 1
@ -103,7 +103,7 @@
[/tile]
[tile]
pos=7
type={LETTER}
type={TERRAIN_PATTERN}
[/tile]
[/terrain_graphics]
#enddef

View file

@ -71,6 +71,8 @@ def formaltype(f):
ftype = "span"
elif f in ("RANGE",):
ftype = "range"
elif f in ("LETTER",):
ftype = "terrain_code"
elif f in ("NAME", "VAR", "IMAGESTEM", "ID") or f.endswith("_NAME"):
ftype = "name"
elif f in ("STRING", "TYPE", "TERRAIN", "TEXT"):
@ -105,12 +107,16 @@ def actualtype(a):
atype = None # Can't tell -- it's a macro expansion
elif re.match(image_reference, a):
atype = "image"
elif re.match(r"[A-Z][a-z]+\^[A-Z][a-z]+\Z", a):
atype = "terrain_code"
elif a.endswith(".wav") or a.endswith(".ogg"):
atype = "sound"
elif a.startswith('"') and a.endswith('"'):
atype = "stringliteral"
elif "=" in a:
atype = "filter"
elif re.match(r"[A-Z][a-z][a-z]?\Z", a):
atype = "shortname"
elif a == "":
atype = "empty"
elif not ' ' in a:
@ -135,9 +141,11 @@ def argmatch(formals, actuals):
pass
elif atype in ("numeric", "position") and ftype == "span":
pass
elif atype in ("name", "stringliteral") and ftype == "string":
elif atype in ("shortname", "name", "stringliteral") and ftype == "string":
pass
elif atype in ("name", "string", "stringliteral", "empty") and ftype == "optional_string":
elif atype in ("shortname", "name", "string", "stringliteral", "empty") and ftype == "optional_string":
pass
elif atype in ("shortname",) and ftype == "terrain_code":
pass
elif atype != ftype and ftype is not None and atype is not None:
return False