Posted February 24, 2025 by Dziban
#uxn #programming
This is gonna be a short post exploring ideas I have about how to generate unit behavior on the fly. The main objective with Kikai is to give you a whole development environment to achieve whatever crazy ideas you want to implement. As with Zachtronics games (and also Dwarf Fortress and Factorio) I want to give the player a simplified but relatively realistic environment and the rest is up to you. You could consider it a networked microcontroller programming sandbox with some Age of Empires elements.
One of the crazy ideas I could think about is a way to create units on the fly by programming the buildings. This idea turns Buildings (what in traditional RTS games produces units) into something akin to compilers and linkers in computer parlance. This also has a very nice parallel with the idea of Unit Production Time
, as that is the time that the building code takes to assemble the code for your unit.
The base building code would be very simple, it would take bytes from a source rom and write them into the unit rom using a building-specific (maybe? maybe it could be used in units as well?) “Factory” device. This would be just a simple basic memcpy
. However things start getting interesting when you consider the implications of buildings being just another Uxn machine. What if instead of just memcpy
it could act more like a compiler or a linker. It could take several different behaviors and stitch them up based on user input (I want to talk about custom interfaces next, but the idea is that a unit can expose several knobs and switches to the player to modify behavior at runtime).
In this way you could generate units specific to the match you are playing based on some predefined code you join together. Or even generate dynamic code on the fly. The possibilities are endless!
The second idea I wanted to explore today is being able to rewrite unit code over Radio updates. Since the Uxn machine allows to change any byte of ram (allowing self-modifying code) you could add a radio message handler that sends code rewrites over the air. I am imagining a building that works as kind of a command center (exposing a custom interface), and one of the possible functions of that command center is to send code updates to small swarm-like units. These units may have very very weak CPUs since you want them very cheap (since they are a Swarm). So you may want to be able to rewrite their behavior instead of containing all possible behaviors from the start. A small radio handler with a memcpy would provide a lot of flexibility allowing for complete code changes on any unit.
Radio by default is unencrypted, the other side can read your messages and it’s up to you to build a way to hide that information so all your units can decode your messages!
That’s it for today!