r/programming
How Cities: Skylines uses a stock-market analogy to drive almost everything in the game
I wanted to find out how Cities: Skylines drives the constant motion you see in a growing city - residents looking for jobs, tourists visiting attractions, garbage trucks doing their rounds, even cims looking for love - and I couldn’t find much written up about it. So I decompiled the game and dug in. What I found is that almost every interaction in the game runs through a single, elegant system: a stock-market-style trading market.
---
I wrote this post a few years back, and recently updated it to add detail to areas I thought lacked sufficient explanation.
I found it really interesting to explore how Colossal Order built such a versatile system, I hope it will be an interesting read to anyone involved in game development.
Please let me know if you have any comments or questions! Thanks for reading.
Raven Software released the Jedi Academy source code in 2013 and the dev comments are crunch rage
So I was thinking about JKA, a game I easily had over 10k hours in back when I was a teen, and stumbled across this piece of history.
It turns out that back in 2013, right when Disney bought Lucasfilm and shut down LucasArts, the devs at Raven Software panicked that their work would get locked in a vault forever. So they hastily dumped the entire source code for Jedi Outcast and Jedi Academy online.
Because it was a sudden dump, they didn't sanitize any of the internal dev comments. The whole thing is a time capsule of stressed-out programmers losing their minds trying to make lightsaber physics work in the Quake 3 engine.
If you look at the main combat file (bg_saber.c), the entire lightsaber melee system is essentially one massive 5000-line switch spaghetti statement.
I scoured the codebase and found some GOATed comments:
1. sv_savegame.cpp - A dev had to write a fake loading loop just to keep a "Saving" popup on the screen long enough for the player to read it.
// I'm going to jump in front of a fucking bus if I ever have to do something so hacky in the future.
int startOfFunction = Sys_Milliseconds();
// ...a few dozen lines later...
// The first thing that the deferred script is going to do is to close the "Saving"
// popup, but we need it to be up for at least a second, so sit here in a fucking
// busy-loop. See note at start of function, re: bus.
2. AI_Jedi.cpp - Trying to program bots to use force powers and navigate 3D maps on a 2003 CPU was clearly a bad time.
{ //fuck, jump instead
{ //fuck it, just force it
3. Dismemberment (G2_bones.cpp) - JKA used a custom skeletal animation system to handle cutting off limbs. Overriding joint angles manually led to this note.
// why I should need do this Fuck alone knows. But I do.
4. bg_pmove.cpp - Someone spent way too long trying to get character models to stop sliding on flat surfaces.
{ //on ground and not moving and on level ground, no reason to do stupid fucking gravity with the clipvelocity!!!!
5. NPC_reactions.cpp - The actual code logic for when you stand there holding your crosshair directly on a friendly NPC's face.
//ask them what the fuck they're doing
6. Quake Math (q_math.cpp) - This famous bit hacking trick was inherited directly from John Carmack’s Quake 3 engine. Even the Raven devs reading it years later had no clue how it worked.
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
7. mhead.c - When the engine hits corrupted MP3 or WAV file data headers.
return 0; // fuck knows what this is, but it ain't one of ours...
8. Fatal crash error (win_glimp.cpp) - What happens if the graphics renderer completely fails to load on Windows.
// error box that'll only appear if something's seriously fucked then I'm going to fallback to
9. Win32 rage (ModView tool) - Anyone who has fought the Win32 API will appreciate this function name used to force the UI to update the document title bar.
void FuckingWellSetTheDocumentNameAndDontBloodyIgnoreMeYouCunt(LPCSTR psDocName) {
if (gpLastOpenedModViewDoc) {
// make absolutely fucking sure this bastard does as it's told...
gpLastOpenedModViewDoc->SetTitle(psDocName);
}
}
10. wp_saber.cpp - When another dev breaks the main header file so you have to manually extern your variables.
// Need to extern these. We can't #include qcommon.h because some fuckwit
11. Skeletal mesh constraints (g_client.cpp) - Trying to bend the player's spine based on mouse yaw without breaking the hitbox.
//SIGH... fucks him up BAD
// ...18 lines later...
//SIGH... spine wiggles fuck all this shit
12. Fixing multiplayer collision in a singleplayer game (g_active.cpp) - The fastest way to fix a physics bug where NPCs were killing each other by clipping into one another.
Because the Quake 3 engine was built for multiplayer everything is a 'client', they retrofitted it for a single player campaign, and if NPCs bump into each other fast enough they just die. So instead of spending weeks changing the AI pathing they just removed the collision damage with a simple if statement if the two colliding clients were of the NPC type basically.
{//aw, fuck it, clients no longer take impact damage from other clients, unless you're the player
13. Vehicle state logic (g_vehicles.c) - Handling the logic for when a bike hits a wall.
{//just get the fuck out
14. Splash Damage (g_mover.c) - Calculating splash damage to players standing near a destructible map object.
{//just blow the fuck out of them
15. fuck the leap years 😂
16. Giving up on linear algebra (r_surface.cpp) ModView was the internal tool used to render 3D character models and animations. Dealing with 3D matrix transformations and surface math clearly broke someone's spirit.
>// Fuck this maths shit, it doesn't work// #define real_nclip(x0,y0,x1,y1,x2,y2) ( (y1-y0)*(x2-x1) - (x1-x0)*(y2-y1) )
17. Early 2000s hardware rage (textures.cpp) Hardcode an exception just to stop AMD/ATI graphics cards from crashing the tool.
>if (error && error != GL_STACK_OVERFLOW /* fucking stupid ATI cards report this for no reason sometimes */ )
18. Audio buffer time travel (cl_mp3.org) Because the engine decodes the compressed audio in linear chunks to save RAM, it can't easily rewind the audio buffer. When the game engine's clock stuttered and requested an audio sample from the past, the dev just gave up.
> // what?!?!?! Fucking time travel needed or something?, forget it
It is wild to think that one of the highest skill ceiling multiplayer games ever made runs on this exact code. Shoutout to the OpenJK team for cleaning up this spaghetti and keeping the game alive today.
EDIT: Fixed formatting EDIT: Added some more stuff
314 npm packages just got compromised, 271 @antv, echarts-for-react, size-sensor, timeago.js
atool maintainer account got hacked, and attacker pushed 631 malicious versions across 314 packages in 22 minutes. another day and another attack. it steals everything like AWS keys, GitHub tokens, npm creds, SSH keys, database strings, docker configs, kubernetes tokens. If you have docker socket exposed, it escapes the container with privileged access.
The just-say-no engineer was a ZIRP phenomenon
seangoedecke.comBuilt an interactive system design tool every architecture is clickable and you can simulate failures
Reqflow : pick an architecture (WhatsApp,
Uber, Netflix…), hit play, watch a request flow through it step by step. Click any component for purpose + tradeoffs. Kill the cache and watch the path change.
15 systems, 18 concept guides, a drag-and-drop Builder with AI review, and a timed Interview mode.
Feedback welcome — especially what's missing from the 15.
5 Years and $5M Later: Inventing a New Programming Language for Web Development Was a Mistake
wasp.shNobody Pushed Back: Why Engineers Stay Silent Until It's Too Late
Most architectural disasters aren't a knowledge problem. The engineers knew. Speaking up just wasn't worth it.