I've made something that could well be the first (mostly) working railroad implementation for Spring (at least I don't know of anything else of that nature). This is not a playable mod, but rather a technical demonstration. Most likely not interesting to anyone except other mod devs. How that works: the system is powered by cob and lua mix. The 'train' itself is immobile, ie it cannot move away from the tracks on its own. It moves only when attached to a track, driven by the track's script. It's not MoveCtrl as well (MoveCtrl can probably make my code much simpler, but I'm not sure of that). Track consists of separate sections ('test_track' and 'test_station' units) which are buildings. They connect to each other and 'register' with each other, so that when the train reaches a section's end, it's passed on to the next section in the chain. Red and green spheres between sections indicate a succesful connection. The track is built by the 'Expand' button on the sections - when pressed, it spawns a new section at each free end of the current one and links them. If both ends of a section are linked to something, it becomes unselectable (since it cannot expand any more). 'Train' (a yellow sphere) is spawned at the 'test_station' section (Spawn Train button). Train is controlled by 3 more custom buttons - Forward, Train Stop and Reverse (available on the train unit). So far it works, at least until there's only 1 train per system (2 or more cause strange things to happen, will work on that later). Test_station is set to be the starting unit, and can be cheat-spawned to produce another independent railroad. There is no way yet to connect separate railroads to each other. Models are just placeholders of course :)
Just tested it. It certainly works, great work. Needs to handle curves and change the angle of the Units attached as they go around them, then I think with a bit of cleanup it would be pretty easy to get it all working nicely.
Here's a version which (hopefully) fixes the problems with 2 or more trains on the same system. Curved tracks are very well possible - the track unit just needs to move the train along whatever path, I need to make some examples probably. Model orientation is simple to add as well - when I make that with actual models, that feature will be in (I want to make the basics first, like configurable rail direction and maybe switches).
Update: now the tracks can be rotated, look somewhat different (and I hope better), the train got a model that has a visible front/rear sides and now properly orientates itself according to the track. Warning: building circular track is not yet supported, the ends will not link properly (trains won't be able to pass there). You can build a closed-loop rail track, but it won't function as you'd expect.
When loops work, I'll sit down with this and see if I can make it pretty. Can it deal with height by re-orienting the unit being moved to roughly follow the difference in heights between the two ends?
Also, I'd make more lengths on tracks, by a multiple of at least 2, and make some "long" and "very long" versions for long straights. The current lengths are teeny by Spring standards, and you'd need literally hundreds of Units to cross a medium-sized map. Since each Unit's a CPU load.... well, you get it. I had to do the same trick with the roads in World Builder, to keep CPU costs down where possible.
Of course tracks can be longer. I just made it the way it is for testing. If I'd want to add that to S'44 for example, I'll add much, much longer track sections. Scripts only depend on section length, which is set by 2 constants in test_track.bos and test_station.bos (LINK1_Z and LINK2_Z). Now I think those would be better autodetected from the model, so models of any size could be used without script changes. As for height differences, reorienting the unit can be done - it's not that different from the current forced heading change (only the unit will get 2 angles instead of 1 and will rotate the model along x-axis using the second angle), but as it is now, track will look bad on uneven terrain.
Edit: here's a version with 2 different track sections. As you can see, the differences between them are minimal, so adding sections of any other length is easy.
Added the circular railway feature. Basically, a section now automatically tries to link to free links on other sections that are nearby, so if you build a loop, it now works (sometimes they fail to link, that happens when the track is quite long so small errors in coordinates add up and ends of sections that should be close together actually aren't, but that should happen very rarely). No switches yet, so a loop is just that - it cannot be expanded anymore unless you destroy one of the sections somehow. If the track is remodelled to be somewhat elevated, it can look like a monorail - should be suitable for those robotic cities Argh is making imo (and 1-unit train will not look so strange on a monorail).
If the rails fail to auto-link, you can adjust the distance at which they do so. Look in rail.lua, function CheckPossibleLink, line 114 in the file:
if tmpDistance <= 5 then
5 is the distance. Making it greater than 15 will make strange connections happen.
Section length can really be anything you make it. Constants are set in scripts\trackSize.h, SIZE1 is the small section, SIZE2 is the large one (in 3DO builder units with linear constant of 163840, I prefer it that way). Train speed is in each section .bos files however (#define TRAIN_SPEED ), I'll change that to be a property of the train itself and not be a constant. Reaction to killed section is as follows - the sections that just got a free end because of this will show the 'buffers' (track end stop devices), become selectable again and allow to spawn new sections, just like they weren't connected before. I only tested with self-D kills though, but I don't see why weapon kills shold be any different. Pre-computing is possible, but it's made the way it is to allow for unplanned train stops. Plus train's position will have to be updated every frame anyway, which should be the main CPU eater there.
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum