A (kind of) railroad in Spring

A (kind of) railroad in Spring

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

A (kind of) railroad in Spring

Post by yuritch »

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 :)
Attachments
RailTestStandalone.zip
RailTest mod
(14.18 KiB) Downloaded 51 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: A (kind of) railroad in Spring

Post by Argh »

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.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: A (kind of) railroad in Spring

Post by yuritch »

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).
Attachments
RailTestStandalone.zip
Rail test mk.2
(14.81 KiB) Downloaded 28 times
User avatar
Pendrokar
Posts: 658
Joined: 30 May 2007, 10:45

Re: A (kind of) railroad in Spring

Post by Pendrokar »

Great. Now we can have a WW1 RTS game on spring. :lol:
BaNa
Posts: 1562
Joined: 09 Sep 2007, 21:05

Re: A (kind of) railroad in Spring

Post by BaNa »

Pendrokar wrote:Great. Now we can have a WW1 RTS game on spring. :lol:
Couldnt we have a crazy rail-based rts instead? would be way cooler.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: A (kind of) railroad in Spring

Post by Pressure Line »

TRANSPORT TYCOON SPRING KTHX.
BaNa
Posts: 1562
Joined: 09 Sep 2007, 21:05

Re: A (kind of) railroad in Spring

Post by BaNa »

Pressure Line wrote:TRANSPORT TYCOON SPRING KTHX.
ONLY WITH GUNS FOR WIN !!111one1one
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: A (kind of) railroad in Spring

Post by CarRepairer »

Monorail cat mod.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: A (kind of) railroad in Spring

Post by imbaczek »

CarRepairer wrote:Monorail cat mod.
+9001
Ashnal
Posts: 104
Joined: 24 Jun 2008, 00:57

Re: A (kind of) railroad in Spring

Post by Ashnal »

A mod where you build tracks to expand, and your units are trains loaded with different kinds of guns and explosives. ^_^
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: A (kind of) railroad in Spring

Post by yuritch »

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.
Attachments
RailTestStandalone02.zip
Rail Test v2
(17.42 KiB) Downloaded 19 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: A (kind of) railroad in Spring

Post by Argh »

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.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: A (kind of) railroad in Spring

Post by yuritch »

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.
Attachments
RailTestStandalone.zip
v0.21
(21.07 KiB) Downloaded 26 times
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2700
Joined: 25 Aug 2004, 13:31

Re: A (kind of) railroad in Spring

Post by bobthedinosaur »

pix... nao
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: A (kind of) railroad in Spring

Post by yuritch »

Here's a train on the track. As I already said, it's not pretty yet, since the basic functionality is not yet finished.
train.jpg
A train on the track
(44.45 KiB) Downloaded 131 times
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: A (kind of) railroad in Spring

Post by yuritch »

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).
Attachments
RailTestStandalone.zip
RailTest, fixed some bugs
(22.89 KiB) Downloaded 27 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: A (kind of) railroad in Spring

Post by Argh »

Excellent, lemme take a look, I'd really like a monorail.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: A (kind of) railroad in Spring

Post by Argh »

Ok, that's super cool! Cool enough that I think that it'd be worth making some content for, and re-arranging the heightmap on my new map, frankly.

Minor quibbles / questions

1. The rotation needs to be over several frames, when it hits a corner. Tricky, but for a polished look...

2. Does it react correctly, if the sections get killed?

3. Can I have a section that's even longer than the current ones, like twice that length? If it will help performance, it doesn't need to rotate.

4. CPU use is a little high. Can't it pre-compute the number of frames before a given train will hit a location? For a single monorail, that would be just fine.

At any rate, I'll see about making some content, but I'm not sure when yet, I have a lot on my plate right now.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: A (kind of) railroad in Spring

Post by yuritch »

A screen of a circular track:
Image
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:

Code: Select all

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 [5]), 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.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: A (kind of) railroad in Spring

Post by Pressure Line »

Argh wrote:Excellent, lemme take a look, I'd really like a monorail.
you could also use it for your cars :)
Post Reply

Return to “Game Development”