Data-Driven Game Unit Configuration: Designing an Artillery Attribute System
Learn how to structure game unit configurations around shared schemas and variant overrides, validate data before runtime, and connect special rules to a reusable combat resolution engine. Artillery units illustrate the approach, including configuration versioning, staged rollout, and rollback.
1. Background and Problem Definition
In strategy and tactical games, a single unit archetype often supports several variants. Artillery units built on the same chassis, for example, might include a standard-range suppression variant and a short-range heavy-firepower variant. They share movement, armor, and crew attributes but differ substantially in range, weapon strength, and hit resolution.
Hardcoding separate logic for each variant quickly creates several problems:
- Duplicated logic: Around 90% of attribute access and resolution code is identical, with only a few values and rule branches changing.
- Scattered configuration: Values are distributed across code constants, design documents, and art assets. Updating one location can leave others out of sync.
- Missing validation: Invalid settings, such as negative ranges or damage values that overflow, surface only at runtime and are costly to diagnose.
- Difficult expansion: Adding a variant requires code changes and a new release, slowing iteration.
Data-driven design addresses these problems by moving unit differences into configuration data consumed by a shared parsing, validation, and resolution engine. The following sections break down the design.
2. Modeling Unit Attributes: Shared Schemas and Variant Overrides
Unit attributes should be organized into two layers.
The base schema defines the shared structure of a unit class:
{"unit_class": "artillery","move_range": 6,"armor_profile": { "front": 12, "side": 10, "rear": 10 },"crew_required": 3,"crew_min_alive": 1}
The variant overlay defines differences within that structure. For example, a short-range heavy-firepower variant can override the standard variant’s weapon settings:
{"variant_id": "heavy_mortar_v1","base_ref": "artillery_standard","weapon": {"range_min": 12,"range_max": 36,"strength": 10,"ap": 2,"blast_radius": 5,"special_rules": ["no_direct_fire"]}}
Three principles guide this design:
- Inherit by reference rather than copying. A variant points to its base through
base_refand overrides only the fields that differ. This reduces configuration drift between related units. - Declare constraints explicitly. Restrictions such as
no_direct_fireand minimum crew requirements should be available to the resolution engine, rather than inferred through implicit logic. - Separate values from rules. Numerical values belong in configuration tables; behavior belongs in the rules engine. Rule IDs connect the two so they can evolve independently.
3. Configuration Structure and Validation: Catch Errors Before Runtime
Use a two-layer structure consisting of a base table and a variant table, supported by static validation. Typical checks include:
- Range validation:
range_min <= range_max, with both values at or above the engine’s required lower bound. - Reference integrity:
base_refmust point to an existing base definition, preventing dangling references. - Rule compatibility: If a unit declares
no_direct_fire, itsrange_minshould normally exceed the direct-fire threshold. Otherwise, the configuration may conflict with the intended design and should trigger an error or warning. - Crew consistency:
crew_min_alive <= crew_required, and the minimum crew must be sufficient to support the unit’s minimum operational functions.
The following pseudocode illustrates these checks:
def validate_artillery(cfg, registry):errs = []base = registry.get(cfg.get("base_ref"))if base is None:errs.append(f"unknown base_ref: {cfg['base_ref']}")w = cfg.get("weapon", {})if w.get("range_min", 0) > w.get("range_max", 0):errs.append("range_min must <= range_max")if "no_direct_fire" in w.get("special_rules", []):if w.get("range_min", 0) <= DIRECT_FIRE_THRESHOLD:errs.append("indirect-fire unit needs range_min above threshold")crew = cfg.get("crew_required", 0)if not (0 < cfg.get("crew_min_alive", 0) <= crew):errs.append("invalid crew_min_alive")return errs
Integrate validation into the submission pipeline, such as configuration repository hooks or continuous integration tasks, to reject invalid configurations before they are merged. This is an effective quality control measure for collaborative projects.
4. The Rules Engine and Combat Resolution
Attribute configurations are static data. The resolution process is what turns those values into unit behavior.
A typical artillery attack within a turn follows these steps:
- Validate the target. Check that the target is between
range_minandrange_maxand meets the observation requirements for indirect fire, such as having an observer unit available. - Resolve the hit or scatter. In a scatter-based model, perform the hit check first. If it fails, randomly offset the impact point according to the scatter rules.
- Resolve area effects. Apply effects to all units within the impact radius, typically including friendly-fire checks.
- Resolve vehicle and crew effects. Artillery attacks against vehicles may apply special effects, such as additional penetration or crew suppression. Implement these as pluggable components in the rules engine.
An illustrative resolution snippet is:
def resolve_hit(shooter, target, rng):if "no_direct_fire" in shooter.rules and not shooter.has_observer():return Result.REJECTif not (shooter.range_min <= dist <= shooter.range_max):return Result.OUT_OF_RANGEdamage = weapon_profile(shooter.variant_id)return apply_effect(target, damage, rng)
The central design principle is to register rules as independent components. Adding a special rule requires implementing the rule interface and referencing its ID in configuration, without changing the main resolution flow.
5. Versioning and Staged Rollout
Balance changes are routine during a game’s live operation. The configuration system should support:
- Versioned snapshots: Assign a version to each change. Lock match replays and multiplayer consistency checks to that configuration version so results remain reproducible.
- Staged comparison: Apply new configurations to test rooms first. Use simulated matches to measure key indicators, such as changes in win rate and average resolution time, before rolling out broadly.
- Rollback: Retain the most recent N configuration snapshots so problematic changes can be rolled back within minutes.
6. Conclusion
An artillery variant may appear to be little more than a more powerful gun, but it provides a useful example of a complete data-driven configuration workflow: shared schemas separated from variant differences, static validation before runtime, pluggable rules, and traceable configuration versions.
Implement the approach in this order:
- Identify shared attributes and variant-specific differences.
- Build the configuration tables and validation pipeline.
- Integrate special rules into the resolution engine as independent components.
The approach does not depend on any particular platform and can be applied to strategy, tactical, and simulation games that need to manage large numbers of unit configurations.
