Live data from Hacker News

MicropolisJS: A JavaScript clone of the original SimCity

graememcc.co.uk

41–50 of 55 posts

Re: MicropolisJS: A JavaScript clone of the original SimCity

#41

Pretty fun! It crashes reliably for me right after I build a police station, however. Console says: micropolis.js?f750f1ad7f255ea64b6a:1 Uncaught TypeError: A.Position is not a constructor at micropolis.js?f750f1ad7f255ea64b6a:1:242246 at De.mapScan (micropolis.js? f750f1ad7f255ea64b6a:1:243311) at Object.Wi [as _simulate] (micropolis.js? f750f1ad7f255ea64b6a:1:272893) at Object.bi._simFrame (micropolis.js? f750f1ad7…

https://github.com/graememcc/micropolisJS/issues/34

https://github.com/graememcc/micropolisJS/issues/34#issuecom...

quickly fixed and a lesson learned!

Re: MicropolisJS: A JavaScript clone of the original SimCity

#42
This is incredibly cool, thanks to Don Hopkins for open-sourcing the original (C, C++ or Java implementations) micropolis codebase [1] !

As a shameless plug, I've been for the last few years re-implementing on and off this exact same project (based on the C++ codebase) in Rust, WebAssembly and Svelte! [2] Quite a bunch of buzzwords I know, but it's specifically made for me to have fun.

The map generation is working (or at least it was properly rendered when I was using React) and about ~50% of the codebase has been ported over to Rust, but there's still a lot of work to be done if anyone wants to help!

The end goal is notably to have tons of slick data visualisations with d3.js.

[1] https://github.com/SimHacker/micropolis [2] https://github.com/pierreyoda/micropolis-rs

Re: MicropolisJS: A JavaScript clone of the original SimCity

#43

It's really fun. Please store state in localstorage if at all possible. I accidentally killed a tab and lost my city :( The other issue I had was dragging with the road tool occasionally glitched and skipped squares. It'd be nice if you could allow users to drag fairly quickly and give them a nice straight road as an outcome.

Original Sim City had the same issue?

Re: MicropolisJS: A JavaScript clone of the original SimCity

#44

It's really fun. Please store state in localstorage if at all possible. I accidentally killed a tab and lost my city :( The other issue I had was dragging with the road tool occasionally glitched and skipped squares. It'd be nice if you could allow users to drag fairly quickly and give them a nice straight road as an outcome.

I'm not the creator of this (https://github.com/graememcc is), but using the "Save" button persists it across tabs for me (click the "Load Game" button on the homepage to load the state).

It seems to store game state in LocalStorage as JSON under the `micropolisJSGame` key.

Re: MicropolisJS: A JavaScript clone of the original SimCity

#48
post #20

This is so much fun. I love the simplicity of the original feel of the game. No need for fancy graphics, etc. for it to be enjoyable. And I'm amazed at 0 browser issues or weirdness. Takes me right back to my Tandy 1000. My only wish it had the help stuff to remember how to resolve some of the problems in the city. I can't remember if that was in the game or in the book back in the day. I have housing and unemploymen…

Here is the html documentation from the Micropolis source code, which I typed in from the original SimCity manual (originally into FrameMaker, but then I converted it to HTML), that was released by EA under GPL:

https://github.com/SimHacker/micropolis/tree/master/Micropol...

Introduction:

https://github.com/SimHacker/micropolis/blob/master/Micropol...

Tutorial:

https://github.com/SimHacker/micropolis/blob/master/Micropol...

Reference:

https://github.com/SimHacker/micropolis/blob/master/Micropol...

Inside the Simulator:

https://github.com/SimHacker/micropolis/blob/master/Micropol...

History Of Cities And City Planning by Cliff Ellis:

https://github.com/SimHacker/micropolis/blob/master/Micropol...

Bibliography:

https://github.com/SimHacker/micropolis/blob/master/Micropol...

Here is a pdf file of a scan of the HyperLook SimCity manual I made with the NeWS version of FrameMaker:

https://donhopkins.com/home/HyperLook-SimCity-Manual.pdf

And here's an illustrated transcript and video of the Hacking at Random talk I gave about Micropolis:

https://donhopkins.medium.com/har-2009-lightning-talk-transc...

Re: MicropolisJS: A JavaScript clone of the original SimCity

#49

It's really fun. Please store state in localstorage if at all possible. I accidentally killed a tab and lost my city :( The other issue I had was dragging with the road tool occasionally glitched and skipped squares. It'd be nice if you could allow users to drag fairly quickly and give them a nice straight road as an outcome.

I fixed that in the NeWS and X11 versions of SimCity, but probably that code didn't get ported to the JavaScript version, since it was in the user interface layer, which works a bit differently in MicropolisJS (and on every platform) of course.

The MicropolisEngine::toolDrag method does what you want, I think: it drags a tool from one tile to another, drawing all the tiles in-between without gaps.

It would be wonderful if somebody would port the "toolDrag" code to the JavaScript version. It's pretty brute force but straightforward. The mouse tracking code that calls it needs to pass in the previous mouse coordinates (in tile coordinates, independent of scrolling), of course.

(I'm sorry, but I haven't had time to work on Micropolis in a long time, but I'm delighted for other people to work on it and I love Graham's excellent work, and I'm happy to answer any questions.)

https://github.com/SimHacker/micropolis/blob/master/Micropol...

    /**
     * Drag a tool from (\a fromX, \a fromY) to (\a toX, \a toY).
     * @param tool Tool being dragged.
     * @param fromX Horizontal coordinate of the starting position.
     * @param fromY Vertical coordinate of the starting position.
     * @param toX Horizontal coordinate of the ending position.
     * @param toY Vertical coordinate of the ending position.
     */
    void Micropolis::toolDrag(EditingTool tool,
                                short fromX, short fromY, short toX, short toY)
    ...
        // Do not drag big tools.
    ...
        doTool(tool, fromX, fromY); // Ensure the start position is done.
    ...
        // Vertical line up or down
    ...
        // Horizontal line left/right
    ...
        // General case: both X and Y change.
    ...
Here's the Python code for the MicropolisTool class that calls it (via SWIG), in the PyGTK user interface:

https://github.com/SimHacker/micropolis/blob/master/Micropol...

And here's the client/server version (OpenLaszlo/Flash client, Python/TurboGears server):

Laszlo appview.drawToolStart/Move/Start:

https://github.com/SimHacker/micropolis/blob/master/laszlo/m...

Python Micropolis Session handleMessage_drawToolStart/Move/Stop:

https://github.com/SimHacker/micropolis/blob/master/Micropol...

Looks like the old TCL/Tk/X11 version even let you hold down the control key to constrain the road/rail to vertical or horizontal lines -- that's a nice feature I totally forgot about:

https://github.com/SimHacker/micropolis/blob/master/micropol...

https://github.com/SimHacker/micropolis/blob/master/micropol...

Make sure you call toolDrag on the initial and final mouse coordinate on mouse down and up, don't just call toolDrag on mouse move events (or animation ticks), or you might miss the initial source or final destination when the user draws quickly!

For extra credit, make sure the drawing tools work smoothly and reliably with auto-scroll! That makes drawing long roads and railroads easy. ;)

Some of the above user interface code is tricky because it supports multiple views, and each view must maintain its own independent track state. (TCL/Tk/X11 SimCity supported not only multiple views, but also multi-player mode with one X11 client connected to several X11 servers at once (which is rightfully considered a terribly unsafe practice these days), so several people could actually be drawing at once, and you don't want to get their tracking state mixed up! The Python/Flash networked version supported multiple views and users via multiple independent "Sessions" attached to the same simulator, and all the tracking state (like the last tile position to draw from) stayed on the client side.)

Nowadays it's second nature for user interface views to encapsulate all of the mouse tracking state, but the original SimCity code (and the original TCL/Tk UI tracking code) just had lots and lots of global variables! So all the mouse tracking and tool drawing stuff needed to be abstracted and implemented in a higher level platform specific layer, instead of inside MicropolisCore.

Post reply on HN