You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

6972 lines
311 KiB

//
// Copyright 2020 Electronic Arts Inc.
//
// TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
// software: you can redistribute it and/or modify it under the terms of
// the GNU General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
// in the hope that it will be useful, but with permitted additional restrictions
// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
// distributed with this program. You should have received a copy of the
// GNU General Public License along with permitted additional restrictions
// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
/* $Header: /CounterStrike/TECHNO.CPP 5 3/17/97 1:28a Steve_tall $ */
/***********************************************************************************************
*** 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 : BASE.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : May 8, 1994 *
* *
* Last Update : November 1, 1996 [JLB] *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* TechnoClass::AI -- Handles AI processing for techno object. *
* TechnoClass::Anti_Air -- Determines the anti-aircraft strength of the object. *
* TechnoClass::Anti_Armor -- Determines the anti-armor strength of the object. *
* TechnoClass::Anti_Infantry -- Calculates the anti-infantry strength of this object. *
* TechnoClass::Area_Modify -- Determine the area scan modifier for the cell. *
* TechnoClass::Assign_Destination -- Assigns movement destination to the object. *
* TechnoClass::Assign_Target -- Assigns the targeting computer with specified target. *
* TechnoClass::Base_Is_Attacked -- Handle panic response to base being attacked. *
* TechnoClass::Can_Fire -- Determines if this techno object can fire. *
* TechnoClass::Can_Player_Fire -- Determines if the player can give this object a fire order*
* TechnoClass::Can_Player_Move -- Determines if the object can move be moved by player. *
* TechnoClass::Can_Repair -- Determines if the object can and should be repaired. *
* TechnoClass::Can_Teleport_Here -- Checks cell to see if a valid teleport destination. *
* TechnoClass::Captured -- Handles capturing this object. *
* TechnoClass::Clicked_As_Target -- Sets the flash count for this techno object. *
* TechnoClass::Cloaking_AI -- Perform the AI maintenance for a cloaking device. *
* TechnoClass::Combat_Damage -- Fetch the amount of damage infliced by the specified weapon.*
* TechnoClass::Crew_Type -- Fetches the kind of crew this object contains. *
* TechnoClass::Debug_Dump -- Displays the base class data to the monochrome screen. *
* TechnoClass::Desired_Load_Dir -- Fetches loading parameters for this object. *
* TechnoClass::Detach -- Handles removal of target from tracking system. *
* TechnoClass::Do_Cloak -- Start the object into cloaking stage. *
* TechnoClass::Do_Shimmer -- Causes this object to shimmer if it is cloaked. *
* TechnoClass::Do_Uncloak -- Cause the stealth tank to uncloak. *
* TechnoClass::Draw_It -- Draws the health bar (if necessary). *
* TechnoClass::Draw_Pips -- Draws the transport pips and other techno graphics. *
* TechnoClass::Electric_Zap -- Fires electric zap at the target specified. *
* TechnoClass::Enter_Idle_Mode -- Object enters its default idle condition. *
* TechnoClass::Evaluate_Cell -- Determine the value and object of specified cell. *
* TechnoClass::Evaluate_Just_Cell -- Evaluate a cell as a target by itself. *
* TechnoClass::Evaluate_Object -- Determines score value of specified object. *
* TechnoClass::Exit_Object -- Causes specified object to leave this object. *
* TechnoClass::Find_Docking_Bay -- Searches for a close docking bay. *
* TechnoClass::Find_Exit_Cell -- Finds an appropriate exit cell for this object. *
* TechnoClass::Fire_At -- Fires projectile at target specified. *
* TechnoClass::Fire_Coord -- Determine the coordinate where bullets appear. *
* TechnoClass::Fire_Direction -- Fetches the direction projectile fire will take. *
* TechnoClass::Get_Ownable -- Fetches the ownable bits for this object. *
* TechnoClass::Greatest_Threat -- Determines best target given search criteria. *
* TechnoClass::Hidden -- Returns the object back into the hidden state. *
* TechnoClass::How_Many_Survivors -- Determine the number of survivors to escape. *
* TechnoClass::In_Range -- Determines if specified target is within weapon range. *
* TechnoClass::In_Range -- Determines if specified target is within weapon range. *
* TechnoClass::In_Range -- Determines if the specified coordinate is within range. *
* TechnoClass::Is_Allowed_To_Recloak -- Can this object recloak? *
* TechnoClass::Is_Allowed_To_Retaliate -- Checks object to see if it can retaliate. *
* TechnoClass::Is_In_Same_Zone -- Determine if specified cell is in same zone as object. *
* TechnoClass::Is_Players_Army -- Determines if this object is part of the player's army. *
* TechnoClass::Is_Ready_To_Cloak -- Determines if this object is ready to begin cloaking. *
* TechnoClass::Is_Ready_To_Random_Animate -- Determines if the object should random animate.*
* TechnoClass::Is_Visible_On_Radar -- Is this object visible on player's radar screen? *
* TechnoClass::Is_Weapon_Equipped -- Determines if this object has a combat weapon. *
* TechnoClass::Kill_Cargo -- Destroys any cargo attached to this object. *
* TechnoClass::Look -- Performs a look around (map reveal) action. *
* TechnoClass::Mark -- Handles marking of techno objects. *
* TechnoClass::Nearby_Location -- Radiates outward looking for clear cell nearby. *
* TechnoClass::Owner -- Who is the owner of this object? *
* TechnoClass::Per_Cell_Process -- Handles once-per-cell operations for techno type objects.*
* TechnoClass::Pip_Count -- Fetches the number of pips to display on this object. *
* TechnoClass::Player_Assign_Mission -- Assigns a mission as result of player input. *
* TechnoClass::Rearm_Delay -- Calculates the delay before firing can occur. *
* TechnoClass::Receive_Message -- Handles inbound message as appropriate. *
* TechnoClass::Record_The_Kill -- Records the death of this object. *
* TechnoClass::Refund_Amount -- Returns with the money to refund if this object is sold. *
* TechnoClass::Remap_Table -- Fetches the appropriate remap table to use. *
* TechnoClass::Renovate -- Heal a building to maximum *
* TechnoClass::Response_Attack -- Handles the voice response when given attack order. *
* TechnoClass::Response_Move -- Handles the voice response to a movement request. *
* TechnoClass::Response_Select -- Handles the voice response when selected. *
* TechnoClass::Revealed -- Handles revealing an object to the house specified. *
* TechnoClass::Risk -- Fetches the risk associated with this object. *
* TechnoClass::Select -- Selects object and checks to see if can be selected. *
* TechnoClass::Set_Mission -- Forced mission set (used by editor). *
* TechnoClass::Stun -- Prepares the object for removal from the game. *
* TechnoClass::Take_Damage -- Records damage assessed to this object. *
* TechnoClass::Target_Something_Nearby -- Handles finding and assigning a nearby target. *
* TechnoClass::TechnoClass -- Constructor for techno type objects. *
* TechnoClass::Techno_Draw_Object -- General purpose draw object routine. *
* TechnoClass::Threat_Range -- Returns the range to scan based on threat control. *
* TechnoClass::Tiberium_Load -- Fetches the current tiberium load percentage. *
* TechnoClass::Time_To_Build -- Determines the time it would take to build this. *
* TechnoClass::Unlimbo -- Performs unlimbo process for all techno type objects. *
* TechnoClass::Value -- Fetches the target value for this object. *
* TechnoClass::Visual_Character -- Determine the visual character of the object. *
* TechnoClass::Weapon_Range -- Determines the maximum range for the weapon. *
* TechnoClass::What_Action -- Determines action to perform if cell is clicked on. *
* TechnoClass::What_Action -- Determines what action to perform if object is selected. *
* TechnoClass::What_Weapon_Should_I_Use -- Determines what is the best weapon to use. *
* TechnoTypeClass::Cost_Of -- Fetches the cost of this object type. *
* TechnoTypeClass::Get_Cameo_Data -- Fetches the cameo image for this object type. *
* TechnoTypeClass::Get_Ownable -- Fetches the ownable bits for this object type. *
* TechnoTypeClass::Is_Two_Shooter -- Determines if this object is a double shooter. *
* TechnoTypeClass::Raw_Cost -- Fetches the raw (base) cost of the object. *
* TechnoTypeClass::Read_INI -- Reads the techno type data from the INI database. *
* TechnoTypeClass::Repair_Cost -- Fetches the cost to repair one step. *
* TechnoTypeClass::Repair_Step -- Fetches the health to repair one step. *
* TechnoTypeClass::TechnoTypeClass -- Constructor for techno type objects. *
* TechnoTypeClass::Time_To_Build -- Fetches the time to build this object. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
/***************************************************************************
** Cloaking control values.
*/
#define MAX_UNCLOAK_STAGE 38
//Added for getting the input for special character keys from the client
// - 6/26/2019 JAS
extern bool DLL_Export_Get_Input_Key_State(KeyNumType key);
/***************************************************************************
** These are the pointers to the special shape data that the units may need.
*/
void const * TechnoTypeClass::WakeShapes = 0;
void const * TechnoTypeClass::TurretShapes = 0;
void const * TechnoTypeClass::SamShapes = 0;
void const * TechnoTypeClass::MGunShapes = 0;
//Xlat Tables for French and German
// For name overriding
//#define NEWNAMES 22
#ifdef GERMAN
const char* NewName[] = {
"Scout Ant", "Kundschafter-Ameise",
"Warrior Ant", "Krieger-Ameise",
"Fire Ant", "Feuer-Ameise",
"Queen Ant", "Ameisenk�nigin",
"ATS", "Angriffs-U-Boot",
"Tesla Tank", "Telsapanzer",
"Volkov", "Modell Volkov",
"Chitzkoi", "Roboterhund",
"Stavros", "Stavros",
"F-A Longbow", "Jagdhubschrauber Longbow",
"Civilian Specialist", "Wissenschaftler",
"Alloy Facility", "Legierungswerk",
NULL,
};
#endif
#ifdef FRENCH
const char* NewName[] = {
"Scout Ant", "Fourmi de Reconnaissance",
"Warrior Ant", "Fourmi Guerri�re",
"Fire Ant", "Fourmi Lance-Flammes",
"Queen Ant", "Reine des Fourmis",
"ATS", "SMTA",
"Tesla Tank", "Tank Tesla",
"Volkov", "Volkov",
"Chitzkoi", "Cyber-Chien",
"Stavros", "Stavros",
"F-A Longbow", "HAA (H�licopt�re d'Assaut Avanc�)",
"Civilian Specialist", "Sp�cialiste Civil",
"Alloy Facility", "Usine M�tallurgique",
NULL,
};
#endif
/***************************************************************************
** Which shape to use depending on which facing is controlled by these arrays.
*/
int const TechnoClass::BodyShape[32] = {0,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
/***********************************************************************************************
* TechnoClass::Is_Players_Army -- Determines if this object is part of the player's army. *
* *
* The player's army is considered to be all those mobile units that can be selected *
* and controlled by the player (they may or may not have weapons in the traditional *
* sense). *
* *
* INPUT: none *
* *
* OUTPUT: bool; Is this object part of the player's selectable controllable army? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/23/1996 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::Is_Players_Army(void) const
{
/*
** An object that is dead (or about to be) is not considered part of
** the player's army.
*/
if (Strength <= 0) {
return(false);
}
/*
** If the object is not yet on the map or is otherwise indisposed, then
** don't consider it.
*/
if (IsInLimbo || !IsLocked) {
return(false);
}
/*
** Buildings, although sometimes serving a combat purpose, are not part
** of the player's army.
*/
if (What_Am_I() == RTTI_BUILDING) {
return(false);
}
/*
** If not discoverd by the player, then don't consider it part of the
** player's army (yet).
*/
if (!Is_Discovered_By_Player()) {
return(false);
}
/*
** If not selectable, then not really part of the player's active army.
*/
if (!Techno_Type_Class()->IsSelectable) {
return(false);
}
/*
** If not under player control, then it isn't part of the player's army.
*/
if (!House->IsPlayerControl) {
return(false);
}
return(true);
}
/***********************************************************************************************
* TechnoClass::Can_Teleport_Here -- Checks cell to see if a valid teleport destination. *
* *
* Use this routine to examine the cell specified and if the cell could be a valid *
* destination for a teleport, then return true. *
* *
* INPUT: cell -- The cell to examine as a possible legal teleport destination. *
* *
* OUTPUT: bool; Is the specified cell a legal teleport destination? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/08/1996 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::Can_Teleport_Here(CELL cell) const
{
/*
** Infantry are never allowed to teleport.
*/
if (What_Am_I() == RTTI_INFANTRY) {
return(false);
}
/*
** The destination cell must be on the playfield.
*/
if (!Map.In_Radar(cell)) {
return(false);
}
/*
** Teleporting directly onto the flag spot is not allowed. This is due to the
** requirement that entering that location must proceed under normal channels.
*/
if (Map[cell].Overlay == OVERLAY_FLAG_SPOT) {
return(false);
}
/*
** Determine if the object could enter the cell by normal means. If the
** cell is impassable, then it can't be teleported there.
*/
TechnoTypeClass const * ttype = Techno_Type_Class();
if (!Map[cell].Is_Clear_To_Move(ttype->Speed, true, true, -1, ttype->Speed == SPEED_FLOAT ? MZONE_WATER : MZONE_NORMAL)) {
return(false);
}
return(true);
}
/***********************************************************************************************
* TechnoClass::What_Weapon_Should_I_Use -- Determines what is the best weapon to use. *
* *
* This routine will compare the weapons this object is equipped with verses the *
* candidate target object. The best weapon to use against the target will be returned. *
* Special emphasis is given to weapons that can fire on the target without requiring *
* this object to move within range. *
* *
* INPUT: target -- The candidate target to determine which weapon is best against. *
* *
* OUTPUT: Returns with an identifier the specifies what weapon to use against the target. *
* The return value will be "0" for the primary weapon and "1" for the secondary. *
* *
* WARNINGS: This routine is called very frequently. It should be as efficient as possible. *
* *
* HISTORY: *
* 08/12/1996 JLB : Created. *
*=============================================================================================*/
int TechnoClass::What_Weapon_Should_I_Use(TARGET target) const
{
if (!Target_Legal(target)) return(0);
/*
** Fetch the armor of the candidate target object. Presume that if the target
** is not an object, then its armor is equivalent to wood. Who knows why?
*/
ArmorType armor = ARMOR_WOOD;
if (Is_Target_Object(target)) {
armor = As_Object(target)->Class_Of().Armor;
}
TechnoTypeClass const * ttype = Techno_Type_Class();
/*
** Get the value of the primary weapon verses the candidate target. Increase the
** value of the weapon if it happens to be in range.
*/
int w1 = 0;
WeaponTypeClass const * wptr = ttype->PrimaryWeapon;
if (wptr != NULL && wptr->WarheadPtr != NULL) w1 = wptr->WarheadPtr->Modifier[armor] * 1000;
if (In_Range(target, 0)) w1 *= 2;
FireErrorType ok = Can_Fire(target, 0);
if (ok == FIRE_CANT || ok == FIRE_ILLEGAL) w1 = 0;
/*
** Calculate a similar value for the secondary weapon.
*/
int w2 = 0;
wptr = ttype->SecondaryWeapon;
if (wptr != NULL && wptr->WarheadPtr != NULL) w2 = wptr->WarheadPtr->Modifier[armor] * 1000;
if (In_Range(target, 1)) w2 *= 2;
ok = Can_Fire(target, 1);
if (ok == FIRE_CANT || ok == FIRE_ILLEGAL) w2 = 0;
/*
** Return with the weapon identifier that should be used to fire upon the
** candidate target.
*/
if (w2 > w1) return(1);
return(0);
}
/***********************************************************************************************
* TechnoClass::How_Many_Survivors -- Determine the number of survivors to escape. *
* *
* This routine will determine the number of survivors that should run from this object *
* when it is destroyed. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the maximum number of survivors that should run from this object *
* when the object gets destroyed. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 08/04/1996 JLB : Created. *
*=============================================================================================*/
int TechnoClass::How_Many_Survivors(void) const
{
if (Techno_Type_Class()->IsCrew) {
return(1);
}
return(0);
}
/***********************************************************************************************
* TechnoClass::Combat_Damage -- Fetch the amount of damage infliced by the specified weapon. *
* *
* This routine will examine the specified weapon of this object and determine how much *
* damage it could inflict -- best case. *
* *
* INPUT: which -- Which weapon to consider. If -1 is specified, then the average of both *
* weapon types (if present) is returned. *
* *
* OUTPUT: Returns with the combat damage that could be inflicted by the specified weapon. *
* *
* WARNINGS: This routine could return a negative number if a medic is scanned. *
* *
* HISTORY: *
* 09/16/1996 JLB : Created. *
*=============================================================================================*/
int TechnoClass::Combat_Damage(int which) const
{
TechnoTypeClass const * ttype = Techno_Type_Class();
int divisor = 0;
int value = 0;
if (which == 0 || which == -1) {
if (ttype->PrimaryWeapon != NULL) {
value += ttype->PrimaryWeapon->Attack;
divisor += 1;
}
}
if (which == 1 || which == -1) {
if (ttype->SecondaryWeapon != NULL) {
value += ttype->SecondaryWeapon->Attack;
divisor += 1;
}
}
if (divisor > 1) {
return(value / divisor);
}
return(value);
}
/***********************************************************************************************
* TechnoClass::Is_Allowed_To_Recloak -- Can this object recloak? *
* *
* Determine is this object can recloak now and returns that info. Usually the answer is *
* yes, but it can be overridden be derived classes. *
* *
* INPUT: none *
* *
* OUTPUT: bool; Can this object recloak now? (presumes it has the ability to cloak) *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/29/1996 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::Is_Allowed_To_Recloak(void) const
{
return(true);
}
/***********************************************************************************************
* TechnoClass::Fire_Coord -- Determine the coordinate where bullets appear. *
* *
* This routine will determine the coordinate to use when this object fires. The coordinate *
* is the location where bullets appear (or fire effects appear) when the object fires *
* its weapon. *
* *
* INPUT: which -- Which weapon is the coordinate to be calculated for? 0 means primary *
* weapon, 1 means secondary weapon. *
* *
* OUTPUT: Returns with the coordinate that any bullets fired from the specified weapon *
* should appear. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/29/1996 JLB : Created. *
*=============================================================================================*/
FireDataType TechnoClass::Fire_Data(int which) const
{
assert(IsActive);
TechnoTypeClass const * tclass = Techno_Type_Class();
int dist = 0;
if (which == 0) {
dist = tclass->PrimaryOffset;
} else {
dist = tclass->SecondaryOffset;
}
COORDINATE coord = Coord_Move(Center_Coord(), DIR_N, tclass->VerticalOffset + Height);
coord = Coord_Move(coord, DIR_E, tclass->HorizontalOffset);
return{coord,dist};
}
COORDINATE TechnoClass::Fire_Coord(int which) const
{
assert(IsActive);
DirType dir = Turret_Facing();
TechnoTypeClass const * tclass = Techno_Type_Class();
int dist = 0;
int lateral = 0;
if (which == 0) {
dist = tclass->PrimaryOffset;
lateral = tclass->PrimaryLateral;
} else {
dist = tclass->SecondaryOffset;
lateral = tclass->SecondaryLateral;
}
COORDINATE coord = Coord_Move(Center_Coord(), DIR_N, tclass->VerticalOffset + Height);
coord = Coord_Move(coord, DIR_E, tclass->HorizontalOffset);
if (IsSecondShot) {
coord = Coord_Move(coord, (DirType)(dir+DIR_E), lateral);
} else {
coord = Coord_Move(coord, (DirType)(dir+DIR_W), lateral);
}
coord = Coord_Move(coord, dir, dist);
return(coord);
}
#ifdef CHEAT_KEYS
/***********************************************************************************************
* TechnoClass::Debug_Dump -- Displays the base class data to the monochrome screen. *
* *
* This routine is used to dump the status of the object class to the monochrome screen. *
* This display can be used to track down or prevent bugs. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/02/1994 JLB : Created. *
*=============================================================================================*/
void TechnoClass::Debug_Dump(MonoClass * mono) const
{
assert(IsActive);
mono->Set_Cursor(10, 7);mono->Printf("%2d", Fetch_Rate());
mono->Set_Cursor(14, 7);mono->Printf("%2d", Fetch_Stage());
mono->Set_Cursor(49, 1);mono->Printf("%3d", Ammo);
mono->Set_Cursor(71, 1);mono->Printf("$%4d", PurchasePrice);
mono->Set_Cursor(54, 1);mono->Printf("%3d", (long)Arm);
if (Is_Something_Attached()) {
mono->Set_Cursor(1, 5);mono->Printf("%08X", Attached_Object());
}
if (Target_Legal(TarCom)) {
mono->Set_Cursor(29, 3);mono->Printf("%08X", TarCom);
}
if (Target_Legal(SuspendedTarCom)) {
mono->Set_Cursor(38, 3);mono->Printf("%08X", SuspendedTarCom);
}
if (Target_Legal(ArchiveTarget)) {
mono->Set_Cursor(69, 5);mono->Printf("%08X", ArchiveTarget);
}
mono->Set_Cursor(47, 3);mono->Printf("%02X:%02X", PrimaryFacing.Current(), PrimaryFacing.Desired());
mono->Set_Cursor(64, 1);mono->Printf("%d(%d)", Cloak, CloakingDevice);
mono->Fill_Attrib(14, 15, 12, 1, IsUseless ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(14, 16, 12, 1, IsTickedOff ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(14, 17, 12, 1, IsCloakable ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(27, 13, 12, 1, IsLeader ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(27, 14, 12, 1, IsALoaner ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(27, 15, 12, 1, IsLocked ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(27, 16, 12, 1, IsInRecoilState ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(27, 17, 12, 1, IsTethered ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(40, 13, 12, 1, IsOwnedByPlayer ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(40, 14, 12, 1, IsDiscoveredByPlayer ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(40, 15, 12, 1, IsDiscoveredByComputer ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(40, 16, 12, 1, IsALemon ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Set_Cursor(47, 17);mono->Printf("%3d", (long)IronCurtainCountDown);
mono->Fill_Attrib(40, 17, 12, 1, IronCurtainCountDown > 0 ? MonoClass::INVERSE : MonoClass::NORMAL);
RadioClass::Debug_Dump(mono);
}
#endif
/***********************************************************************************************
* TechnoClass::TechnoClass -- Default constructor for techno objects. *
* *
* This default constructor for techno objects is used to reset all internal variables to *
* their default state. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/09/1994 JLB : Created. *
*=============================================================================================*/
TechnoClass::TechnoClass(RTTIType rtti, int id, HousesType house) :
RadioClass(rtti, id),
IsUseless(false),
IsTickedOff(false),
IsCloakable(false),
IsLeader(false),
IsALoaner(false),
IsLocked(false),
IsInRecoilState(false),
IsTethered(false),
IsOwnedByPlayer(false),
IsDiscoveredByPlayer(false),
IsDiscoveredByComputer(false),
IsALemon(false),
IsSecondShot(true),
ArmorBias(1),
FirepowerBias(1),
IdleTimer(0),
IronCurtainCountDown(0),
SpiedBy(0),
ArchiveTarget(TARGET_NONE),
House(HouseClass::As_Pointer(house)),
Cloak(UNCLOAKED),
TarCom(TARGET_NONE),
SuspendedTarCom(TARGET_NONE),
PrimaryFacing(DIR_N),
Arm(0),
Ammo(-1),
ElectricZapDelay(-1),
ElectricZapTarget(0),
ElectricZapWhich(0),
PurchasePrice(0)
{
//IsOwnedByPlayer = (PlayerPtr == House);
// Added for multiplayer changes. ST - 4/24/2019 10:40AM
IsDiscoveredByPlayerMask = 0;
if (Session.Type == GAME_NORMAL) {
IsOwnedByPlayer = (PlayerPtr == House);
} else {
IsOwnedByPlayer = House->IsHuman;
}
}
/***********************************************************************************************
* TechnoClass::Is_Visible_On_Radar -- Is this object visible on player's radar screen? *
* *
* Use this routine to determine if this object should be visible on the player's radar *
* screen. This routine doesn't take into consideration mapped terrain or whether the *
* radar is active. It merely checks to see that if all else is functioning correctly, *
* is this unit invisible or visible on the radar map. Typically, cloaked vehicles will *
* not be visible. *
* *
* INPUT: none *
* *
* OUTPUT: bool; Is this object nominally visible on the player's radar screen? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/27/1996 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::Is_Visible_On_Radar(void) const
{
/*
** Hack: MRJ is invisible to radar, unless it's allied with the player.
*/
if (What_Am_I() == RTTI_UNIT) {
if(*((UnitClass *)this) == UNIT_MRJ) {
if(!House->Is_Ally(PlayerPtr)) {
return(false);
}
}
}
if (!Is_Cloaked(PlayerPtr, true)) {
return(true);
}
return(false);
}
/***********************************************************************************************
* TechnoClass::Revealed -- Handles revealing an object to the house specified. *
* *
* When a unit moves out from under the shroud or when it gets delivered into already *
* explored terrain, then it must be "revealed". Objects that are revealed may be *
* announced to the player. The discovered bit updated accordingly. *
* *
* INPUT: house -- The house that this object is revealed to. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/02/1994 JLB : Created. *
* 12/27/1994 JLB : Discovered trigger event processing. *
*=============================================================================================*/
bool TechnoClass::Revealed(HouseClass * house)
{
assert(IsActive);
/* Replaced by client/server version from TD. ST - 8/7/2019 11:09AM
if (house == PlayerPtr && IsDiscoveredByPlayer) return(false);
if (house != PlayerPtr) {
if (IsDiscoveredByComputer) return(false);
IsDiscoveredByComputer = true;
}
*/
if (house == NULL) {
return false;
}
if (Is_Discovered_By_Player(house)) {
return false;
}
if (house->IsHuman == false) {
if (IsDiscoveredByComputer) {
return false;
}
IsDiscoveredByComputer = true;
}
if (RadioClass::Revealed(house)) {
/*
** An enemy object that is discovered will go into hunt mode if
** its current mission is to ambush.
*/
if (!house->IsHuman && Mission == MISSION_AMBUSH) {
Assign_Mission(MISSION_HUNT);
}
if (Session.Type == GAME_NORMAL) {
if (house == PlayerPtr) {
IsDiscoveredByPlayer = true;
if (!IsOwnedByPlayer) {
/*
** If there is a trigger event associated with this object, then process
** it for discovery purposes.
*/
if (!ScenarioInit && Trigger.Is_Valid()) {
Trigger->Spring(TEVENT_DISCOVERED, this);
}
/*
** Alert the enemy house to presence of the friendly side.
*/
House->IsDiscovered = true;
if (house->IsHuman) {
Set_Discovered_By_Player(house);
} else {
IsDiscoveredByComputer = true;
}
} else {
if (house->IsHuman) {
Set_Discovered_By_Player(house);
} else {
IsDiscoveredByComputer = true;
}
/*
** A newly revealed object will always perform a look operation.
*/
Look();
}
} else {
IsDiscoveredByComputer = true;
}
} else {
if (house->IsHuman) {
Set_Discovered_By_Player(house);
}
Look();
}
return(true);
}
return(false);
}
/***********************************************************************************************
* TechnoClass::Hidden -- Returns the object back into the hidden state. *
* *
* This routine is called for every object that returns to the darkness shroud or when *
* it gets destroyed. This also occurs when an object enters another (such as infantry *
* entering a transport helicopter). *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/02/1994 JLB : Created. *
*=============================================================================================*/
void TechnoClass::Hidden(void)
{
assert(IsActive);
//if (!IsDiscoveredByPlayer) return;
if (!Is_Discovered_By_Player()) { // ST - 8/7/2019 11:17AM
return;
}
if (!House->IsHuman) {
Clear_Discovered_By_Players();
}
}
/***********************************************************************************************
* TechnoClass::Mark -- Handles marking of techno objects. *
* *
* On the Techno-level, marking handles transmission of the redraw command to any object *
* that it is 'connected' with. This only occurs during loading and unloading. *
* *
* INPUT: mark -- The marking method. This routine just passes this on to base classes. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/17/1994 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::Mark(MarkType mark)
{
assert(IsActive);
if (RadioClass::Mark(mark)) {
/*
** When redrawing an object, if there is another object tethered to this one,
** redraw it as well.
*/
if (IsTethered) {
Transmit_Message(RADIO_REDRAW);
}
return(true);
}
return(false);
}
/***********************************************************************************************
* TechnoClass::Receive_Message -- Handles inbound message as appropriate. *
* *
* This routine is used to handle inbound radio messages. It only handles those messages *
* that deal with techno objects. Typically, these include loading and unloading. *
* *
* INPUT: from -- Pointer to the originator of the radio message. *
* *
* message -- The inbound radio message. *
* *
* param -- Reference to optional parameter that might be used to transfer *
* more information than is possible with the simple radio message *
* type. *
* *
* OUTPUT: Returns with the radio response. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/17/1994 JLB : Created. *
* 06/17/1995 JLB : Handles tether contact messages. *
*=============================================================================================*/
RadioMessageType TechnoClass::Receive_Message(RadioClass * from, RadioMessageType message, long & param)
{
assert(IsActive);
switch (message) {
/*
** Just received instructions to attack the specified target.
*/
case RADIO_ATTACK_THIS:
if (Techno_Type_Class()->PrimaryWeapon != NULL) {
Assign_Target(param);
Assign_Mission(MISSION_ATTACK);
return(RADIO_ROGER);
}
break;
/*
** Establish a tethered connection to the object in radio contact.
*/
case RADIO_TETHER:
if (!IsTethered) {
IsTethered = true;
Transmit_Message(RADIO_TETHER, from);
return(RADIO_ROGER);
}
break;
/*
** Break the tethered connection to the object in radio contact.
*/
case RADIO_UNTETHER:
if (IsTethered) {
IsTethered = false;
Transmit_Message(RADIO_UNTETHER, from);
return(RADIO_ROGER);
}
break;
/*
** A tethered unit has reached it's destination. All is
** clear, so radio contact can be broken.
*/
case RADIO_UNLOADED:
Transmit_Message(RADIO_UNTETHER, from);
return(Transmit_Message(RADIO_OVER_OUT, from));
/*
** When this message is received, it means that the other object
** has already turned its radio off. Turn this radio off as well.
*/
case RADIO_OVER_OUT:
Transmit_Message(RADIO_UNTETHER, from);
RadioClass::Receive_Message(from, message, param);
return(RADIO_ROGER);
/*
** Request to be informed when unloaded. This message is transmitted
** by the transport unit to the transported unit as it is about to be
** unloaded. It is saying, "All is clear. Drive off now."
*/
case RADIO_UNLOAD:
case RADIO_BACKUP_NOW:
case RADIO_HOLD_STILL:
Transmit_Message(RADIO_TETHER, from);
RadioClass::Receive_Message(from, message, param);
return(RADIO_ROGER);
/*
** Handle reloading one ammo point for this unit.
*/
case RADIO_RELOAD:
if (Ammo == Techno_Type_Class()->MaxAmmo) return(RADIO_NEGATIVE);
/*BG*/ Mark(MARK_CHANGE_REDRAW);
Ammo++;
return(RADIO_ROGER);
/*
** Handle repair of this unit.
*/
case RADIO_REPAIR:
/*
** If it's a mine layer, re-arm him if he's empty. This always takes precedence
** over repair, since this operation is free.
*/
if (What_Am_I() == RTTI_UNIT && *((UnitClass *)this) == UNIT_MINELAYER && ((UnitClass *)this)->Ammo < ((UnitClass *)this)->Class->MaxAmmo) {
((UnitClass *)this)->Ammo = ((UnitClass *)this)->Class->MaxAmmo;
return(RADIO_NEGATIVE);
}
/*
** Determine if this unit can be repaired becaause it is under strength. If so, then
** proceed with the repair process.
*/
if (Health_Ratio() < Rule.ConditionGreen) {
int cost = Techno_Type_Class()->Repair_Cost();
cost = max(cost, 1);
int step = Techno_Type_Class()->Repair_Step();
step = max(step, 1);
/*
** If there is sufficient money to repair the unit one step, then do so.
** Otherwise return with a "can't complete" radio response.
** Special case: in single-player campaigns, also try to use the repair pad house's money.
*/
HouseClass* house = House;
if (Session.Type == GAME_NORMAL && house->Available_Money() < cost) {
house = HouseClass::As_Pointer(from->Owner());
}
if (house != NULL && house->Available_Money() >= cost) {
house->Spend_Money(cost);
Strength += step;
/*
** Return with either an all ok or mission accomplished radio message. This
** lets the repairing object know if it should abort the repair control process
** or continue it.
*/
if (Health_Ratio() < Rule.ConditionGreen) {
return(RADIO_ROGER);
} else {
Strength = Techno_Type_Class()->MaxStrength;
return(RADIO_ALL_DONE);
}
} else {
return(RADIO_CANT);
}
}
return(RADIO_NEGATIVE);
default:
break;
}
return(RadioClass::Receive_Message(from, message, param));
}
/***********************************************************************************************
* TechnoClass::Per_Cell_Process -- Handles once-per-cell operations for techno type objects. *
* *
* This routine handles marking a game object as not a loaner. It is set only if the unit *
* is not player owned and is on the regular map. This is necessary so that enemy objects *
* can exist off-map but as soon as they move onto the map, are flagged so that can never *
* leave it again. *
* *
* INPUT: why -- Specifies the circumstances under which this routine was called. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/17/1994 JLB : Created. *
* 10/26/94 JLB : Handles scanner units. *
* 12/27/1994 JLB : Checks for an processes any trigger in cell. *
*=============================================================================================*/
void TechnoClass::Per_Cell_Process(PCPType why)
{
assert(IsActive);
if (why == PCP_END) {
CELL cell = Coord_Cell(Center_Coord());
/*
** When enemy units enter the proper map area from off map, they are
** flagged so that they won't travel back off the map again.
*/
if (!IsLocked && Map.In_Radar(cell)) {
IsLocked = true;
}
/*
** If this object somehow moves into mapped terrain, but is not yet
** discovered, then flag it to be discovered.
*/
// Change for client/server multiplayer ST - 8/7/2019 11:19AM
//if (!IsDiscoveredByPlayer && Map[cell].IsVisible) {
//Revealed(PlayerPtr);
if (!Is_Discovered_By_Player() && Map[cell].Is_Visible(House)) {
Revealed(House);
}
}
}
/***********************************************************************************************
* TechnoClass::Draw_It -- Draws the health bar (if necessary). *
* *
* This routine will draw the common elements for techno type objects. This element is *
* the health bar. The main game object has already been rendered by the time this *
* routine is called. *
* *
* INPUT: x,y -- The coordinate of the center of the unit. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/17/1994 JLB : Created. *
* 10/26/94 JLB : Knows about radar scanned cells. *
* 12/13/1994 JLB : Clips health bar against map edge. *
* 01/23/1995 JLB : Dynamic selected object rectangle. *
*=============================================================================================*/
void TechnoClass::Draw_It(int x, int y, WindowNumberType window) const
{
assert(IsActive);
/*
** Tells the door logic that it has been drawn.
*/
((TechnoClass *)this)->Clear_Redraw_Flag();
/*
** Draw electric zap
*/
if ((ElectricZapDelay >= 0) && ElectricZapTarget) {
Electric_Zap(ElectricZapTarget, ElectricZapWhich, window);
}
int width, height;
Class_Of().Dimensions(width, height);
const bool show_health_bar = (Strength > 0) && !Is_Cloaked(PlayerPtr) && (Is_Selected_By_Player() ||
((Rule.HealthBarDisplayMode == RulesClass::HB_DAMAGED) && (Strength < Techno_Type_Class()->MaxStrength)) ||
(Rule.HealthBarDisplayMode == RulesClass::HB_ALWAYS));
/*
** Draw the selected object graphic.
*/
int lx = width / 2;
int ly = height / 2;
int dx = width / 5;
int dy = height / 5;
int fudge = show_health_bar ? 4 : 0;
if (What_Am_I() == RTTI_VESSEL) {
lx = width / 2;
}
//if (IsSelected) {
if (Is_Selected_By_Player() || show_health_bar) {
GraphicViewPortClass draw_window( LogicPage->Get_Graphic_Buffer(),
WindowList[window][WINDOWX] + LogicPage->Get_XPos(),
WindowList[window][WINDOWY] + LogicPage->Get_YPos(),
WindowList[window][WINDOWWIDTH],
WindowList[window][WINDOWHEIGHT]);
/*
** The infantry select box should be a bit higher than normal.
*/
if (What_Am_I() == RTTI_INFANTRY) {
y -= 6;
}
if (What_Am_I() == RTTI_BUILDING && ((BuildingTypeClass const &)Class_Of()).Type == STRUCT_BARRACKS) {
y -= 5;
}
/*
** Fetch the dimensions of the object. These dimensions will be used to draw
** the selection box and the health bar.
*/
if (show_health_bar) {
fixed ratio = Health_Ratio();
int pwidth; // Pixel width of bar interior.
int color; // The color to give the interior of the bargraph.
int xx = x-width/2;
int yy = y-(height/2);
/*
** Draw the outline of the bargraph.
*/
draw_window.Remap(xx+1, yy+1, width-1, 3-1, Map.FadingShade);
draw_window.Draw_Rect(xx, yy, xx+width-1, yy+3, BLACK);
/*
** Determine the width of the interior strength
** graph.
*/
pwidth = (width-2) * ratio;
pwidth = Bound(pwidth, 1, width-2);
color = LTGREEN;
if (ratio <= Rule.ConditionYellow) {
color = YELLOW;
}
if (ratio <= Rule.ConditionRed) {
color = RED;
}
draw_window.Fill_Rect(xx+1, yy+1, xx+pwidth, yy+(3-1), color);
}
/*
** Draw the selected object graphic.
*/
if (Is_Selected_By_Player()) {
// Upper left corner.
draw_window.Draw_Line(x - lx, fudge + y - ly, x - lx + dx, fudge + y - ly, WHITE);
draw_window.Draw_Line(x - lx, fudge + y - ly, x - lx, fudge + y - ly + dy, WHITE);
// Upper right corner.
draw_window.Draw_Line(x + lx, fudge + y - ly, x + lx - dx, fudge + y - ly, WHITE);
draw_window.Draw_Line(x + lx, fudge + y - ly, x + lx, fudge + y - ly + dy, WHITE);
// Lower right corner.
draw_window.Draw_Line(x + lx, y + ly, x + lx - dx, y + ly, WHITE);
draw_window.Draw_Line(x + lx, y + ly, x + lx, y + ly - dy, WHITE);
// Lower left corner.
draw_window.Draw_Line(x - lx, y + ly, x - lx + dx, y + ly, WHITE);
draw_window.Draw_Line(x - lx, y + ly, x - lx, y + ly - dy, WHITE);
}
}
// MBL 04.21.2020
bool selected = Is_Selected_By_Player() || Rule.ResourceBarDisplayMode == RulesClass::RB_ALWAYS;
// if ((window == WINDOW_VIRTUAL) || (Is_Selected_By_Player() && (House->Is_Ally(PlayerPtr) || (Spied_By() & (1 << (PlayerPtr->Class->House))))))
if ((window == WINDOW_VIRTUAL) || (selected && (House->Is_Ally(PlayerPtr) || (Spied_By() & (1 << (PlayerPtr->Class->House))))))
{
Draw_Pips((x-lx)+5, y+ly-3, window);
}
}
/***********************************************************************************************
* TechnoClass::Unlimbo -- Performs unlimbo process for all techno type objects. *
* *
* This routine handles the common operation between techno objects when they are *
* unlimboed. This includes revealing the map. *
* *
* INPUT: coord -- The coordinate to unlimbo object at. *
* *
* dir (optional) -- initial facing direction for this object *
* *
* OUTPUT: bool; Was the unlimbo successful? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 11/14/1994 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::Unlimbo(COORDINATE coord, DirType dir)
{
assert(IsActive);
if (RadioClass::Unlimbo(coord, dir)) {
PrimaryFacing = dir;
Enter_Idle_Mode(true);
Commence();
IsLocked = Map.In_Radar(Coord_Cell(coord));
return(true);
}
return(false);
}
/***********************************************************************************************
* TechnoClass::In_Range -- Determines if specified target is within weapon range. *
* *
* This routine is used to compare the distance to the specified target with the range *
* of the weapon. If the target is outside of weapon range, then false is returned. *
* *
* INPUT: target -- The target to check if it is within weapon range. *
* *
* which -- Which weapon to use in determining range. 0=primary, 1=secondary. *
* *
* OUTPUT: bool; Is the specified target within weapon range? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 11/14/1994 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::In_Range(TARGET target, int which, bool reciprocal_check) const
{
assert(IsActive);
if (IsLocked && Target_Legal(target)) {
int range = Weapon_Range(which);
BuildingClass const * building = As_Building(target);
if (building != NULL) {
range += ((building->Class->Width() + building->Class->Height()) * (ICON_LEPTON_W / 4));
}
FireDataType data = Fire_Data(which);
if (MAX(0, ::Distance(data.Center, As_Coord(target)) - data.Distance) <= range) {
return(true);
}
/*
** There's a longstanding bug where enemy units aligned north/south may have different perceptions of whether they
** are in range of each other due to the turrets offset on the unit. This check will say that if either considers the
** the other to be in range, then they both do. ST - 3/18/2020 10:44AM
*/
if (reciprocal_check && !building) {
ObjectClass *target_object = As_Object(target);
if (target_object) {
RTTIType my_type = What_Am_I();
if (target_object->What_Am_I() == my_type) {
if (range == target_object->Weapon_Range(which)) {
TechnoClass *tech = As_Techno(target);
if (tech->In_Range(As_Target(), which, false)) {
return true;
}
}
}
}
}
}
return(false);
}
/***********************************************************************************************
* TechnoClass::In_Range -- Determines if specified target is within weapon range. *
* *
* This routine will determine if the pointer to the target object passed into this *
* routine is within weapon range. *
* *
* INPUT: target -- Pointer to the target object to check if within weapon range. *
* *
* which -- Which weapon to use in determining range. 0=primary, 1=secondary. *
* *
* OUTPUT: bool; Is the target within weapon range? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 11/14/1994 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::In_Range(ObjectClass const * target, int which, bool reciprocal_check) const
{
assert(IsActive);
if (IsLocked && target) {
int range = Weapon_Range(which);
if (target->What_Am_I() == RTTI_BUILDING) {
BuildingClass const * building = (BuildingClass const *)target;
range += ((building->Class->Width() + building->Class->Height()) * (ICON_LEPTON_W / 4));
}
FireDataType data = Fire_Data(which);
if (MAX(0, ::Distance(data.Center, target->Center_Coord()) - data.Distance) <= range) {
return(true);
}
/*
** There's a longstanding bug where enemy units aligned north/south may have different perceptions of whether they
** are in range of each other due to the turrets offset on the unit. This check will say that if either considers the
** the other to be in range, then they both do. ST - 3/18/2020 10:44AM
*/
if (reciprocal_check) {
RTTIType my_type = What_Am_I();
if (my_type != RTTI_BUILDING) {
if (target->What_Am_I() == my_type) {
if (range == target->Weapon_Range(which)) {
if (((TechnoClass*)target)->In_Range(this, which, false)) {
return true;
}
}
}
}
}
}
return(false);
}
/***********************************************************************************************
* TechnoClass::In_Range -- Determines if the specified coordinate is within range. *
* *
* Use this routine to determine if the specified coordinate is within weapon range. *
* *
* INPUT: coord -- The coordinate to examine against the object to determine range. *
* *
* which -- The weapon to consider when determining range. 0=primary, 1=secondary. *
* *
* OUTPUT: bool; Is the weapon within range? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 03/16/1995 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::In_Range(COORDINATE coord, int which) const
{
assert(IsActive);
return(IsLocked && ::Distance(Fire_Coord(which), coord) <= Weapon_Range(which));
}
/***********************************************************************************************
* TechnoClass::Area_Modify -- Determine the area scan modifier for the cell. *
* *
* This routine scans around the cell specified and if there are any friendly buildings *
* nearby, the multiplier return value will be reduced. If there are no friendly buildings *
* nearby, then the return value will be 1. It checks to see if the primary weapon is *
* supposed to perform this scan and if so, the scan will be performed. Otherwise the *
* default value is quickly returned. *
* *
* INPUT: cell -- The cell where the potential target lies. An area around this cell will *
* be scanned for friendly buildings. *
* *
* OUTPUT: Returns with the multiplier to be multiplied by the potential target score value. *
* For less opportune targets, the multiplier fraction will be less than one. For *
* all other cases, it will return the default value of 1. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 08/23/1996 JLB : Created. *
*=============================================================================================*/
fixed TechnoClass::Area_Modify(CELL cell) const
{
// assert(Techno_Type_Class()->PrimaryWeapon != NULL);
if (Techno_Type_Class()->PrimaryWeapon == NULL || !Techno_Type_Class()->PrimaryWeapon->IsSupressed) return(1);
int crange = Lepton_To_Cell(Rule.SupressRadius);
fixed odds = 1;
for (int radius = 1; radius < crange; radius++) {
/*
** Scan the top and bottom rows of the "box".
*/
for (int x = -radius; x <= radius; x++) {
CELL newcell;
if ((Cell_X(cell) + x) < Map.MapCellX) continue;
if ((Cell_X(cell) + x) >= (Map.MapCellX+Map.MapCellWidth)) continue;
if ((Cell_Y(cell) - radius) >= Map.MapCellY) {
newcell = XY_Cell(Cell_X(cell) + x, Cell_Y(cell)-radius);
BuildingClass const * building = Map[newcell].Cell_Building();
if (building != NULL && House->Is_Ally(building)) {
odds /= 2;
}
}
if ((Cell_Y(cell) + radius) < (Map.MapCellY+Map.MapCellHeight)) {
newcell = XY_Cell(Cell_X(cell)+x, Cell_Y(cell)+radius);
BuildingClass const * building = Map[newcell].Cell_Building();
if (building != NULL && House->Is_Ally(building)) {
odds /= 2;
}
}
}
/*
** Scan the left and right columns of the "box".
*/
for (int y = -(radius-1); y < radius; y++) {
CELL newcell;
if ((Cell_Y(cell) + y) < Map.MapCellY) continue;
if ((Cell_Y(cell) + y) >= (Map.MapCellY+Map.MapCellHeight)) continue;
if ((Cell_X(cell) - radius) >= Map.MapCellX) {
newcell = XY_Cell(Cell_X(cell)-radius, Cell_Y(cell)+y);
BuildingClass const * building = Map[newcell].Cell_Building();
if (building != NULL && House->Is_Ally(building)) {
odds /= 2;
}
}
if ((Cell_X(cell) + radius) < (Map.MapCellX+Map.MapCellWidth)) {
newcell = XY_Cell(Cell_X(cell)+radius, Cell_Y(cell)+y);
BuildingClass const * building = Map[newcell].Cell_Building();
if (building != NULL && House->Is_Ally(building)) {
odds /= 2;
}
}
}
}
return(odds);
}
/***********************************************************************************************
* TechnoClass::Evaluate_Object -- Determines score value of specified object. *
* *
* This routine is used to determine the score value (value as a potential target) of the *
* object specified. This routine will check the specified object for all the various *
* legality checks that threat scanning requires. This is the main workhorse routine for *
* target searching. *
* *
* INPUT: method -- The threat method requested. This is a combined bitflag value that *
* not only specifies the kind of targets to consider, but how far away *
* they are allowed to be. *
* *
* mask -- This is an RTTI mask to use for quickly eliminating object types. *
* The mask is created outside of this routine because this routine is *
* usually called from within a loop and this value is constant in that *
* context. *
* *
* range -- The range at which potential target objects are rejected. *
* 0 = must be within weapon range. *
* >0 = must be within this lepton distance. *
* <0 = range doesn't matter. *
* *
* object -- Pointer to the object itself. *
* *
* value -- Reference to the value variable that this routine will fill in. The *
* higher the value the more likely this object will be selected as best. *
* *
* zone -- The zone restriction if any. A -1 means no zone check required. *
* *
* OUTPUT: Did the target pass all legality checks? If this value is returned true, then the *
* value parameter will be filled in correctly. *
* *
* WARNINGS: This routine is time consuming. Don't call unless necessary. *
* *
* HISTORY: *
* 06/30/1995 JLB : Created. *
* 07/14/1995 JLB : Forces SAM site to not fire on landed aircraft. *
* 09/22/1995 JLB : Zone checking enabled. *
* 10/05/1995 JLB : Gives greater weight to designated enemy house targets. *
* 02/16/1996 JLB : Added additional threat checks. *
*=============================================================================================*/
bool TechnoClass::Evaluate_Object(ThreatType method, int mask, int range, TechnoClass const * object, int & value, int zone) const
{
assert(IsActive);
assert(object != NULL);
BStart(BENCH_EVAL_OBJECT);
/*
** An object in limbo can never be a valid target.
*/
if (object == NULL || object->IsInLimbo) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** If the object is cloaked, then it isn't a legal target.
*/
if (object->Is_Cloaked(this)) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** If the object is in a "harmless" state, then don't bother to consider it
** a threat.
*/
if (MissionControl[object->Mission].IsNoThreat) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** If the object is not within the desired zone, then ignore it, but only if
** zone checking is desired.
*/
COORDINATE objectcoord = object->Center_Coord();
if (zone != -1 && Map[objectcoord].Zones[Techno_Type_Class()->MZone] != zone) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** Friendly units are never considered a good target. Bail if this
** object is a friend. Unless we're a medic, of course. But then,
** only consider it a target if it's injured.
*/
bool is_ally = House->Is_Ally(object);
bool is_medic = Combat_Damage() < 0;
bool green_health = object->Health_Ratio() == Rule.ConditionGreen;
if ((is_ally && (!is_medic || green_health)) || (!is_ally && is_medic)) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** If the object is further away than allowed, bail.
*/
int dist = Distance(object);
if (range > 0 && dist > range) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
if (range == 0) {
int primary = What_Weapon_Should_I_Use(object->As_Target());
if (!In_Range(object, primary)) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
}
/*
** If the object is not visible, then bail. Human controlled units
** are always considered to be visible.
*/
if (!object->IsOwnedByPlayer && !object->IsDiscoveredByPlayer && Session.Type == GAME_NORMAL && object->What_Am_I() != RTTI_AIRCRAFT) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** Quickly eliminate all unit types that are not allowed according to the mask
** value.
*/
RTTIType otype = object->What_Am_I();
if (!((1 << otype) & mask)) {
BEnd(BENCH_EVAL_OBJECT);
return(false); // Mask failure.
}
/*
** Determine if the target is theoretically allowed to be a target. If
** not, then bail.
*/
TechnoTypeClass const * tclass = object->Techno_Type_Class();
if (!tclass->IsLegalTarget) {
BEnd(BENCH_EVAL_OBJECT);
return(false); // Legality failure.
}
/*
** Never consider a spy to be a valid target, unless you're a dog
*/
if (otype == RTTI_INFANTRY && ((InfantryTypeClass const *)tclass)->Type == INFANTRY_SPY) {
if (What_Am_I() == RTTI_INFANTRY && ((InfantryClass *)this)->Class->IsDog) {
// continue executing...
} else {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
}
/*
** Special case so that SAM site doesn't fire on aircraft that are landed.
*/
if (otype == RTTI_AIRCRAFT && What_Am_I() == RTTI_BUILDING && *((BuildingClass *)this) == STRUCT_SAM) {
if (((AircraftClass *)object)->Height == 0) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
}
/*
** If only allowed to attack civilians, then eliminate all other types.
*/
if ((method & THREAT_CIVILIANS) && object->Owner() != HOUSE_NEUTRAL) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** If the scan is limited to capturable buildings only, then bail if the examined
** object isn't a capturable building.
*/
if ((method & THREAT_CAPTURE) && (otype != RTTI_BUILDING || !object->Can_Capture())) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** If we're a sub and the subject is a structure, bail if the structure
** is other than a sub pen or shipyard.
*/
if (otype == RTTI_BUILDING && What_Am_I() == RTTI_VESSEL && *(VesselClass *)this == VESSEL_SS) {
StructType ostruc = *(BuildingClass *)object;
if (ostruc != STRUCT_SUB_PEN && ostruc != STRUCT_SHIP_YARD) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
}
/*
** SPECIAL CASE: Friendly units won't automatically fire on buildings
** if the building is not aggressive. That is, unless it is part of a team. A team
** is allowed to pick any target it so chooses.
*/
if ((!Is_Foot() || !((FootClass *)this)->Team.Is_Valid()) &&
(House->IsHuman || (House->IsPlayerControl && Session.Type == GAME_NORMAL)) &&
otype == RTTI_BUILDING && tclass->PrimaryWeapon == NULL) {
#ifdef OBSOLETE
if ((!Is_Foot() || ((FootClass *)this)->Team.Is_Valid()) && House->IsHuman && otype == RTTI_BUILDING && tclass->PrimaryWeapon == NULL) {
#endif
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** Player-controlled demo trucks never automatically target.
*/
if ((House->IsHuman || (House->IsPlayerControl && Session.Type == GAME_NORMAL)) && What_Am_I() == RTTI_UNIT && *(UnitClass *)this == UNIT_DEMOTRUCK) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/*
** If the search is restricted to Tiberium processing objects, then
** perform the special qualification check now.
*/
if (method & THREAT_TIBERIUM) {
switch (otype) {
case RTTI_UNIT:
if (!((UnitTypeClass const *)tclass)->IsToHarvest) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
break;
case RTTI_BUILDING:
if (!((BuildingTypeClass const *)tclass)->Capacity && Session.Type != GAME_NORMAL) {
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
break;
default:
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
}
/*
** If this target value is better than the previously recorded best
** target value then record this target for possible return as the
** best.
*/
int rawval = object->Value();
value = rawval + object->Crew.Kills;
/*
** If the candidate object is owned by the designated enemy of this house, then
** give it a higher value. This will tend to gravitate attacks toward the main
** antagonist of this house.
*/
if (House->Enemy != HOUSE_NONE && House->Enemy == object->House->Class->House) {
value += 500;
value *= 3;
}
/*
** If the object is outside of the protective umbrella of the enemy base, then give it
** a target boost value.
*/
if (object->House->Which_Zone(object) == ZONE_NONE) {
value *= 2;
}
/*
** If fake buildings are considered to be a greater target option, then boost
** the fake building's value.
*/
if ((method & THREAT_FAKES) && otype == RTTI_BUILDING) {
//switch (!((BuildingTypeClass const *)tclass)->Type) {
//The '!' in front of the expression means we are switching on a bool instead of the type. Going to remove it so it compiles, but it might change behavior depending on what Watcom original made of this.
//Might be better to remove this switch altogether
//ST - 5/9/2019
switch (((BuildingTypeClass const *)tclass)->Type) {
case STRUCT_FAKECONST:
case STRUCT_FAKEWEAP:
case STRUCT_FAKE_YARD:
case STRUCT_FAKE_PEN:
case STRUCT_FAKE_RADAR:
break;
/*
** Ignore all non-fake buildings.
*/
default:
value = 0;
break;
}
}
/*
** If power plants are to be considered a greater threat, then increase
** their value here. Buildings that produce no power are not considered
** a threat.
*/
if ((method & THREAT_POWER) && otype == RTTI_BUILDING) {
if (((BuildingTypeClass const *)tclass)->Power > 0) {
value += ((BuildingTypeClass const *)tclass)->Power * 1000;
} else {
value = 0;
}
}
/*
** If factories are to be considered a greater threat, then don't
** consider any non-factory building.
*/
if ((method & THREAT_FACTORIES) && otype == RTTI_BUILDING) {
if (((BuildingTypeClass const *)tclass)->ToBuild == RTTI_NONE) {
value = 0;
}
}
/*
** If base defensive structures are to be considered a greater threat, then
** don't consider an unarmed building to be a threat.
*/
if ((method & THREAT_BASE_DEFENSE) /*&& otype == RTTI_BUILDING*/) {
if (tclass->PrimaryWeapon == NULL) {
value = 0;
}
}
/*
** Possibly cause a reduction of the target's value if it is nearby friendly
** structures and the primary weapon of this object is flagged for
** friendly fire supression special check logic.
*/
fixed areamod = Area_Modify(Coord_Cell(object->Center_Coord()));
if (areamod != 1) {
value = areamod * value;
}
/*
** Adjust the target value upward if it is in the 'nervous zone' of the
** owning base. This will tend to protect the base more thoroughly than
** an unmodified scan would.
*/
if (House->Which_Zone(object) != ZONE_NONE) {
value *= Rule.NervousBias;
}
/*
** Lessen threat as a factor of distance.
*/
if (value) {
// if (rawval) {
value = (value * 32000) / ((dist/ICON_LEPTON_W)+1);
// value = (value * 32000) / (((dist/ICON_LEPTON_W)*(dist/ICON_LEPTON_W))+1);
// if (value < MAP_CELL_W*2) value = dist/ICON_LEPTON_W;
value = max(value, 1);
BEnd(BENCH_EVAL_OBJECT);
return(true);
}
value = 0;
BEnd(BENCH_EVAL_OBJECT);
return(false);
}
/***********************************************************************************************
* TechnoClass::Evaluate_Cell -- Determine the value and object of specified cell. *
* *
* This routine will examine the specified cell and return with the potential target *
* object it contains and the value of it. Use this routine when searching for threats. *
* *
* INPUT: method -- The scan method to use for target searching. *
* *
* mask -- Prebuilt mask of object RTTI types acceptable for scanning. *
* *
* range -- Scan range limit to use for elimination purposes. This ensures that *
* objects in the "corner" of a square scan get properly discarded. *
* *
* object -- Pointer to object pointer to be filled in with the object at this *
* cell as a valid target. *
* *
* value -- Reference to the value of the object in this cell. It will be set *
* according to the object's value. *
* *
* zone -- The zone restriction if any. A -1 means no zone check required. *
* *
* OUTPUT: Was a valid potential target found in this cell? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/19/1995 JLB : Created. *
* 09/22/1995 JLB : Zone checking enabled. *
*=============================================================================================*/
bool TechnoClass::Evaluate_Cell(ThreatType method, int mask, CELL cell, int range, TechnoClass const * * object, int & value, int zone) const
{
assert(IsActive);
BStart(BENCH_EVAL_CELL);
*object = NULL;
value = 0;
/*
** If the cell is not on the legal map, then always ignore it.
*/
if ((unsigned)cell > MAP_CELL_TOTAL) {
BEnd(BENCH_EVAL_CELL);
return(false);
}
if (!Map.In_Radar(cell)) {
BEnd(BENCH_EVAL_CELL);
return(false);
}
/*
** Fetch the techno object from the cell. If there is no
** techno object there, then bail.
*/
CellClass * cellptr = &Map[cell];
/*
** Don't consider for evaluation a cell that is not within the same zone. Only
** perform this check if zone checking is required.
*/
if (zone != -1 && cellptr->Zones[Techno_Type_Class()->MZone] != zone) {
BEnd(BENCH_EVAL_CELL);
return(false);
}
TechnoClass const * tentative = (TechnoClass const *)cellptr->Cell_Occupier();
while (tentative != NULL) {
if (tentative != this) {
if (tentative->Is_Techno()) {
if (Combat_Damage() < 0) {
if (tentative->Health_Ratio() < Rule.ConditionGreen && House->Is_Ally(tentative)) break;
} else {
if (!House->Is_Ally(tentative)) break;
}
}
}
tentative = (TechnoClass const *)(ObjectClass *)tentative->Next;
}
if (tentative == NULL) {
BEnd(BENCH_EVAL_CELL);
return(false);
}
*object = tentative;
bool result = Evaluate_Object(method, mask, range, tentative, value);
BEnd(BENCH_EVAL_CELL);
return(result);
}
/***********************************************************************************************
* TechnoClass::Evaluate_Just_Cell -- Evaluate a cell as a target by itself. *
* *
* This will examine the cell (as if it contained no sentient objects) and determine a *
* target value to assign to it. Typically, this is only useful for wall destroyable *
* weapons when dealing with enemy walls. *
* *
* INPUT: cell -- The cell to examine and evaluate. *
* *
* OUTPUT: Returns with the target value to assign to this cell. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/10/1996 JLB : Created. *
*=============================================================================================*/
int TechnoClass::Evaluate_Just_Cell(CELL cell) const
{
BStart(BENCH_EVAL_WALL);
/*
** Ships don't scan for walls.
*/
if (What_Am_I() == RTTI_VESSEL) {
return(0);
}
/*
** First, only computer objects are allowed to automatically scan for walls.
*/
if (House->IsHuman) {
BEnd(BENCH_EVAL_WALL);
return(0);
}
/*
** Even then, if the difficulty indicates that it shouldn't search for wall
** targets, then don't allow it to do so.
*/
if (!Rule.Diff[House->Difficulty].IsWallDestroyer) {
BEnd(BENCH_EVAL_WALL);
return(0);
}
/*
** Determine if, in fact, a wall is located at this cell location.
*/
CellClass const * cellptr = &Map[cell];
if (cellptr->Overlay == OVERLAY_NONE || !OverlayTypeClass::As_Reference(cellptr->Overlay).IsWall) {
BEnd(BENCH_EVAL_WALL);
return(0);
}
/*
** As a convenience to the target scanning logic, don't consider any wall to be
** a target if it isn't in range of the primary weapon.
*/
int primary = What_Weapon_Should_I_Use(::As_Target(cell));
if (!In_Range(Cell_Coord(cell), primary)) {
BEnd(BENCH_EVAL_WALL);
return(0);
}
/*
** See if the object has a weapon that can damage walls.
*/
TechnoTypeClass const * ttype = (TechnoTypeClass const *)Techno_Type_Class();
if (ttype->PrimaryWeapon == NULL || ttype->PrimaryWeapon->WarheadPtr == NULL) {
BEnd(BENCH_EVAL_WALL);
return(0);
}
/*
** If the weapon cannot deal with ground based targets, then don't consider
** this a valid cell target.
*/
if (ttype->PrimaryWeapon->Bullet != NULL && !ttype->PrimaryWeapon->Bullet->IsAntiGround) {
BEnd(BENCH_EVAL_WALL);
return(0);
}
/*
** If the primary weapon cannot destroy a wall, then don't give the cell any
** value as a target.
*/
if (!ttype->PrimaryWeapon->WarheadPtr->IsWallDestroyer) {
BEnd(BENCH_EVAL_WALL);
return(0);
}
/*
** If this is a friendly wall, then don't attack it.
*/
if (House->Is_Ally(cellptr->Owner)) {
BEnd(BENCH_EVAL_WALL);
return(0);
}
/*
** Since a wall was found, then return a value adjusted according to the range the wall
** is from the object. The greater the range, the lesser the value returned.
*/
BEnd(BENCH_EVAL_WALL);
return(Weapon_Range(0) - Distance(Cell_Coord(cell)));
}
bool TechnoClass::Is_Cloaked(HousesType house, bool check_invisible) const
{
const bool is_invisible = check_invisible && Techno_Type_Class()->IsInvisible;
return !House->Is_Ally(house) && ((Cloak == CLOAKED) || is_invisible);
}
bool TechnoClass::Is_Cloaked(HouseClass const * house, bool check_invisible) const
{
const bool is_invisible = check_invisible && Techno_Type_Class()->IsInvisible;
return !House->Is_Ally(house) && ((Cloak == CLOAKED) || is_invisible);
}
bool TechnoClass::Is_Cloaked(ObjectClass const * object, bool check_invisible) const
{
const bool is_invisible = check_invisible && Techno_Type_Class()->IsInvisible;
return !House->Is_Ally(object) && ((Cloak == CLOAKED) || is_invisible);
}
/***********************************************************************************************
* TechnoClass::Greatest_Threat -- Determines best target given search criteria. *
* *
* This routine will scan game objects looking for the best target. It is used by the *
* general target searching processes. The type of target scan to perform is controlled *
* by the method control parameter. *
* *
* INPUT: method -- The method control parameter is used to control the type of target *
* scan performed. It consists of a series of bit flags (see ThreatType) *
* that are combined to form the target scan desired. *
* *
* OUTPUT: Returns the target value of a suitable target. If no target was found then the *
* value TARGET_NONE is returned. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 11/14/1994 JLB : Created. *
* 06/20/1995 JLB : Greatly optimized scan method. *
* 09/22/1995 JLB : Takes into account the zone (if necessary). *
* 05/30/1996 JLB : Tighter elimination mask checking. *
*=============================================================================================*/
TARGET TechnoClass::Greatest_Threat(ThreatType method) const
{
assert(IsActive);
BStart(BENCH_GREATEST_THREAT);
ObjectClass const * bestobject = NULL;
int bestval = -1;
int zone = -1;
TargetScan++;
/*
** Determine the zone that the target must be in. For aircraft and gunboats, they
** ignore zones since they either can fly over any zone or are designed to fire into
** other zones. If scanning for targets that are within range, then zone checking need
** not be performed -- range checking is much more thorough and effective.
*/
if (!(method & THREAT_RANGE) &&
What_Am_I() != RTTI_VESSEL &&
What_Am_I() != RTTI_BUILDING &&
What_Am_I() != RTTI_AIRCRAFT) {
zone = Map[Center_Coord()].Zones[Techno_Type_Class()->MZone];
}
/*
** Hack for dogs, 'cause they can only consider infantrymen to be a
** threat. Medics also.
*/
if (What_Am_I() == RTTI_INFANTRY) {
if (((InfantryClass *)this)->Class->IsDog || Combat_Damage() < 0) {
method = THREAT_INFANTRY | (method & (THREAT_RANGE | THREAT_AREA));
#ifdef FIXIT_CSII // checked - ajw 9/28/98
if(*(InfantryClass *)this == INFANTRY_MECHANIC) {
method = (THREAT_VEHICLES | THREAT_AIR) | (method & (THREAT_RANGE | THREAT_AREA));
}
#endif
}
}
/*
** Build a quick elimination mask. If the RTTI of the object doesn't
** qualify with this mask, then we KNOW that it shouldn't be considered.
*/
int mask = 0;
if (method & THREAT_CIVILIANS) mask |= ((1 << RTTI_BUILDING) | (1 << RTTI_INFANTRY) | (1 << RTTI_UNIT));
if (method & THREAT_AIR) mask |= (1 << RTTI_AIRCRAFT);
if (method & THREAT_CAPTURE) mask |= (1 << RTTI_BUILDING);
if (method & (THREAT_CIVILIANS|THREAT_BUILDINGS|THREAT_FACTORIES|THREAT_POWER|THREAT_FAKES|THREAT_BASE_DEFENSE|THREAT_TIBERIUM)) mask |= (1 << RTTI_BUILDING);
if (method & (THREAT_CIVILIANS|THREAT_INFANTRY|THREAT_BASE_DEFENSE)) mask |= (1 << RTTI_INFANTRY);
if (method & THREAT_VEHICLES) mask |= (1 << RTTI_UNIT);
if (method & THREAT_BASE_DEFENSE) mask |= (1 << RTTI_BUILDING);
if (method & THREAT_BOATS) mask |= (1 << RTTI_VESSEL);
/*
** Limit area target scans use a method where the actual map cells are
** examined for occupants. The occupant is then examined in turn. The
** best target within the area is returned as a target.
*/
if (method & (THREAT_AREA|THREAT_RANGE)) {
int range = Threat_Range((method & THREAT_RANGE) ? 0 : 1);
int crange = range / ICON_LEPTON_W;
if (range == 0) {
crange = max(Weapon_Range(0), Weapon_Range(1)) / ICON_LEPTON_W;
crange++;
}
CELL cell = Coord_Cell(Fire_Coord(0));
/*
** BG: Miserable hack to get the stupid doctor to actually do area
** guarding.
*/
if (Combat_Damage() < 0) {
/*if (method & THREAT_AREA)*/ crange++;
}
/*
** If aircraft are a legal target, then scan through all of them at this time.
** Scanning by cell is not possible for aircraft since they are not recorded
** at the cell level.
*/
if (method & THREAT_AIR) {
for (int index = 0; index < Aircraft.Count(); index++) {
TechnoClass * object = Aircraft.Ptr(index);
int value = 0;
if (object->In_Which_Layer() != LAYER_GROUND && Evaluate_Object(method, mask, range, object, value)) {
if (value > bestval) {
bestobject = object;
bestval = value;
}
}
}
}
/*
** When scanning the ground, always consider landed aircraft as a valid
** potential target. This is only true if vehicles are considered a
** valid target. A landed aircraft is considered a vehicle.
*/
if (method & THREAT_VEHICLES) {
mask |= (1 << RTTI_AIRCRAFT);
}
/*
** Radiate outward from the object's location, looking for the best
** target.
*/
CELL bestcell = -1;
int bestcellvalue = 0;
TechnoClass const * object;
int value;
// int rad = 1;
// BG: Medics need to be able to look in their own cell too.
// if (Combat_Damage() < 0 || (What_Am_I() == RTTI_INFANTRY && ((InfantryClass*)this)->Class->IsDog)) {
// rad = 0;
// }
for (int radius = 0; radius < crange; radius++) {
/*
** Scan the top and bottom rows of the "box".
*/
for (int x = -radius; x <= radius; x++) {
CELL newcell;
if ((Cell_X(cell) + x) < Map.MapCellX) continue;
if ((Cell_X(cell) + x) >= (Map.MapCellX+Map.MapCellWidth)) continue;
if ((Cell_Y(cell) - radius) >= Map.MapCellY) {
newcell = XY_Cell(Cell_X(cell) + x, Cell_Y(cell)-radius);
if (Evaluate_Cell(method, mask, newcell, range, &object, value, zone)) {
if (bestval < value) {
bestobject = object;
}
}
if (bestobject == NULL) {
value = Evaluate_Just_Cell(newcell);
if (bestcellvalue < value) {
bestcellvalue = value;
bestcell = newcell;
}
}
}
if ((Cell_Y(cell) + radius) < (Map.MapCellY+Map.MapCellHeight)) {
newcell = XY_Cell(Cell_X(cell)+x, Cell_Y(cell)+radius);
if (Evaluate_Cell(method, mask, newcell, range, &object, value, zone)) {
if (bestval < value) {
bestobject = object;
}
}
if (bestobject == NULL) {
value = Evaluate_Just_Cell(newcell);
if (bestcellvalue < value) {
bestcellvalue = value;
bestcell = newcell;
}
}
}
}
/*
** Scan the left and right columns of the "box".
*/
for (int y = -(radius-1); y < radius; y++) {
CELL newcell;
if ((Cell_Y(cell) + y) < Map.MapCellY) continue;
if ((Cell_Y(cell) + y) >= (Map.MapCellY+Map.MapCellHeight)) continue;
if ((Cell_X(cell) - radius) >= Map.MapCellX) {
newcell = XY_Cell(Cell_X(cell)-radius, Cell_Y(cell)+y);
if (Evaluate_Cell(method, mask, newcell, range, &object, value, zone)) {
if (bestval < value) {
bestobject = object;
}
}
if (bestobject == NULL) {
value = Evaluate_Just_Cell(newcell);
if (bestcellvalue < value) {
bestcellvalue = value;
bestcell = newcell;
}
}
}
if ((Cell_X(cell) + radius) < (Map.MapCellX+Map.MapCellWidth)) {
newcell = XY_Cell(Cell_X(cell)+radius, Cell_Y(cell)+y);
if (Evaluate_Cell(method, mask, newcell, range, &object, value, zone)) {
if (bestval < value) {
bestobject = object;
}
}
if (bestobject == NULL) {
value = Evaluate_Just_Cell(newcell);
if (bestcellvalue < value) {
bestcellvalue = value;
bestcell = newcell;
}
}
}
}
/*
** Bail early if a target has already been found and the range is at
** one of the breaking points (i.e., normal range or range * 2).
*/
if (bestobject != NULL) {
if (radius == crange/4) {
return(bestobject->As_Target());
}
if (radius == crange/2) {
return(bestobject->As_Target());
}
}
if (bestcell != -1) {
return(::As_Target(bestcell));
}
}
} else {
/*
** A full map scan was requested. First scan through aircraft. The top map layer
** is NOT scanned since that layer will probably contain more bullets and animations
** than aircraft.
*/
if (mask & (1L << RTTI_AIRCRAFT)) {
for (int index = 0; index < Aircraft.Count(); index++) {
TechnoClass * object = Aircraft.Ptr(index);
int value = 0;
if (Evaluate_Object(method, mask, -1, object, value)) {
if (value > bestval) {
bestobject = object;
bestval = value;
}
}
}
}
/*
** When scanning the ground, always consider landed aircraft as a valid
** potential target. This is only true if vehicles are considered a
** valid target. A landed aircraft is considered a vehicle.
*/
if (method & THREAT_VEHICLES) {
mask |= (1 << RTTI_AIRCRAFT);
}
/*
** Now scan through the entire ground layer. This is painful, but what other
** choice is there?
*/
for (int index = 0; index < Map.Layer[LAYER_GROUND].Count(); index++) {
ObjectClass const * object = Map.Layer[LAYER_GROUND][index];
int value = 0;
if (object->Is_Techno() && Evaluate_Object(method, mask, -1, (TechnoClass const *)object, value, zone)) {
if (value > bestval) {
bestobject = object;
bestval = value;
}
}
}
}
BEnd(BENCH_GREATEST_THREAT);
/*
** If a good target object was found, then return with the target value
** of it.
*/
if (bestobject != NULL) {
return(bestobject->As_Target());
}
return(TARGET_NONE);
}
/***********************************************************************************************
* TechnoClass::Owner -- Who is the owner of this object? *
* *
* Use this routine to examine this object and return who the owner is. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the house number of the owner of this object. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/09/1994 JLB : Created. *
*=============================================================================================*/
HousesType TechnoClass::Owner(void) const
{
assert(IsActive);
return(House->Class->House);
}
/***********************************************************************************************
* TechnoClass::Clicked_As_Target -- Sets the flash count for this techno object. *
* *
* Use this routine to set the flash count for the object. This flash count is the number *
* of times the object will "flash". Typically it is called as a result of the player *
* clicking on this object in order to make it the target of a move or attack. *
* *
* INPUT: count -- The number of times the object should flash. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/09/1994 JLB : Created. *
*=============================================================================================*/
void TechnoClass::Clicked_As_Target(HousesType house, int count) // 2019/09/20 JAS - Added record of who clicked on the object
{
assert(IsActive);
FlashCount = count;
// 2019/09/20 JAS - Flashing info needs to exist per player
if (house < HOUSE_COUNT)
{
FlashCountPerPlayer[house] = count;
}
else
{
//receiving HOUSE_COUNT means do it for every player
for (int i = 0; i < HOUSE_COUNT; ++i)
{
FlashCountPerPlayer[i] = count;
}
}
}
/***********************************************************************************************
* TechnoClass::AI -- Handles AI processing for techno object. *
* *
* This routine handles AI processing for techno objects. Typically, this merely dispatches *
* to the appropriate AI routines for the base classes. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: Make sure that this routine is only called ONCE per game tick. *
* *
* HISTORY: *
* 12/09/1994 JLB : Created. *
*=============================================================================================*/
void TechnoClass::AI(void)
{
assert(IsActive);
/*
** Handle recoil recovery here.
*/
if (IsInRecoilState) {
IsInRecoilState = false;
Mark(MARK_CHANGE_REDRAW);
}
/*
** If this building is being spied on by the player, need to redraw if selected
** since the money amount is rendering.
*/
if (Is_Selected_By_Player()) {
if (What_Am_I() == RTTI_BUILDING) {
int spiedby = Spied_By() & (1<<(PlayerPtr->Class->House));
if (spiedby) {
if (((BuildingClass *)this)->Class->Capacity) {
Mark(MARK_CHANGE_REDRAW);
}
}
}
}
CargoClass::AI();
RadioClass::AI();
if (!IsActive || (Height > 0 && What_Am_I() != RTTI_AIRCRAFT)) return;
DoorClass::AI();
/*
** If this is a vehicle that heals itself (e.g., Mammoth Tank), then it will perform
** the heal logic here.
*/
if (Techno_Type_Class()->IsSelfHealing && (Frame % (Rule.RepairRate * TICKS_PER_MINUTE)) == 0 && Health_Ratio() <= Rule.ConditionYellow) {
Strength++;
Mark(MARK_CHANGE);
}
/*
** Cloaking device processing.
*/
Cloaking_AI();
/*
** If for some strange reason, the computer is firing upon itself, then
** tell it not to.
*/
if (!House->IsHuman && As_Techno(TarCom) && As_Techno(TarCom)->House->Is_Ally(this) && Combat_Damage() >= 0) {
//#ifdef FIXIT_CSII // checked - ajw 9/28/98 (commented out)
//if(What_Am_I() == RTTI_INFANTRY && *(InfantryClass *)this==INFANTRY_GENERAL && Session.Type==GAME_NORMAL && House->Class->House==HOUSE_UKRAINE) {
//} else
//#endif
Assign_Target(TARGET_NONE);
}
/*
** Perform a maintenance check to see that if somehow this object is trying to fire
** upon an object it can never hit (because it can't reach it), then abort the tarcom
*/
if (What_Am_I() != RTTI_AIRCRAFT && Target_Legal(TarCom) && (!Is_Foot() || !((FootClass *)this)->Team.Is_Valid()) && (!Is_Foot() || !Is_In_Same_Zone(As_Cell(TarCom)))) {
int primary = What_Weapon_Should_I_Use(TarCom);
if (!In_Range(TarCom, primary)) {
Assign_Target(TARGET_NONE);
}
}
/*
** Update the animation timer system. If the animation stage
** changes, then flag the object to be redrawn as well as determine
** if the current animation process needs to change.
*/
if (What_Am_I() != RTTI_BUILDING) {
if (StageClass::About_To_Change()) {
Mark(MARK_CHANGE_REDRAW);
}
if (StageClass::Graphic_Logic() || Time_To_Redraw()) {
Mark(MARK_CHANGE_REDRAW);
}
}
/*
** If the object is flashing and a change of flash state has occurred, then mark the
** object to be redrawn.
*/
if (FlasherClass::Process()) {
Mark(MARK_CHANGE);
}
/*
** Handle electric zap delay logic.
*/
if (ElectricZapDelay >= 0) {
Map.Flag_To_Redraw(true);
if (--ElectricZapDelay < 0) {
ElectricZapTarget = 0;
ElectricZapWhich = 0;
}
}
}
/***********************************************************************************************
* TechnoClass::Cloaking_AI -- Perform the AI maintenance for a cloaking device. *
* *
* This routine handles the cloaking device logic for this object. It will handle the *
* transition effects as the object cloaks or decloaks. It will also try to start an *
* object to cloak if possible. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/09/1996 JLB : Created. *
*=============================================================================================*/
void TechnoClass::Cloaking_AI(void)
{
/*
** Handle decision to re-cloak here. Process the cloaking/decloaking operation.
*/
if (IsCloakable) {
/*
** If this object is uncloaked, but it can be cloaked and it thinks that it
** is a good time do so, then begin cloaking.
*/
if (Cloak == UNCLOAKED) {
#ifdef PREDATOR
// Changed for multiplayer so we can visually see the different players in the original renderer. ST - 3/13/2019 5:40PM
//if (IsOwnedByPlayer) Mark(MARK_CHANGE);
if (Is_Owned_By_Player()) Mark(MARK_CHANGE);
#endif
CloakingDevice.Graphic_Logic();
if (Is_Ready_To_Cloak()) {
if (Health_Ratio() > Rule.ConditionRed) {
Do_Cloak();
} else {
if (Percent_Chance(4)) {
Do_Cloak();
}
}
}
} else {
CloakingDevice.Graphic_Logic();
switch (Cloak) {
/*
** Handle the uncloaking process. Always mark to redraw
** the object and when cloaking is complete, stabilize into
** the normal uncloaked state.
*/
case UNCLOAKING:
Mark(MARK_CHANGE);
if (Visual_Character(true) == VISUAL_NORMAL) {
CloakingDevice.Set_Rate(0);
CloakingDevice.Set_Stage(0); // re-start the stage counter
Cloak = UNCLOAKED;
CloakDelay = Rule.CloakDelay * TICKS_PER_MINUTE;
Mark(MARK_CHANGE);
}
break;
/*
** Handle the cloaking process. Always mark to redraw the object
** and when the cloaking process is complete, stabilize into the
** normal cloaked state.
*/
case CLOAKING:
Mark(MARK_CHANGE);
if(!CloakingDevice.Fetch_Rate()) {
CloakingDevice.Set_Rate(1);
}
switch (Visual_Character(true)) {
/*
** If badly damaged, then it can never fully cloak.
*/
case VISUAL_DARKEN:
if (Health_Ratio() <= Rule.ConditionRed && Percent_Chance(25)) {
Cloak = UNCLOAKING;
}
break;
case VISUAL_HIDDEN:
Cloak = CLOAKED;
CloakingDevice.Set_Rate(0);
CloakingDevice.Set_Stage(0);
Mark(MARK_CHANGE);
Map[Center_Coord()].Redraw_Objects(true);
Map.RadarClass::Flag_To_Redraw(true);
/*
** Special check to ensure that if the unit is carrying a captured
** flag, it will never fully cloak.
*/
if (What_Am_I() == RTTI_UNIT && ((UnitClass *)this)->Flagged != HOUSE_NONE) {
Do_Shimmer();
} else {
Detach_All(false);
}
/*
** A computer controlled unit will try to scatter if possible so
** that it will be much harder to locate.
*/
if (What_Am_I() == RTTI_UNIT && !House->IsHuman) {
Scatter(0, true);
}
break;
}
break;
/*
** A cloaked object will always be redrawn if it is owned by the
** player. This ensures that the shimmering effect will animate.
*/
case CLOAKED:
#ifdef PREDATOR
//if (IsOwnedByPlayer) {
// Changed for multiplayer so we can visually see the different players in the original renderer. ST - 3/13/2019 5:40PM
if (Is_Owned_By_Player()) {
Mark(MARK_CHANGE);
}
#endif
break;
}
}
}
}
/***********************************************************************************************
* TechnoClass::Is_Ready_To_Cloak -- Determines if this object is ready to begin cloaking. *
* *
* This routine will examine this object and determine if it can and is ready and able *
* to begin cloaking. It will also check to make sure it appears to be a good time to cloak *
* as well. *
* *
* INPUT: none *
* *
* OUTPUT: bool; Is this unit ready and able to start cloaking? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/09/1996 JLB : Created. *
*=============================================================================================*/
bool TechnoClass::Is_Ready_To_Cloak(void) const
{
/*
** If it is already cloaked or in the process of cloaking, then it can't start cloaking.
*/
if (Cloak == CLOAKED || (Cloak == CLOAKING && CloakingDevice.Fetch_Rate())) {
return(false);
}
/*