Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Command & Conquer Remastered Collection - Technical Analysis

A comprehensive technical analysis of the Command & Conquer Remastered Collection source code, covering both Tiberian Dawn and Red Alert. This project documents the most complex subsystems, cheat codes, and implementation details of this historic real-time strategy game codebase.

Overview

The Command & Conquer Remastered Collection represents a historic preservation effort to modernize 1990s real-time strategy game code while maintaining compatibility and determinism. This repository provides in-depth technical analysis of the codebase, which includes TiberianDawn.dll, RedAlert.dll, and the Map Editor.

Electronic Arts released the source code under the GPL V3 license, making it possible to study one of the most influential RTS games ever created.

What's Included

This repository contains detailed technical documentation covering:

An analysis of the hardest technical challenges in the C&C codebase:

  • Deterministic Multiplayer Synchronization (โญโญโญโญโญ)

    • Lockstep model with event-based synchronization
    • CommBufferClass for network event management
    • CRC validation for game state verification
    • Multi-protocol support with compression
  • Pathfinding & Unit Movement AI (โญโญโญโญโญ)

    • A* implementation with multiple movement strategies
    • Dynamic path adjustment and obstacle handling
    • Formation and group movement coordination
    • Performance-optimized for 1990s hardware
  • Legacy Graphics System

    • DirectDraw surface management
    • Video memory handling and fallbacks
    • Complex lock/unlock protocols
    • Blitting and transparency operations
  • Inline Assembly Optimization

    • x86 assembly for drawing routines
    • CRC calculation in assembly
    • Coordinate transformations
    • CPUID detection
  • Expert AI System

    • Urgency-based decision making
    • Multiple competing strategies
    • Dynamic state machine
    • Resource and threat assessment
  • Custom Memory Management

    • Object pool systems
    • Specialized allocators
    • Memory tracking and debugging

Comprehensive analysis of the deterministic lockstep networking system:

Event System:

  • EventClass with 30+ event types (MEGAMISSION, PLACE, FRAMESYNC, FRAMEINFO)
  • Variable-length serialization for bandwidth optimization
  • Command synchronization across all machines

Frame Synchronization:

  • Lockstep simulation model
  • FRAMESYNC events with scenario CRC validation
  • FRAMEINFO heartbeat packets with game state CRC
  • Desync detection and prevention

Communication Buffer:

  • CommBufferClass for send/receive queue management
  • ACK/retry protocol for reliable delivery
  • Response time tracking and latency measurement

CRC Validation:

  • Scenario CRC for identical starting conditions
  • Game state CRC computed every frame
  • Detects divergence from non-deterministic code

Protocols:

  • IPX (Novell NetWare) for LAN
  • Modem (serial, dial-up)
  • Null modem (direct cable)
  • Internet TCP/IP (Red Alert)

Bandwidth Optimization:

  • Event compression (40x reduction vs state sync)
  • Frame grouping and delta encoding
  • Latency compensation with MaxAhead buffer

Deep dive into the expert system AI architecture:

Core Architecture:

  • Expert_AI() control loop called every ~10 seconds
  • Urgency-based decision making (5 levels: NONE, LOW, MEDIUM, HIGH, CRITICAL)
  • Check_* methods evaluate strategic needs
  • AI_* methods execute selected strategies

Strategic Analysis:

  • Check_Build_Power() - Power supply assessment
  • Check_Build_Defense() - Base defense evaluation
  • Check_Build_Income() - Economy/harvesting capacity
  • Check_Build_Offense() - Attack force strength
  • Check_Build_Engineer() - Capture opportunities
  • Check_Fire_Sale() - Desperation assessment

Strategy Execution:

  • AI_Build_Power() - Construct power plants
  • AI_Build_Defense() - Build defensive structures
  • AI_Build_Units() - Produce combat units
  • AI_Attack() - Launch coordinated offensives
  • AI_Raise_Money() - Emergency fundraising

Base Management:

  • 5-zone system (NORTH, SOUTH, EAST, WEST, CORE)
  • Zone-based defense placement
  • Building location optimization

Difficulty System:

  • IQ levels (1-5) unlock advanced behaviors
  • Difficulty modifiers (EASY, NORMAL, HARD)
  • Paranoid mode when AI player defeated

Complete analysis of the DirectDraw graphics system:

Core Architecture:

  • GraphicBufferClass abstraction (video/system memory)
  • GraphicViewPortClass (viewport clipping)
  • DirectDraw 2 integration with surface lock/unlock protocol
  • 256-color palettized rendering

Shape System:

  • .SHP file format with Format 80 (LCW) compression
  • Shape caching with LRU eviction
  • CC_Draw_Shape() with transparency and remapping
  • Hardware acceleration detection

Special Effects:

  • Predator effect (stealth shimmer)
  • Fading/ghost effect (translucency)
  • Shroud and fog of war
  • Palette animation for water/lasers

Performance:

  • Dirty rectangle optimization
  • Assembly-optimized blitters
  • Surface loss recovery
  • 640x480 @ 15 FPS on Pentium 75MHz

Detailed examination of the audio architecture:

Core Architecture:

  • AudioClass (sound instance management)
  • SampleTrackerClass (10-channel playback)
  • DirectSound API integration
  • Priority-based mixing

Audio Formats:

  • VOC format (Creative Voice)
  • AUD format (Westwood Audio with IMA ADPCM)
  • 4:1 compression ratio
  • 22050 Hz, 16-bit samples

3D Positional Audio:

  • Coordinate-based volume attenuation
  • Distance calculation from viewport center
  • Pan calculation for left/right positioning
  • Linear falloff (100% center โ†’ 0% edge)

Sound Effects:

  • 100+ sound effects with priority system
  • Voice variation system (.V00, .V01, .V02, .V03)
  • Priority queue (nuclear = 100, click = 10)
  • LRU caching with 50-sound capacity

Music System:

  • MIDI playback via Windows MIDI
  • Music streaming for large files
  • Dynamic music switching (combat intensity)
  • Fade in/out transitions

Comprehensive analysis of the mission scripting architecture:

Mission System:

  • MissionClass state machine (24 mission types)
  • Variable delay system (reduces CPU 70%)
  • Mission handlers (Sleep, Attack, Guard, Hunt, Harvest, etc.)
  • Mission override and restoration

Trigger System:

  • TriggerClass event-action pairs
  • 22 event types (time, destruction, presence, resources)
  • 18 action types (win/lose, production, reinforcements, special abilities)
  • Multi-event combinations (AND, OR, LINKED)
  • Trigger persistence (volatile, semipersistant, persistant)

Team System:

  • TeamClass coordinated group tactics
  • Team composition (5 unit types max)
  • Mission sequences (5 missions: move, attack, guard, etc.)
  • Recruitment and autocreation
  • Aggressive/suicide/roundabout behavior flags

๐Ÿ—๏ธ Building System Analysis

Detailed examination of base construction and management:

Core Architecture:

  • BuildingClass hierarchy (Object โ†’ Mission โ†’ Radio โ†’ Techno โ†’ Building)
  • 30+ structure types (power, production, defense, support, superweapons)
  • Building states (construction, idle, active, full)
  • Animation state machine

Power System:

  • Power production and consumption tracking
  • Dynamic power ratio (256-level gradation)
  • Power state effects (100%, 75%, 50%, <50%)
  • Damaged buildings produce proportional power

Factory System:

  • FactoryClass production manager
  • 54-step production process
  • Cost-per-tick calculation
  • Multiple factory coordination via primary designation
  • Blocked exit retry logic

Construction:

  • Placement validation (terrain, occupancy)
  • Construction/deconstruction animations
  • Grand_Opening special logic
  • Sell-back refund (50% of cost)
  • Engineer capture mechanics

Comprehensive examination of the combat system:

Architecture:

  • Weapon-Warhead-Bullet trinity (separation of concerns)
  • WeaponTypeClass (ROF, damage, range)
  • BulletTypeClass (projectile physics)
  • WarheadTypeClass (armor modifiers)

Projectile Types:

  • Instant hit (bullets, lasers)
  • Ballistic arc (cannon, artillery)
  • Homing missiles (SAM, Dragon)
  • Flame weapons (area effect)
  • Special projectiles (dog attack, invisibles)

Damage System:

  • Armor vs Warhead matrix (5 armor ร— 10 warheads)
  • Distance-based falloff
  • Explosion mechanics with splash radius
  • Wide area damage (nuclear strikes)

Ballistic Physics:

  • Parabolic trajectories
  • Homing guidance (ROT turn rate)
  • Turbo boost vs aircraft
  • Inaccuracy when moving

Complete documentation of the economic gameplay loop:

Resource System:

  • Ore (25 credits/bale) and Gems (100 credits/bale)
  • 4 growth stages per resource type
  • Static fields (no growth, unlike Tiberian Dawn)

Harvesting:

  • Mission_Harvest state machine (9 states)
  • Automated ore extraction (1 bale per 8 frames)
  • Goto_Tiberium pathfinding (32-cell radius)
  • Harvester capacity (400 credits)

Processing:

  • Refinery docking coordination via radio
  • HarvestedCredits buffer system
  • Animated credit counter (tick-up with sound)
  • Storage overflow to immediate credits

Economic AI:

  • Harvester-to-refinery ratio (1:1 target)
  • Refinery construction (16% of buildings)
  • Silo urgency at 90% capacity
  • Emergency response to low funds

Balance:

  • Starting credits by difficulty (7,500-15,000)
  • Income rate (~1,100 credits/min per harvester)
  • Cost-per-tick production (54-step factory)
  • Storage capacity calculation

Complete documentation of the cheat code system used during development:

Universal Cheats:

  • Alt+W - Instant victory
  • Alt+L - Instant defeat
  • Shift+M / Alt+M / Ctrl+M - Add 10,000 credits
  • F4 - Reveal map (Playtest mode)
  • / - Special options dialog (requires Debug_Flag)
  • F - Toggle pathfinding visualization
  • Delete - Remove selected unit
  • Insert - Clone selected unit
  • Alt+Z - Toggle full map view

Command-Line Parameters:

  • Developer-specific CRC-hashed codes
  • Special option flags
  • Debug mode activation

Debug Flags:

  • Debug_Flag - Master cheat enable
  • Debug_Playtest - Limited QA testing mode
  • Debug_Cheat - Comprehensive cheat mode
  • Various Debug_* toggles

๐Ÿ—บ๏ธ Pathfinding Analysis

Deep dive into the pathfinding and unit movement system:

Core Architecture:

  • FootClass (base movement class)
  • DriveClass (vehicle movement)
  • InfantryClass (soldier movement with 5 sub-cell positions)
  • AircraftClass (flight model)

Pathfinding Algorithm:

  • Modified A* with multiple heuristic strategies
  • Cost calculation with terrain, threat, and congestion modifiers
  • Open/closed list implementation
  • Multiple movement types (MOVE_CLOAK, MOVE_DESTROYABLE, MOVE_TEMP, etc.)

Key Features:

  • Real-time pathfinding for dozens of simultaneous units
  • Multiple terrain types (land, water, air)
  • Dynamic obstacle handling
  • Formation movement
  • Network determinism
  • 60 FPS performance on 1990s hardware

Movement Physics:

  • Track-based rotation for vehicles
  • Speed management and acceleration
  • Collision detection and avoidance
  • Sub-cell positioning for infantry
  • Turret vs body facing

Project Structure

command-and-conquer-analysis/
โ”œโ”€โ”€ README.md                    # This file
โ”œโ”€โ”€ LICENSE.md                   # GPL V3 license with EA's additional terms
โ”œโ”€โ”€ CODEBASE_ANALYSIS.md        # Hardest technical challenges
โ”œโ”€โ”€ CHEAT_CODES_ANALYSIS.md     # Comprehensive cheat code documentation
โ”œโ”€โ”€ PATHFINDING_ANALYSIS.md     # Pathfinding and movement AI deep dive
โ”œโ”€โ”€ CnCRemastered.sln           # Main solution file
โ”œโ”€โ”€ CnCTDRAMapEditor.sln        # Map editor solution
โ”œโ”€โ”€ CnCTDRAMapEditor/           # Map editor source code
โ”œโ”€โ”€ REDALERT/                   # Red Alert game engine source
โ”œโ”€โ”€ TIBERIANDAWN/               # Tiberian Dawn game engine source
โ””โ”€โ”€ SCRIPTS/                    # Build and utility scripts

Key Technical Insights

1. Deterministic Multiplayer

The game uses a lockstep model where every player action is serialized into events and executed on the same frame across all machines. This requires:

  • Perfect determinism in all calculations
  • Identical random number generation
  • Frame-perfect synchronization
  • CRC validation to detect desyncs

2. Real-Time Pathfinding

The A* pathfinding implementation evaluates multiple movement strategies simultaneously:

  • MOVE_CLOAK (easiest path, avoid all obstacles)
  • MOVE_DESTROYABLE (destroy obstacles like walls)
  • MOVE_MOVING_BLOCK (push through moving units)

The system picks the strategy with the best cost/benefit ratio.

3. 1990s Performance Constraints

The codebase is heavily optimized for 60 FPS performance on 486 and Pentium processors:

  • Inline x86 assembly for critical operations
  • Custom memory pools
  • Pathfinding delay timers to amortize costs
  • Efficient data structures (fixed arrays vs dynamic allocation)

4. Development Tools

The extensive cheat code system reveals the tools developers used:

  • Instant win/lose for mission testing
  • Free money for balance testing
  • Map reveal for level design
  • Unit spawning for combat scenarios
  • Pathfinding visualization
  • Monochrome debug monitor

Historical Significance

Command & Conquer (1995) pioneered many RTS conventions:

  • Resource gathering and base building
  • Fog of war and exploration
  • Unit production queues
  • Sidebar interface
  • Real-time multiplayer over modem/LAN

This codebase represents the technical foundation that influenced countless games including StarCraft, Age of Empires, and Warcraft series.

Technical Complexity Ratings

Based on the analysis, here are the most complex subsystems:

Subsystem Complexity Key Challenge
Deterministic Multiplayer โญโญโญโญโญ Perfect frame-sync across network
Pathfinding & Movement โญโญโญโญโญ Real-time A* for dozens of units
Legacy Graphics (DirectDraw) โญโญโญโญ Deprecated API, hardware variations
Inline Assembly โญโญโญโญ Platform-specific, hard to maintain
Expert AI System โญโญโญโญ Urgency-based multi-strategy AI
Custom Memory Management โญโญโญโญ Manual pool allocation, leak tracking

Use Cases

This documentation is valuable for:

  • Game Developers: Understanding RTS architecture and real-time pathfinding
  • Retro Gaming Enthusiasts: Learning how classic games worked under the hood
  • Computer Science Students: Studying A* pathfinding, deterministic simulation, and network synchronization
  • Modders: Understanding the codebase to create custom content
  • Software Engineers: Appreciating optimization techniques for constrained hardware

Building the Project

The project includes Visual Studio solution files:

  • CnCRemastered.sln - Main game engines
  • CnCTDRAMapEditor.sln - Map editor

Requirements:

  • Visual Studio (C++ development)
  • Windows SDK
  • DirectX SDK (for legacy DirectDraw support)

Note: This is analysis documentation. For building instructions, refer to EA's official documentation.

License

The Command & Conquer source code was released by Electronic Arts under the GNU General Public License v3.0 with additional terms. See LICENSE.md for complete details.

Scope of GPL License:

  • TiberianDawn.dll
  • RedAlert.dll
  • Command & Conquer Map Editor
  • Corresponding source code

Contributing

Contributions to this technical analysis are welcome! Areas for expansion:

  • Network protocol deep dive
  • AI scripting system
  • Sound and music system
  • Mission scripting and triggers
  • Building and unit balance
  • Graphics rendering pipeline details
  • Save/load system architecture

Acknowledgments

  • Electronic Arts for releasing the source code under GPL v3
  • Petroglyph Games (former Westwood Studios developers) for the remastered collection
  • The C&C Community for preservation efforts and modding contributions

References


This is an unofficial technical analysis project created for educational purposes. Command & Conquer is a trademark of Electronic Arts Inc.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors