Vinifera-Developers / Vinifera

Vinifera is a C&C: Tiberian Sun engine extension implementing new logics and fixing bugs.
GNU General Public License v3.0
43 stars 10 forks source link

[New Feature] Torpedoes #444

Open Bittah opened 3 years ago

Bittah commented 3 years ago

Description:

Projectiles that can only travel over water and will self-destruct when hitting land.

Possible Implementation:

Same as in RA1 or YR. RA1 uses UnderWater=yes on the projectile to prevent it from traveling onto land, while YR uses Level=yes.

; UnderWater = Does the projectile travel under water?
; Level = Does it stay at the same altitude in flight? (Currently also acts as IsTorpedo)
Rampastring commented 3 years ago

The RA1 implementation for this assigns the value of the UnderWater= key to BulletTypeClass.IsSubSurface. Basically the most important part of the logic is a check in BulletClass::Is_Forced_To_Explode:

    /*
    **  Check to make sure that underwater projectiles (torpedoes) will not
    **  travel in anything but water.
    */
    if (Class->IsSubSurface) {
        int d = ::Distance(Coord_Fraction(coord), XY_Coord(CELL_LEPTON_W/2, CELL_LEPTON_W/2));
        if (cellptr->Land_Type() != LAND_WATER || (d < CELL_LEPTON_W/3 && cellptr->Cell_Techno() != NULL && cellptr->Cell_Techno() != Payback)) {

            /*
            **  Force explosion to be at center of techno object if one is present.
            */
            if (cellptr->Cell_Techno() != NULL) {
                coord = cellptr->Cell_Techno()->Target_Coord();
            }

            /*
            **  However, if the torpedo was blocked by a bridge, then force the
            **  torpedo to explode on top of that bridge cell.
            */
            if (cellptr->Is_Bridge_Here()) {
                coord = Coord_Snap(coord);
            }

            return(true);
        }
    }

There is also an interesting targeting check in VESSEL.CPP line 1081 that the unit does not fire the torpedo if there are any land cells between the submarine and its target (if so, the submarine prefers moving closer to the target before attempting firing again): https://github.com/electronicarts/CnC_Remastered_Collection/blob/master/REDALERT/VESSEL.CPP#L1081

E1Elite commented 3 years ago

In YR, this feature has limitation of working with only tiles that are part of WaterSet in theater INI, which could be expanded to include tiles with water characteristics.