Command and Conquer Remaster source code has been released

For those who didn’t know a remaster of the original Command and Conquer games is out on June 5th and they’ve done some interesting work on putting it all together. There are other people out there who have done this before of course but EA seem to have decided it’s worth giving it official support. What they’ve done though which completely took me by surprise is they’ve posted up the entire source code of both Tiberium Dawn and Red Alert in C#.

For anyone who is at all interested in how RTS games especially the older variety were made be sure to check this out, I’m even thinking about having a look at how they’ve done their AI. This will be invaluable for me like when I found the Age of Empires 2 skirmish computer code, I recommend checking it out.

https://github.com/electronicarts/CnC_Remastered_Collection

Edit: C++ not C#, my bad!

3 Likes

Aaand it is GPL.

It’s C++, not C#

1 Like

Sorry my mistake LOL, I really want to have a look at their AI code so I’m going to dig through it.

Also fairly old-style C++.

void * AircraftClass::operator new(size_t)
{
    void * ptr = Aircraft.Allocate();
    if (ptr) {
        ((AircraftClass *)ptr)->Set_Active();
    }
    return(ptr);
}

Manual VTable, huh. Haven’t seen this for a while.

void AircraftClass::Init(void)
{
    AircraftClass *ptr;

    Aircraft.Free_All();

    ptr = new AircraftClass();
    VTable = ((void **)(((char *)ptr) + sizeof(AbstractClass) - 4))[0];
    delete ptr;
}

However, this is very educational.

/* $Header:   F:\projects\c&c\vcs\code\aircraft.cpv   2.12   19 Jun 1995 09:27:22   JOE_BOSTIC  $ */
/***********************************************************************************************
 ***             C O N F I D E N T I A L  ---  W E S T W O O D   S T U D I O S               ***
 ***********************************************************************************************
 *                                                                                             *
 *                 Project Name : Command & Conquer                                            *
 *                                                                                             *
 *                    File Name : AIRCRAFT.CPP                                                 *
 *                                                                                             *
 *                   Programmer : Joe L. Bostic                                                *
 *                                                                                             *
 *                   Start Date : July 22, 1994                                                *
 *                                                                                             *
 *                  Last Update : August 13, 1995 [JLB]                                        *
 *                                                                                             *
 *---------------------------------------------------------------------------------------------*

26 years old origin. Brings back some memories.

2 Likes

We should be using this code as a case study, I’m finding it fascinating to look through, they even have a lot of comments in there too.

From what I recall from their discussions on the matter, this is basically the code from the game rewritten so it’s functional without the third party middleware like bink video and the like with minimal cleanup.

Which was the reasonable thing to do.

Anyway, this is a good historical artifact of sorts. Stuff from there can’t be borrowed into another game, though, due to GPL. But it could be fun to dive in.

1 Like

Because you don’t watch enough Jonathan Blow streams! :smile:

OH! OH!

I found the AI building section of the code.

Edit: In this section they even have the building placement code which is fantastic, this is going to be very useful for me. Also this explains so much of how they do it, they use zones on the terrain and run checks to see what’s in there. This is fantastic, I can easily see this being transferable to C# using modern colliders and so on.

1 Like

8k lines in one class. Just from that I wouldn’t use their code for inspiration :stuck_out_tongue:

LOL I mean don’t get me wrong, it’s messy, but at the same time it’s fascinating because there are concepts I wouldn’t have thought of like the build zone strength and how they check how many of a certain type of building is being built before moving onto the next in the construction queues.

VTable = ((void **)(((char *)ptr) + sizeof(AbstractClass) - 4))[0];

I think I see why I left C++ behind in one line…

1 Like

Old style Cpp. Pointers are a thing of the past (for most cases)

That’s C-style programming that is no longer necessary to use in C++ these days.
And that’s what it means to have a 24 year old origin codebase.

3 Likes

Besides, great training before you get into Pearl programming! :smile:

We have a class is our game that is 700 lines long that I’m not proud how. It needs rewrite. 8k though :slight_smile:

1 Like

The amount of comments in that source code is through the roof. :hushed: