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.
 
 
 
 

6088 lines
247 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/BUILDING.CPP 5 3/13/97 5:18p Joe_b $ */
/***********************************************************************************************
*** 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 : BUILDING.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : September 10, 1993 *
* *
* Last Update : October 27, 1996 [JLB] *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* BuildingClass::AI -- Handles non-graphic AI processing for buildings. *
* BuildingClass::Active_Click_With -- Handles cell selection for buildings. *
* BuildingClass::Animation_AI -- Handles normal building animation processing. *
* BuildingClass::Assign_Target -- Assigns a target to the building. *
* BuildingClass::Begin_Mode -- Begins an animation mode for the building. *
* BuildingClass::BuildingClass -- Constructor for buildings. *
* BuildingClass::Can_Demolish -- Can the player demolish (sell back) the building? *
* BuildingClass::Can_Enter_Cell -- Determines if building can be placed down. *
* BuildingClass::Can_Fire -- Determines if this building can fire. *
* BuildingClass::Can_Player_Move -- Can this building be moved? *
* BuildingClass::Captured -- Captures the building. *
* BuildingClass::Center_Coord -- Fetches the center coordinate for the building. *
* BuildingClass::Charging_AI -- Handles the special charging logic for Tesla coils. *
* BuildingClass::Check_Point -- Fetches the landing checkpoint for the given flight pattern.*
* BuildingClass::Click_With -- Handles clicking on the map while the building is selected. *
* BuildingClass::Crew_Type -- This determines the crew that this object generates. *
* BuildingClass::Death_Announcement -- Announce the death of this building. *
* BuildingClass::Debug_Dump -- Displays building status to the monochrome screen. *
* BuildingClass::Detach -- Handles target removal from the game system. *
* BuildingClass::Detach_All -- Possibly abandons production according to factory type. *
* BuildingClass::Docking_Coord -- Fetches the coordinate to use for docking. *
* BuildingClass::Draw_It -- Displays the building at the location specified. *
* BuildingClass::Drop_Debris -- Drops rubble when building is destroyed. *
* BuildingClass::Enter_Idle_Mode -- The building will enter its idle mode. *
* BuildingClass::Exit_Coord -- Determines location where object will leave it. *
* BuildingClass::Exit_Object -- Initiates an object to leave the building. *
* BuildingClass::Factory_AI -- Handle factory production and initiation. *
* BuildingClass::Find_Exit_Cell -- Find a clear location to exit an object from this buildin*
* BuildingClass::Fire_Direction -- Fetches the direction of firing. *
* BuildingClass::Fire_Out -- Handles when attached animation expires. *
* BuildingClass::Flush_For_Placement -- Handles clearing a zone for object placement. *
* BuildingClass::Get_Image_Data -- Fetch the image pointer for the building. *
* BuildingClass::Grand_Opening -- Handles construction completed special operations. *
* BuildingClass::Greatest_Threat -- Searches for target that building can fire upon. *
* BuildingClass::How_Many_Survivors -- This determine the maximum number of survivors. *
* BuildingClass::Init -- Initialize the building system to an empty null state. *
* BuildingClass::Limbo -- Handles power adjustment as building goes into limbo. *
* BuildingClass::Mark -- Building interface to map rendering system. *
* BuildingClass::Mission_Attack -- Handles attack mission for building. *
* BuildingClass::Mission_Construction -- Handles mission construction. *
* BuildingClass::Mission_Deconstruction -- Handles building deconstruction. *
* BuildingClass::Mission_Guard -- Handles guard mission for combat buildings. *
* BuildingClass::Mission_Harvest -- Handles refinery unloading harvesters. *
* BuildingClass::Mission_Missile -- State machine for nuclear missile launch. *
* BuildingClass::Mission_Repair -- Handles the repair (active) state for building. *
* BuildingClass::Mission_Unload -- Handles the unload mission for a building. *
* BuildingClass::Pip_Count -- Determines "full" pips to display for building. *
* BuildingClass::Power_Output -- Fetches the current power output from this building. *
* BuildingClass::Read_INI -- Reads buildings from INI file. *
* BuildingClass::Receive_Message -- Handle an incoming message to the building. *
* BuildingClass::Remap_Table -- Fetches the remap table to use for this building. *
* BuildingClass::Remove_Gap_Effect -- Stop a gap generator from jamming cells *
* BuildingClass::Repair -- Initiates or terminates the repair process. *
* BuildingClass::Repair_AI -- Handle the repair (and sell) logic for the building. *
* BuildingClass::Revealed -- Reveals the building to the specified house. *
* BuildingClass::Rotation_AI -- Process any turret rotation required of this building. *
* BuildingClass::Sell_Back -- Controls the sell back (demolish) operation. *
* BuildingClass::Shape_Number -- Fetch the shape number for this building. *
* BuildingClass::Sort_Y -- Returns the building coordinate used for sorting. *
* BuildingClass::Take_Damage -- Inflicts damage points upon a building. *
* BuildingClass::Target_Coord -- Return the coordinate to use when firing on this building. *
* BuildingClass::Toggle_Primary -- Toggles the primary factory state. *
* BuildingClass::Turret_Facing -- Fetches the turret facing for this building. *
* BuildingClass::Unlimbo -- Removes a building from limbo state. *
* BuildingClass::Update_Buildables -- Informs sidebar of additional construction options. *
* BuildingClass::Value -- Determine the value of this building. *
* BuildingClass::What_Action -- Determines action to perform if click on specified object. *
* BuildingClass::What_Action -- Determines what action will occur. *
* BuildingClass::Write_INI -- Write out the building data to the INI file specified. *
* BuildingClass::delete -- Deallocates building object. *
* BuildingClass::new -- Allocates a building object from building pool. *
* BuildingClass::~BuildingClass -- Destructor for building type objects. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
/*
** New sidebar for GlyphX multiplayer. ST - 8/2/2019 2:35PM
*/
#include "SidebarGlyphx.h"
enum SAMState {
SAM_READY, // Launcher can be facing any direction tracking targets.
SAM_FIRING // Stationary while missile is being fired.
};
/***************************************************************************
** Center of building offset table.
*/
COORDINATE const BuildingClass::CenterOffset[BSIZE_COUNT] = {
0x00800080L,
0x008000FFL,
0x00FF0080L,
0x00FF00FFL,
0x018000FFL,
0x00FF0180L,
0x01800180L,
0x00FF0200L,
0x02800280L,
};
/***********************************************************************************************
* BuildingClass::Receive_Message -- Handle an incoming message to the building. *
* *
* This routine handles an incoming message to the building. Messages regulate the *
* various cooperative ventures between buildings and units. This might include such *
* actions as coordinating the construction yard animation with the actual building's *
* construction animation. *
* *
* INPUT: from -- The originator of the message received. *
* *
* message -- The radio message received. *
* *
* param -- Reference to an optional parameter that might be used to return *
* extra information to the message originator. *
* *
* OUTPUT: Returns with the response to the message (typically, this is just RADIO_OK). *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/09/1994 JLB : Created. *
* 06/26/1995 JLB : Forces refinery load anim to start immediately. *
* 08/13/1995 JLB : Uses ScenarioInit for special loose "CAN_LOAD" check. *
*=============================================================================================*/
RadioMessageType BuildingClass::Receive_Message(RadioClass * from, RadioMessageType message, long & param)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
switch (message) {
/*
** This message is received as a request to attach/load/dock with this building.
** Verify that this is allowed and return the appropriate response.
*/
case RADIO_CAN_LOAD:
TechnoClass::Receive_Message(from, message, param);
if (!House->Is_Ally(from)) return(RADIO_STATIC);
if (Mission == MISSION_CONSTRUCTION || Mission == MISSION_DECONSTRUCTION || BState == BSTATE_CONSTRUCTION || (!ScenarioInit && Class->Type != STRUCT_REFINERY && In_Radio_Contact())) return(RADIO_NEGATIVE);
switch (Class->Type) {
case STRUCT_AIRSTRIP:
if (from->What_Am_I() == RTTI_AIRCRAFT && ((AircraftClass const *)from)->Class->IsFixedWing) {
return(RADIO_ROGER);
}
break;
case STRUCT_HELIPAD:
if (from->What_Am_I() == RTTI_AIRCRAFT && !((AircraftClass const *)from)->Class->IsFixedWing) {
return(RADIO_ROGER);
}
break;
case STRUCT_REPAIR:
if (from->What_Am_I() == RTTI_UNIT || (from->What_Am_I() == RTTI_AIRCRAFT)) {
if (Transmit_Message(RADIO_ON_DEPOT, from) != RADIO_ROGER) {
return(RADIO_ROGER);
}
}
return(RADIO_NEGATIVE);
case STRUCT_REFINERY:
if (from->What_Am_I() == RTTI_UNIT &&
*((UnitClass *)from) == UNIT_HARVESTER &&
(ScenarioInit || !Is_Something_Attached())) {
return((Contact_With_Whom() != from) ? RADIO_ROGER : RADIO_NEGATIVE);
}
break;
default:
break;
}
return(RADIO_STATIC);
/*
** This message is received when the object has attached itself to this
** building.
*/
case RADIO_IM_IN:
if (Mission == MISSION_DECONSTRUCTION) {
return(RADIO_NEGATIVE);
}
switch (Class->Type) {
case STRUCT_REPAIR:
IsReadyToCommence = true;
Assign_Mission(MISSION_REPAIR);
from->Assign_Mission(MISSION_SLEEP);
return(RADIO_ROGER);
case STRUCT_AIRSTRIP:
case STRUCT_HELIPAD:
Assign_Mission(MISSION_REPAIR);
from->Assign_Mission(MISSION_SLEEP);
return(RADIO_ROGER);
case STRUCT_REFINERY:
Mark(MARK_CHANGE);
from->Assign_Mission(MISSION_UNLOAD);
return(RADIO_ROGER);
default:
break;
}
break;
/*
** Docking maneuver maintenance message. See if new order should be given to the
** unit trying to dock.
*/
case RADIO_DOCKING:
TechnoClass::Receive_Message(from, message, param);
/*
** When in radio contact for loading, the refinery starts
** flashing the lights.
*/
if (*this == STRUCT_REFINERY && BState != BSTATE_FULL) {
Begin_Mode(BSTATE_FULL);
}
/*
** If this building is already in radio contact, then it might
** be able to satisfy the request to load by bumping off any
** preoccupying task.
*/
if (*this == STRUCT_REPAIR) {
if (Contact_With_Whom() != from) {
if (Transmit_Message(RADIO_ON_DEPOT) == RADIO_ROGER) {
if (Transmit_Message(RADIO_NEED_REPAIR) == RADIO_NEGATIVE) {
Transmit_Message(RADIO_RUN_AWAY);
Transmit_Message(RADIO_OVER_OUT);
return(RADIO_ROGER);
}
}
}
}
/*
** Establish contact with the object if this building isn't already in contact
** with another.
*/
if (!In_Radio_Contact()) {
Transmit_Message(RADIO_HELLO, from);
}
if (Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER) {
switch (Class->Type) {
case STRUCT_AIRSTRIP:
param = As_Target();
break;
case STRUCT_HELIPAD:
param = As_Target();
break;
case STRUCT_REPAIR:
Transmit_Message(RADIO_TETHER);
param = ::As_Target(Coord_Cell(Center_Coord()));
break;
case STRUCT_REFINERY:
param = ::As_Target(Coord_Cell(Adjacent_Cell(Center_Coord(), DIR_S)));
break;
}
/*
** Tell the harvester to move to the docking pad of the building.
*/
if (Transmit_Message(RADIO_MOVE_HERE, param) == RADIO_YEA_NOW_WHAT) {
/*
** Since the harvester is already there, tell it to begin the backup
** procedure now. If it can't, then tell it to get outta here.
*/
Transmit_Message(RADIO_TETHER);
if (*this == STRUCT_REFINERY && Transmit_Message(RADIO_BACKUP_NOW, from) != RADIO_ROGER) {
from->Scatter(NULL, true, true);
}
}
}
return(RADIO_ROGER);
/*
** If a transport or harvester is requesting permission to head toward, dock
** and load/unload, check to make sure that this is allowed given the current
** state of the building.
*/
case RADIO_ARE_REFINERY:
if (Is_Something_Attached() || In_Radio_Contact() || IsInLimbo || House->Class->House != from->Owner() || (*this != STRUCT_REFINERY/* && *this != STRUCT_REPAIR*/)) {
return(RADIO_NEGATIVE);
}
return(RADIO_ROGER);
/*
** Someone is telling us that it is starting construction. This should only
** occur if this is a construction yard and a building was just placed on
** the map.
*/
case RADIO_BUILDING:
Assign_Mission(MISSION_REPAIR);
TechnoClass::Receive_Message(from, message, param);
return(RADIO_ROGER);
/*
** Someone is telling us that they have finished construction. This should
** only occur if this is a construction yard and the building that was being
** constructed has finished. In this case, stop the construction yard
** animation.
*/
case RADIO_COMPLETE:
if (Mission != MISSION_DECONSTRUCTION) {
Assign_Mission(MISSION_GUARD);
}
TechnoClass::Receive_Message(from, message, param);
return(RADIO_ROGER);
/*
** This message may occur unexpectedly if the unit in contact with this
** building is suddenly destroyed. Handle any cleanup necessary. For example,
** a construction yard should stop its construction animation in this case.
*/
case RADIO_OVER_OUT:
Begin_Mode(BSTATE_IDLE);
if (*this == STRUCT_REPAIR) {
Assign_Mission(MISSION_GUARD);
}
TechnoClass::Receive_Message(from, message, param);
return(RADIO_ROGER);
/*
** This message is received when an object has completely left
** building. Sometimes special cleanup action is required when
** this event occurs.
*/
case RADIO_UNLOADED:
if (*this == STRUCT_REPAIR) {
if (Distance(from) < 0x0180) {
return(RADIO_ROGER);
}
}
TechnoClass::Receive_Message(from, message, param);
if (*this == STRUCT_WEAP || *this == STRUCT_AIRSTRIP || *this == STRUCT_REPAIR) return(RADIO_RUN_AWAY);
return(RADIO_ROGER);
default:
break;
}
/*
** Pass along the message to the default message handler in the radio itself.
*/
return(TechnoClass::Receive_Message(from, message, param));
}
#ifdef CHEAT_KEYS
/***********************************************************************************************
* BuildingClass::Debug_Dump -- Displays building status to the monochrome screen. *
* *
* This utility function will output the current status of the building class to the *
* monochrome screen. It is through this data that bugs may be fixed or detected. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
*=============================================================================================*/
void BuildingClass::Debug_Dump(MonoClass * mono) const
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
mono->Set_Cursor(0, 0);
mono->Print(Text_String(TXT_DEBUG_BUILDING));
mono->Fill_Attrib(66, 13, 12, 1, IsRepairing ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(66, 14, 12, 1, IsToRebuild ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(66, 15, 12, 1, IsAllowedToSell ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(66, 16, 12, 1, IsCharging ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(66, 17, 12, 1, IsCharged ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(66, 18, 12, 1, IsJamming ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Fill_Attrib(66, 19, 12, 1, IsJammed ? MonoClass::INVERSE : MonoClass::NORMAL);
mono->Set_Cursor(1, 11);
if (Factory) {
mono->Printf("%s %d%%", Factory->Get_Object()->Class_Of().IniName, (100*Factory->Completion())/FactoryClass::STEP_COUNT);
}
TechnoClass::Debug_Dump(mono);
}
#endif
/***********************************************************************************************
* BuildingClass::Draw_It -- Displays the building at the location specified. *
* *
* This is the low level graphic routine that displays the building at the location *
* specified. *
* *
* INPUT: x,y -- The coordinate to draw the building at. *
* *
* window -- The clipping window to use. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/20/1994 JLB : Created. *
* 06/27/1994 JLB : Takes a clipping window parameter. *
* 07/06/1995 JLB : Handles damaged silos correctly. *
*=============================================================================================*/
void BuildingClass::Draw_It(int x, int y, WindowNumberType window) const
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
/*
** The shape file to use for rendering depends on whether the building
** is undergoing construction or not.
*/
void const * shapefile = Get_Image_Data();
if (shapefile == NULL) return;
/*
** Actually draw the building shape.
*/
IsTheaterShape = Class->IsTheater; //Let Build_Frame know if this is a theater specific shape
Techno_Draw_Object(shapefile, Shape_Number(), x, y, window);
IsTheaterShape = false;
/*
** Patch for adding overlay onto weapon factory. Only add the overlay if
** the building has more than 1 hp. Also, if the building's in radio
** contact, he must be unloading a constructed vehicle, so draw that
** vehicle before drawing the overlay.
*/
if (BState != BSTATE_CONSTRUCTION) {
/*
** A Tethered object is always rendered AFTER the building.
*/
if (*this == STRUCT_WEAP && IsTethered && In_Radio_Contact() && !Contact_With_Whom()->IsInLimbo && Contact_With_Whom()->What_Am_I() != RTTI_BUILDING) {
TechnoClass * contact = Contact_With_Whom();
assert(contact->IsActive);
int xxx = x + ((int)Lepton_To_Pixel((int)Coord_X(contact->Render_Coord())) - (int)Lepton_To_Pixel((int)Coord_X(Render_Coord())));
int yyy = y + ((int)Lepton_To_Pixel((int)Coord_Y(contact->Render_Coord())) - (int)Lepton_To_Pixel((int)Coord_Y(Render_Coord())));
contact->Draw_It(xxx, yyy, window);
contact->IsToDisplay = false;
}
/*
** Draw the weapon factory custom overlay graphic.
*/
if ( (*this == STRUCT_WEAP || *this == STRUCT_FAKEWEAP)) {
int shapenum = Door_Stage();
if (Health_Ratio() <= Rule.ConditionYellow) shapenum += 4;
// Added override shape file name. ST - 8/1/2019 5:24PM
//Techno_Draw_Object(Class->WarFactoryOverlay, shapenum, x, y, window);
Techno_Draw_Object_Virtual(Class->WarFactoryOverlay, shapenum, x, y, window, DIR_N, 0x0100, "WEAP2");
}
/*
** Draw any repair feedback graphic required.
*/
if (IsRepairing && IsWrenchVisible) {
CC_Draw_Shape(ObjectTypeClass::SelectShapes, SELECT_WRENCH, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL);
}
}
TechnoClass::Draw_It(x, y, window);
/*
** If this is a factory that we're spying on, show what it's producing
*/
if ((Spied_By() & (1<<(PlayerPtr->Class->House)) && Is_Selected_By_Player()) || ((window == WINDOW_VIRTUAL) && (Session.Type != GAME_NORMAL))) {
/*
** Fetch the factory that is associate with this building. For computer controlled buildings, the
** factory pointer is integral to the building itself. For human controlled buildings, the factory
** pointer is part of the house structure and must be retrieved from there.
*/
FactoryClass * factory = NULL;
if (House->IsHuman) {
factory = House->Fetch_Factory(Class->ToBuild);
} else {
factory = Factory;
}
/*
** If there is a factory associated with this building, then fetch any attached
** object under production and display its cameo image over the top of this building.
*/
if (factory != NULL) {
TechnoClass * obj = factory->Get_Object();
if (obj != NULL) {
#ifdef FIXIT_CSII
CC_Draw_Shape(obj, obj->Techno_Type_Class()->Get_Cameo_Data(), 0, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_NORMAL, NULL);
#else
void const * remapper = obj->House->Remap_Table(false, obj->Techno_Type_Class()->Remap);
CC_Draw_Shape(obj->Techno_Type_Class()->Get_Cameo_Data(), 0, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL | ((remapper != NULL) ? SHAPE_FADING : SHAPE_NORMAL), remapper);
#endif
}
}
}
}
/***********************************************************************************************
* BuildingClass::Shape_Number -- Fetch the shape number for this building. *
* *
* This routine will examine the current state of the building and return with the shape *
* number to use. The shape number is subordinate to the building graphic image data. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the shape number to use when rendering this building. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/29/1996 JLB : Created. *
*=============================================================================================*/
int BuildingClass::Shape_Number(void) const
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
int shapenum = Fetch_Stage();
/*
** The shape file to use for rendering depends on whether the building
** is undergoing construction or not.
*/
if (BState == BSTATE_CONSTRUCTION) {
/*
** If the building is deconstructing, then the display frame progresses
** from the end to the beginning. Reverse the shape number accordingly.
*/
if (Mission == MISSION_DECONSTRUCTION) {
shapenum = (Class->Anims[BState].Start+Class->Anims[BState].Count-1)-shapenum;
}
} else {
/*
** If this is a camouflaged pill box and it is not owned by the player, then
** it is displayed with the MEGA-camouflaged imagery.
*/
if ((!IsOwnedByPlayer) && (*this == STRUCT_CAMOPILLBOX)) {
shapenum += 1;
}
/*
** The Tesla Coil has a stage value that can be overridden by
** its current state.
*/
if (*this == STRUCT_TESLA) {
if (IsCharged) {
shapenum = 3;
} else {
if (IsCharging) {
shapenum = Fetch_Stage();
} else {
shapenum = 0;
}
}
}
/*
** Buildings that contain a turret handle their shape determination
** differently than normal buildings. They need to take into consideration
** the direction the turret is facing.
*/
if (Class->IsTurretEquipped) {
shapenum = UnitClass::BodyShape[Dir_To_32(PrimaryFacing.Current())];
if (*this == STRUCT_SAM) {
/*
** SAM sites that are free to rotate fetch their animation frame
** from the building's turret facing. All other animation stages
** fetch their frame from the embedded animation sequencer.
*/
// if (Status == SAM_READY || Status == SAM_FIRING || Status == SAM_LOCKING) {
// shapenum = Fetch_Stage();
// }
if (Health_Ratio() <= Rule.ConditionYellow) {
shapenum += 35;
}
} else {
if (IsInRecoilState) {
shapenum += 32;
}
if (Health_Ratio() <= Rule.ConditionYellow) {
shapenum += 64;
}
}
} else {
/*
** If it is a significantly damaged weapons factory, it is shown in
** the worst state possible.
*/
if (*this == STRUCT_WEAP || *this == STRUCT_FAKEWEAP) {
shapenum = 0;
if (Health_Ratio() <= Rule.ConditionYellow) {
shapenum = 1;
}
} else {
/*
** Special render stage for silos. The stage is dependent on the current
** Tiberium collected as it relates to Tiberium capacity.
*/
if (*this == STRUCT_STORAGE) {
int level = 0;
if (House->Capacity) {
level = (House->Tiberium * 5) / House->Capacity;
}
shapenum += Bound(level, 0, 4);
if (Health_Ratio() <= Rule.ConditionYellow) {
shapenum += 5;
}
} else {
/*
** If below half strenth, then show the damage frames of the
** building.
*/
if (Health_Ratio() <= Rule.ConditionYellow) {
if (*this == STRUCT_CHRONOSPHERE) {
shapenum += 29;
} else {
int last1 = Class->Anims[BSTATE_IDLE].Start + Class->Anims[BSTATE_IDLE].Count;
int last2 = Class->Anims[BSTATE_ACTIVE].Start + Class->Anims[BSTATE_ACTIVE].Count;
int largest = max(last1, last2);
last2 = Class->Anims[BSTATE_AUX1].Start + Class->Anims[BSTATE_AUX1].Count;
largest = max(largest, last2);
last2 = Class->Anims[BSTATE_AUX2].Start + Class->Anims[BSTATE_AUX2].Count;
largest = max(largest, last2);
shapenum += largest;
}
}
}
}
}
}
return(shapenum);
}
/***********************************************************************************************
* BuildingClass::Mark -- Building interface to map rendering system. *
* *
* This routine is used to mark the map cells so that when it renders *
* the underlying icons will also be updated as necessary. *
* *
* INPUT: mark -- Type of image change (MARK_UP, _DOWN, _CHANGE) *
* MARK_UP -- Building is removed. *
* MARK_CHANGE -- Building changes shape. *
* MARK_DOWN -- Building is added. *
* *
* OUTPUT: bool; Did the mark operation succeed? Failure could be the result of marking down *
* when the building is already marked down, or visa versa. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 03/31/1994 JLB : Created. *
* 04/15/1994 JLB : Converted to member function. *
* 04/16/1994 JLB : Added health bar tracking. *
* 12/23/1994 JLB : Calls low level check before proceeding. *
* 01/27/1995 JLB : Special road spacer template added. *
*=============================================================================================*/
bool BuildingClass::Mark(MarkType mark)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (TechnoClass::Mark(mark)) {
short const * offset = Overlap_List();
short const * occupy = Occupy_List();
CELL cell = Coord_Cell(Coord);
SmudgeType bib;
switch (mark) {
case MARK_UP:
Map.Pick_Up(cell, this);
if (Class->Bib_And_Offset(bib, cell)) {
SmudgeClass * smudge = new SmudgeClass(bib);
if (smudge != NULL) {
smudge->Disown(cell);
delete smudge;
}
}
break;
case MARK_DOWN:
/*
** Special wall logic is handled here. A building that is really a wall
** gets converted into an overlay wall type when it is placed down. The
** actual building object itself is destroyed.
*/
if (Class->IsWall) {
switch (Class->Type) {
case STRUCT_BRICK_WALL:
new OverlayClass(OVERLAY_BRICK_WALL, cell, House->Class->House);
break;
case STRUCT_BARBWIRE_WALL:
new OverlayClass(OVERLAY_BARBWIRE_WALL, cell, House->Class->House);
break;
case STRUCT_SANDBAG_WALL:
new OverlayClass(OVERLAY_SANDBAG_WALL, cell, House->Class->House);
break;
case STRUCT_WOOD_WALL:
new OverlayClass(OVERLAY_WOOD_WALL, cell, House->Class->House);
break;
case STRUCT_CYCLONE_WALL:
new OverlayClass(OVERLAY_CYCLONE_WALL, cell, House->Class->House);
break;
case STRUCT_FENCE:
new OverlayClass(OVERLAY_FENCE, cell, House->Class->House);
break;
default:
break;
}
Transmit_Message(RADIO_OVER_OUT);
delete this;
} else {
if (Can_Enter_Cell(cell) == MOVE_OK) {
/*
** Determine if a bib is required for this building. If one is, then
** create and place it.
*/
CELL newcell = cell;
if (Class->Bib_And_Offset(bib, newcell)) {
new SmudgeClass(bib, Cell_Coord(newcell), Class->IsBase ? House->Class->House : HOUSE_NONE);
}
Map.Place_Down(cell, this);
} else {
return(false);
}
}
break;
case MARK_CHANGE_REDRAW:
Map.Refresh_Cells(cell, Overlap_List(true));
break;
default:
Map.Refresh_Cells(cell, Overlap_List(false));
Map.Refresh_Cells(cell, occupy);
break;
}
return(true);
}
return(false);
}
/***********************************************************************************************
* BuildingClass::AI -- Handles non-graphic AI processing for buildings. *
* *
* This function is to handle the AI logic for the building. The graphic logic (facing, *
* firing, and animation) is handled elsewhere. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
* 12/26/1994 JLB : Handles production. *
* 06/11/1995 JLB : Revamped. *
*=============================================================================================*/
void BuildingClass::AI(void)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
/*
** Process building animation state changes. Transition to a following state
** if there is one specified and the current animation sequence has expired.
** This process must occur before mission AI since the mission AI relies on
** the bstate change to occur immediately before the MissionClass::AI.
*/
Animation_AI();
/*
** If now is a good time to act on a new mission, then do so. This process occurs
** here because some outside event may have requested a mission change for the building.
** Such outside requests (player input) must be initiated BEFORE the normal AI process.
*/
if (IsReadyToCommence && BState != BSTATE_CONSTRUCTION) {
/*
** Clear the commencement flag ONLY if something actually occurred. By acting
** this way, a building can set the IsReadyToCommence flag before it goes
** to "sleep" knowing that it will wake up as soon as a new mission comes
** along.
*/
if (Commence()) {
IsReadyToCommence = false;
}
}
/*
** Proceed with normal logic processing. This is where the mission processing
** occurs. This call must be located after the animation sequence makes the
** transition to the next frame (see above) in order for the mission logic to
** act at the exact moment of graphic transition BEFORE it has a chance to
** be displayed.
*/
TechnoClass::AI();
/*
** Bail if the object died in the AI routine.
*/
if (!IsActive) {
return;
}
/*
** Building ammo is instantly reloaded.
*/
if (!Ammo) {
Ammo = Class->MaxAmmo;
}
/*
** If now is a good time to act on a new mission, then do so. This occurs here because
** some AI event may have requested a mission change (usually from another mission
** state machine). This must occur here before it has a chance to render.
*/
if (IsReadyToCommence) {
/*
** Clear the commencement flag ONLY if something actually occurred. By acting
** this way, a building can set the IsReadyToCommence flag before it goes
** to "sleep" knowing that it will wake up as soon as a new mission comes
** along.
*/
if (Commence()) {
IsReadyToCommence = false;
}
}
/*
** If a change of animation was requested, then make the change
** now. The building animation system acts independently but subordinate
** to the mission state machine system. By performing the animation change-up
** here, the mission AI system is ensured of immediate visual affect when it
** decides to change the animation state of the building.
*/
if (QueueBState != BSTATE_NONE) {
if (BState != QueueBState) {
BState = QueueBState;
BuildingTypeClass::AnimControlType const * ctrl = Fetch_Anim_Control();
if (BState == BSTATE_CONSTRUCTION || BState == BSTATE_IDLE) {
Set_Rate(Options.Normalize_Delay(ctrl->Rate));
} else {
Set_Rate(ctrl->Rate);
}
Set_Stage(ctrl->Start);
}
QueueBState = BSTATE_NONE;
}
/*
** If the building's strength has changed, then update the power
** accordingly.
*/
if (Strength != LastStrength) {
int oldpower = Power_Output();
LastStrength = Strength;
int newpower = Power_Output();
House->Adjust_Power(newpower - oldpower);
}
/*
** Check to see if the destruction countdown timer is active. If so, then decrement it.
** When this timer reaches zero, the building is removed from the map. All the explosions
** are presumed to be in progress at this time.
*/
if (Strength == 0) {
if (CountDown == 0) {
Limbo();
Drop_Debris(WhomToRepay);
delete this;
}
return;
}
/*
** Charging logic.
*/
Charging_AI();
/*
** Handle any repair process that may be going on.
*/
Repair_AI();
/*
** For computer controlled buildings, determine what should be produced and start
** production accordingly.
*/
Factory_AI();
/*
** Check for demolition timeout. When timeout has expired, the building explodes.
*/
if (IsGoingToBlow && CountDown == 0) {
/*
** Maybe trigger an achivement. ST - 11/14/2019 1:53PM
*/
TechnoTypeClass const *object_type = Techno_Type_Class();
if (object_type) {
TechnoClass *saboteur = As_Techno(WhomToRepay);
if (saboteur && saboteur->IsActive && saboteur->House && saboteur->House->IsHuman) {
On_Achievement_Event(saboteur->House, "BUILDING_DESTROYED_C4", object_type->IniName);
}
}
int damage = Strength;
Take_Damage(damage, 0, WARHEAD_FIRE, As_Techno(WhomToRepay), true);
if (!IsActive) {
return;
}
Mark(MARK_CHANGE);
}
/*
** Turret equiped buildings must handle turret rotation logic here. This entails
** rotating the turret to the desired facing as well as figuring out what that
** desired facing should be.
*/
Rotation_AI();
/*
** Gap Generators need to scan if they've just become activated, or if
** the power has just come on enough so they can scan. Also, they need
** to un-jam if the power has just dropped off.
*/
if (*this == STRUCT_GAP) {
if (Arm == 0) {
IsJamming = false;
Arm = TICKS_PER_MINUTE * Rule.GapRegenInterval + Random_Pick(1, TICKS_PER_SECOND);
}
if (!IsJamming) {
if (House->Power_Fraction() >= 1) {
Map.Jam_From(Coord_Cell(Center_Coord()), Rule.GapShroudRadius, House);
IsJamming = true;
}
} else {
if (House->Power_Fraction() < 1) {
IsJamming = false;
Map.UnJam_From(Coord_Cell(Center_Coord()), Rule.GapShroudRadius, House);
}
}
}
/*
** Radar facilities and SAMs need to check for the proximity of a mobile
** radar jammer.
*/
if ((*this == STRUCT_RADAR || *this == STRUCT_SAM) && (Frame % TICKS_PER_SECOND) == 0) {
IsJammed = false;
for (int index = 0; index < Units.Count(); index++) {
UnitClass * obj = Units.Ptr(index);
if (obj != NULL &&
!obj->IsInLimbo &&
!obj->House->Is_Ally(House) &&
obj->Class->IsJammer &&
Distance(obj) <= Rule.RadarJamRadius) {
IsJammed = true;
break;
}
}
}
/*
** Chronosphere active animation control.
*/
if (*this == STRUCT_CHRONOSPHERE && BState == BSTATE_ACTIVE && QueueBState == BSTATE_NONE && Scen.FadeTimer == 0) {
Begin_Mode(BSTATE_IDLE);
}
}
/***********************************************************************************************
* BuildingClass::Unlimbo -- Removes a building from limbo state. *
* *
* Use this routine to transform a building that has been held in limbo *
* state, into one that really exists on the map. Once a building as *
* been unlimboed, then it becomes a normal object in the game world. *
* *
* INPUT: pos -- The position to place the building on the map. *
* *
* dir (optional) -- not used for this class *
* *
* OUTPUT: bool; Was the unlimbo successful? *
* *
* WARNINGS: The unlimbo operation might not be successful if the *
* building could not be placed at the location specified. *
* *
* HISTORY: *
* 04/16/1994 JLB : Created. *
* 06/07/1994 JLB : Matches virtual function format for base class. *
* 05/09/1995 JLB : Handles wall placement. *
* 06/18/1995 JLB : Checks for wall legality before placing down. *
*=============================================================================================*/
bool BuildingClass::Unlimbo(COORDINATE coord, DirType dir)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
/*
** If this is a wall type building, then it never gets unlimboed. Instead, it gets
** converted to an overlay type.
*/
if (Class->IsWall) {
if (Can_Enter_Cell(Coord_Cell(coord), FACING_NONE) == MOVE_OK) {
OverlayType otype = OVERLAY_NONE;
switch (Class->Type) {
case STRUCT_SANDBAG_WALL:
otype = OVERLAY_SANDBAG_WALL;
break;
case STRUCT_CYCLONE_WALL:
otype = OVERLAY_CYCLONE_WALL;
break;
case STRUCT_BRICK_WALL:
otype = OVERLAY_BRICK_WALL;
break;
case STRUCT_BARBWIRE_WALL:
otype = OVERLAY_BARBWIRE_WALL;
break;
case STRUCT_WOOD_WALL:
otype = OVERLAY_WOOD_WALL;
break;
case STRUCT_FENCE:
otype = OVERLAY_FENCE;
break;
default:
otype = OVERLAY_NONE;
break;
}
if (otype != OVERLAY_NONE) {
ObjectClass * o = OverlayTypeClass::As_Reference(otype).Create_One_Of(House);
if (o && o->Unlimbo(coord)) {
Map[coord].Owner = House->Class->House;
Transmit_Message(RADIO_OVER_OUT);
Map.Sight_From(Coord_Cell(coord), Class->SightRange, House);
delete this;
return(true);
}
}
}
return(false);
}
/*
** Normal building unlimbo process.
*/
if (TechnoClass::Unlimbo(coord, dir)) {
/*
** Ensure that the owning house knows about the
** new object.
*/
House->BScan |= (1L << Class->Type);
House->ActiveBScan |= (1L << Class->Type);
/*
** Recalculate the center point of the house's base.
*/
House->Recalc_Center();
/*
** Update the total factory type, assuming this building has a factory.
*/
House->Active_Add(this);
/*
** Possibly the sidebar will be affected by this addition.
*/
House->IsRecalcNeeded = true;
LastStrength = 0;
// Changes to support client/server multiplayer. ST - 8/2/2019 2:36PM
//if ((!IsDiscoveredByPlayer && Map[coord].IsVisible) || Session.Type != GAME_NORMAL) {
if ((!Is_Discovered_By_Player(House) && Map[coord].Is_Visible(House)) || Session.Type != GAME_NORMAL) {
if (House->IsHuman) {
//Revealed(PlayerPtr);
Revealed(House);
}
}
if (!House->IsHuman) {
Revealed(House);
}
// Changes to support client/server multiplayer. ST - 8/2/2019 2:36PM
//if (IsOwnedByPlayer) {
if (Is_Owned_By_Player()) {
Map.PowerClass::IsToRedraw = true;
Map.Flag_To_Redraw(false);
}
if ((Class->Ownable & (HOUSEF_GOOD | HOUSEF_BAD)) != (HOUSEF_GOOD | HOUSEF_BAD)) {
if (Class->Ownable & HOUSEF_GOOD) {
ActLike = HOUSE_GREECE;
} else {
ActLike = HOUSE_USSR;
}
}
return(true);
}
return(false);
}
/***********************************************************************************************
* BuildingClass::Take_Damage -- Inflicts damage points upon a building. *
* *
* This routine will inflict damage points upon the specified building. *
* It will handle the damage animation and building destruction. Use *
* this routine whenever a building is attacked. *
* *
* INPUT: damage -- Amount of damage to inflict. *
* *
* distance -- The distance from the damage center point to the object's center point.*
* *
* warhead -- The kind of damage to inflict. *
* *
* source -- The source of the damage. This is used to change targeting. *
* *
* forced -- Is the damage forced upon the object regardless of whether it *
* is normally immune? *
* *
* OUTPUT: true/false; Was the building destroyed? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/21/1991 : Created. *
* 04/15/1994 JLB : Converted to member function. *
* 04/16/1994 JLB : Added warhead modifier to damage. *
* 06/03/1994 JLB : Added source of damage as target value. *
* 06/20/1994 JLB : Source is a base class pointer. *
* 11/22/1994 JLB : Shares base damage handler for techno objects. *
* 07/15/1995 JLB : Power ratio gets adjusted. *
*=============================================================================================*/
ResultType BuildingClass::Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source, bool forced)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
ResultType res = RESULT_NONE;
int shakes;
if (this != source /*&& !Class->IsInsignificant*/) {
if (source) {
House->LATime = Frame;
House->LAType = source->What_Am_I();
House->LAZone = House->Which_Zone(this);
House->LAEnemy = source->Owner();
if (!House->Is_Ally(source)) {
House->Enemy = source->Owner();
}
Base_Is_Attacked(source);
}
short const * offset = Occupy_List();
/*
** Memorize who they used to be in radio contact with.
*/
TechnoClass *tech = Contact_With_Whom();
/*
** Perform the low level damage assessment.
*/
res = TechnoClass::Take_Damage(damage, distance, warhead, source, forced);
switch (res) {
case RESULT_DESTROYED:
/*
** Add the building to the base prebuild list if allowed. This will force
** the computer to rebuild this structure if it can.
*/
if (IsToRebuild && Class->Level != -1 && Base.House == House->Class->House && Base.Get_Node(this) == 0) {
// if (IsToRebuild && Class->IsBuildable && Base.House == House->Class->House && Base.Get_Node(this) == 0) {
Base.Nodes.Add(BaseNodeClass(Class->Type, Coord_Cell(Coord)));
}
/*
** Destroy all attached objects.
*/
while (Attached_Object()) {
FootClass * obj = Detach_Object();
Detach_All(true);
delete obj;
}
/*
** If we were in contact with a landed plane, blow the plane up too.
*/
if (tech && tech->IsActive && tech->What_Am_I() == RTTI_AIRCRAFT && ((AircraftClass *)tech)->Class->IsFixedWing && ((AircraftClass *)tech)->In_Which_Layer() == LAYER_GROUND) {
int damage = 500;
tech->Take_Damage(damage, 0, WARHEAD_AP, source, forced);
}
Sound_Effect(VOC_KABOOM22, Coord);
while (*offset != REFRESH_EOL) {
CELL cell = Coord_Cell(Coord) + *offset++;
/*
** If the building is destroyed, then lots of
** explosions occur.
*/
new SmudgeClass(Random_Pick(SMUDGE_CRATER1, SMUDGE_CRATER6), Cell_Coord(cell));
if (Percent_Chance(50)) {
new AnimClass(ANIM_FIRE_SMALL, Coord_Scatter(Cell_Coord(cell), 0x0080), Random_Pick(0, 7), Random_Pick(1, 3));
if (Percent_Chance(50)) {
new AnimClass(ANIM_FIRE_MED, Coord_Scatter(Cell_Coord(cell), 0x0040), Random_Pick(0, 7), Random_Pick(1, 3));
}
}
new AnimClass(ANIM_FBALL1, Coord_Scatter(Cell_Coord(cell), 0x0040), Random_Pick(0, 3));
}
shakes = Class->Cost_Of() / 400;
if (shakes) {
Shake_The_Screen(shakes, Owner());
if (source && Owner() != source->Owner()) {
Shake_The_Screen(shakes, source->Owner());
}
}
Sound_Effect(VOC_CRUMBLE, Coord);
if (Mission == MISSION_DECONSTRUCTION) {
CountDown = 0;
Set_Rate(0);
} else {
CountDown = 8;
}
/*
** If it is in radio contact and the object seems to be attached, then tell
** it to run away.
*/
if (In_Radio_Contact() && Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER) {
Transmit_Message(RADIO_RUN_AWAY);
}
/*
** A force destruction will not generate survivors.
*/
if (forced || *this == STRUCT_KENNEL) {
IsSurvivorless = true;
}
/*
** Destruction of a radar facility or advanced communications
** center will cause the spiedby field to change...
*/
if (SpiedBy) {
SpiedBy = 0;
StructType struc = *this;
if (struc == STRUCT_RADAR /* || struc == STRUCT_EYE */) {
Update_Radar_Spied();
}
}
/*
** Destruction of a gap generator will cause the cells it affects
** to stop being jammed.
*/
if (*this == STRUCT_GAP) {
Remove_Gap_Effect();
}
/*
** Destruction of a shipyard or sub pen may cause attached ships
** who are repairing themselves to discontinue repairs.
*/
if (*this == STRUCT_SHIP_YARD || *this == STRUCT_SUB_PEN) {
for (int index = 0; index < Vessels.Count(); index++) {
VesselClass *obj = Vessels.Ptr(index);
if (obj && !obj->IsInLimbo && obj->House == House) {
if (obj->IsSelfRepairing) {
if (::Distance(Center_Coord(), obj->Center_Coord()) < 0x0200) {
obj->IsSelfRepairing = false;
obj->IsToSelfRepair = false;
}
}
}
}
}
/*
** Destruction of a barrel will cause the surrounding squares to
** be hit with damage.
*/
if (*this == STRUCT_BARREL || *this == STRUCT_BARREL3) {
COORDINATE center = Center_Coord();
CELL cellcenter = Coord_Cell(center);
BulletClass * bullet;
bullet = new BulletClass(BULLET_INVISIBLE, ::As_Target(Adjacent_Cell(cellcenter, FACING_N)), 0, 200, WARHEAD_FIRE, MPH_MEDIUM_FAST);
if (bullet) {
bullet->Unlimbo(center, DIR_N);
}
bullet = new BulletClass(BULLET_INVISIBLE, ::As_Target(Adjacent_Cell(cellcenter, FACING_E)), 0, 200, WARHEAD_FIRE, MPH_MEDIUM_FAST);
if (bullet) {
bullet->Unlimbo(center, DIR_E);
}
bullet = new BulletClass(BULLET_INVISIBLE, ::As_Target(Adjacent_Cell(cellcenter, FACING_S)), 0, 200, WARHEAD_FIRE, MPH_MEDIUM_FAST);
if (bullet) {
bullet->Unlimbo(center, DIR_S);
}
bullet = new BulletClass(BULLET_INVISIBLE, ::As_Target(Adjacent_Cell(cellcenter, FACING_W)), 0, 200, WARHEAD_FIRE, MPH_MEDIUM_FAST);
if (bullet) {
bullet->Unlimbo(center, DIR_W);
}
}
if (House) {
House->Check_Pertinent_Structures();
}
break;
case RESULT_HALF:
if (*this == STRUCT_PUMP) {
AnimClass * anim = new AnimClass(ANIM_OILFIELD_BURN, Coord_Add(Coord, 0x00400130L), 1);
if (anim) {
anim->Attach_To(this);
}
}
// Fall into next case.
case RESULT_MAJOR:
Sound_Effect(VOC_KABOOM1, Coord);
while (*offset != REFRESH_EOL) {
CELL cell = Coord_Cell(Coord) + *offset++;
AnimClass * anim = NULL;
/*
** Show pieces of fire to indicate that a significant change in
** damage level has occurred.
*/
if (warhead == WARHEAD_FIRE) {
switch (Random_Pick(0, 5+Class->Width()+Class->Height())) {
case 0:
break;
case 1:
case 2:
case 3:
case 4:
case 5:
anim = new AnimClass(ANIM_ON_FIRE_SMALL, Coord_Scatter(Cell_Coord(cell), 0x0060), 0, Random_Pick(1, 3));
break;
case 6:
case 7:
case 8:
anim = new AnimClass(ANIM_ON_FIRE_MED, Coord_Scatter(Cell_Coord(cell), 0x0060), 0, Random_Pick(1, 3));
break;
case 9:
anim = new AnimClass(ANIM_ON_FIRE_BIG, Coord_Scatter(Cell_Coord(cell), 0x0060), 0, 1);
break;
default:
break;
}
} else {
if (Percent_Chance(50)) {
/*
** Building may catch on fire, but only if it wasn't a
** renovator that caused the damage.
*/
if (source == NULL || source->What_Am_I() != RTTI_INFANTRY || *(InfantryClass *)source != INFANTRY_RENOVATOR) {
anim = new AnimClass(ANIM_FIRE_SMALL, Coord_Scatter(Cell_Coord(cell), 0x0060), Random_Pick(0, 7), Random_Pick(1, 3));
}
}
}
/*
** If the animation was created, then attach it to the building.
*/
if (anim) {
anim->Attach_To(this);
}
}
break;
case RESULT_NONE:
break;
case RESULT_LIGHT:
break;
}
if (source && res != RESULT_NONE) {
/*
** If any damage occurred, then inform the house of this fact. If it is the player's
** house, it might announce this fact.
*/
if (!Class->IsInsignificant) {
House->Attacked(this);
}
/*
** Save the type of the house that's doing the damage, so if the building burns
** to death credit can still be given for the kill
*/
WhoLastHurtMe = source->Owner();
/*
** When certain buildings are hit, they "snap out of it" and
** return fire if they are able and allowed.
*/
if (*this != STRUCT_SAM && *this != STRUCT_AAGUN &&
!House->Is_Ally(source) &&
Class->PrimaryWeapon != NULL &&
(!Target_Legal(TarCom) || !In_Range(TarCom))) {
if (source->What_Am_I() != RTTI_AIRCRAFT && (!House->IsHuman || Rule.IsSmartDefense)) {
Assign_Target(source->As_Target());
} else {
/*
** Generate a random rotation effect since there is nothing else that this
** building can do.
*/
if (!PrimaryFacing.Is_Rotating()) {
PrimaryFacing.Set_Desired(Random_Pick(DIR_N, DIR_MAX));
}
}
}
}
}
return(res);
}
/***********************************************************************************************
* BuildingClass::new -- Allocates a building object from building pool. *
* *
* This routine will allocate a building slot from the building alloc *
* system. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with a pointer to the allocated building. If NULL is *
* returned, then this indicates a failure to allocate. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 04/11/1994 JLB : Created. *
* 04/21/1994 JLB : Converted to operator new. *
* 05/17/1994 JLB : Revamped allocation scheme *
* 07/29/1994 JLB : Simplified. *
*=============================================================================================*/
void * BuildingClass::operator new(size_t )
{
void * ptr = Buildings.Allocate();
if (ptr) {
((BuildingClass *)ptr)->Set_Active();
}
return(ptr);
}
/***********************************************************************************************
* BuildingClass::delete -- Deallocates building object. *
* *
* This is the memory deallocation operation for a building object. *
* Since buildings are allocated out of a fixed memory block, all that *
* is needed is to flag the unit as inactive. *
* *
* INPUT: ptr -- Pointer to building to deallocate. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 04/21/1994 JLB : Created. *
*=============================================================================================*/
void BuildingClass::operator delete(void *ptr)
{
if (ptr) {
((BuildingClass *)ptr)->IsActive = false;
}
Buildings.Free((BuildingClass *)ptr);
}
/***********************************************************************************************
* BuildingClass::BuildingClass -- Constructor for buildings. *
* *
* This routine inserts a building into the object tracking system. *
* It is placed into a limbo state unless a location is provided for *
* it to unlimbo at. *
* *
* INPUT: type -- The structure type to make this object. *
* *
* house -- The owner of this building. *
* *
* pos -- The position to unlimbo the building. If -1 is *
* specified, then the building remains in a limbo *
* state. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 04/21/1994 JLB : Created. *
* 08/07/1995 JLB : Fixed act like value to match expected value. *
*=============================================================================================*/
BuildingClass::BuildingClass(StructType type, HousesType house) :
TechnoClass(RTTI_BUILDING, Buildings.ID(this), house),
Class(BuildingTypes.Ptr((int)type)),
Factory(0),
ActLike(House->ActLike),
IsToRebuild(false),
IsToRepair(false),
IsAllowedToSell(true),
IsReadyToCommence(false),
IsRepairing(false),
IsWrenchVisible(false),
IsGoingToBlow(false),
IsSurvivorless(false),
IsCharging(false),
IsCharged(false),
IsCaptured(false),
IsJamming(false),
IsJammed(false),
HasFired(false),
HasOpened(false),
CountDown(0),
BState(BSTATE_NONE),
QueueBState(BSTATE_NONE),
WhoLastHurtMe(house),
WhomToRepay(TARGET_NONE),
AnimToTrack(TARGET_NONE),
LastStrength(0),
PlacementDelay(0)
{
House->Tracking_Add(this);
IsSecondShot = !Class->Is_Two_Shooter();
Strength = Class->MaxStrength;
Ammo = Class->MaxAmmo;
/*
** If the building could never be built, then it can never be sold either. This
** is due to the lack of buildup animation.
*/
if (Class->Get_Buildup_Data() != NULL) {
// if (!Class->IsBuildable) {
IsAllowedToSell = false;
}
// if (Session.Type == GAME_INTERNET) {
// House->BuildingTotals->Increment_Unit_Total( (int) type);
// }
}
/***********************************************************************************************
* BuildingClass::~BuildingClass -- Destructor for building type objects. *
* *
* This destructor for building objects will put the building in limbo if possible. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 01/18/1995 JLB : Created. *
*=============================================================================================*/
BuildingClass::~BuildingClass(void)
{
if (GameActive && Class) {
if (House) {
House->Tracking_Remove(this);
}
BuildingClass::Limbo();
}
Class = 0;
delete (FactoryClass *)Factory;
Factory = 0;
ID = -1;
}
/***********************************************************************************************
* BuildingClass::Drop_Debris -- Drops rubble when building is destroyed. *
* *
* This routine is called when a building is destroyed. It handles *
* placing the rubble down. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/14/1994 JLB : Created. *
* 06/13/1995 JLB : Added smoke and normal infantry survivor possibility. *
* 07/16/1995 JLB : Survival rate depends on if captured or sabotaged. *
*=============================================================================================*/
void BuildingClass::Drop_Debris(TARGET source)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
CELL const * offset;
CELL cell;
/*
** Generate random survivors from the destroyed building.
*/
cell = Coord_Cell(Coord);
offset = Occupy_List();
int odds = 2;
if (Target_Legal(WhomToRepay)) odds -= 1;
if (IsCaptured) odds += 6;
int count = How_Many_Survivors();
while (*offset != REFRESH_EOL) {
CELL newcell;
newcell = cell + *offset++;
CellClass const * cellptr = &Map[newcell];
/*
** Infantry could run out of a destroyed building.
*/
if (!House->IsToDie && count > 0) {
InfantryClass * i = NULL;
if (Random_Pick(0, odds) == 1) {
i = NULL;
InfantryType typ = Crew_Type();
if (typ != INFANTRY_NONE) i = new InfantryClass(typ, House->Class->House);
if (i != NULL) {
if (Class->Get_Buildup_Data() != NULL && i->Class->IsNominal) i->IsTechnician = true;
ScenarioInit++;
if (i->Unlimbo(Cell_Coord(newcell), DIR_N)) {
count--;
i->Strength = Random_Pick(5, (int)i->Class->MaxStrength);
i->Scatter(0, true);
if (source != TARGET_NONE && !House->Is_Ally(As_Object(source))) {
i->Assign_Mission(MISSION_ATTACK);
i->Assign_Target(source);
} else {
if (House->IsHuman) {
i->Assign_Mission(MISSION_GUARD);
} else {
i->Assign_Mission(MISSION_HUNT);
}
}
} else {
delete i;
}
ScenarioInit--;
}
}
}
/*
** Smoke and fire only appear on terrestrail cells. They should not appear on
** rivers, clifs, or water cells.
*/
if (cellptr->Is_Clear_To_Move(SPEED_TRACK, true, true)) {
/*
** Possibly add some smoke rising from the ashes of the building.
*/
switch (Random_Pick(0, 5)) {
case 0:
case 1:
case 2:
new AnimClass(ANIM_SMOKE_M, Coord_Scatter(Cell_Coord(newcell), 0x0050, false), Random_Pick(0, 5), Random_Pick(1, 2));
break;
default:
break;
}
/*
** The building always scars the ground in some fashion.
*/
if (Percent_Chance(25)) {
new SmudgeClass(Random_Pick(SMUDGE_SCORCH1, SMUDGE_SCORCH6), Cell_Coord(newcell));
} else {
new SmudgeClass(Random_Pick(SMUDGE_CRATER1, SMUDGE_CRATER6), Coord_Scatter(Cell_Coord(newcell), 0x0080, false));
}
}
}
}
/***********************************************************************************************
* BuildingClass::Active_Click_With -- Handles clicking on the map while the building is selected.*
* *
* This interface routine handles when the player clicks on the map while this building *
* is currently selected. This is used to assign an override target to a turret or *
* guard tower. *
* *
* INPUT: target -- The target that was clicked upon. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/28/1994 JLB : Created. *
*=============================================================================================*/
void BuildingClass::Active_Click_With(ActionType action, ObjectClass * object)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (action == ACTION_ATTACK && object != NULL) {
Player_Assign_Mission(MISSION_ATTACK, object->As_Target());
}
if (action == ACTION_TOGGLE_PRIMARY && Class->Is_Factory()) {
OutList.Add(EventClass(EventClass::PRIMARY, TargetClass(this)));
}
}
/***********************************************************************************************
* BuildingClass::Active_Click_With -- Handles cell selection for buildings. *
* *
* This routine really only serves one purpose -- to allow targeting of the ground for *
* buildings that are equipped with weapons. *
* *
* INPUT: action -- The requested action to perform. *
* *
* cell -- The cell location to perform the action upon. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/04/1995 JLB : Created. *
* 10/04/1995 JLB : Handles construction yard undeploy to move logic. *
*=============================================================================================*/
void BuildingClass::Active_Click_With(ActionType action, CELL cell)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (action == ACTION_ATTACK) {
Player_Assign_Mission(MISSION_ATTACK, ::As_Target(cell));
}
if (action == ACTION_MOVE && *this == STRUCT_CONST) {
OutList.Add(EventClass(EventClass::ARCHIVE, TargetClass(this), TargetClass(::As_Target(cell))));
OutList.Add(EventClass(EventClass::SELL, TargetClass(this)));
COORDINATE coord = Map.Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y());
OutList.Add(EventClass(ANIM_MOVE_FLASH, PlayerPtr->Class->House, coord, 1 << PlayerPtr->Class->House));
}
}
/***********************************************************************************************
* BuildingClass::Assign_Target -- Assigns a target to the building. *
* *
* Assigning of a target to a building makes sense if the building is one that can attack. *
* This routine would be used to assign the attack target to a turret or guard tower. *
* *
* INPUT: target -- The target that was clicked on while this building was selected. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/28/1994 JLB : Created. *
* 11/02/1994 JLB : Checks for range before assigning target. *
*=============================================================================================*/
void BuildingClass::Assign_Target(TARGET target)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (*this != STRUCT_SAM && *this != STRUCT_AAGUN && !In_Range(target, 0)) {
target = TARGET_NONE;
}
TechnoClass::Assign_Target(target);
}
/***********************************************************************************************
* BuildingClass::Init -- Initialize the building system to an empty null state. *
* *
* This routine initializes the building system in preparation for a scenario load. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/19/1994 JLB : Created. *
*=============================================================================================*/
void BuildingClass::Init(void)
{
Buildings.Free_All();
}
/***********************************************************************************************
* BuildingClass::Exit_Object -- Initiates an object to leave the building. *
* *
* This function is used to cause an object to exit the building. It is called when a *
* factory produces a vehicle or other mobile object and that object needs to exit the *
* building to join the ranks of a regular unit. Typically, the object is placed down on *
* the map such that it overlaps the building and then it is given a movement order so that *
* it will move to an adjacent free cell. *
* *
* INPUT: base -- Pointer to the object that is to exit the building. *
* *
* OUTPUT: Returns the success rating for the exit attempt; *
* 0 = complete failure (refund money please) *
* 1 = temporarily prevented (try again later please) *
* 2 = successful *
* *
* WARNINGS: The building is placed in radio contact with the object. The object is in a *
* tethered condition. This condition will be automatically broken when the *
* object reaches the adjacent square. *
* *
* HISTORY: *
* 11/28/1994 JLB : Created. *
* 04/10/1995 JLB : Handles building production by computer. *
* 06/17/1995 JLB : Handles refinery exit. *
*=============================================================================================*/
int BuildingClass::Exit_Object(TechnoClass * base)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (!base) return(0);
TechnoTypeClass const * ttype = (TechnoTypeClass const *)&base->Class_Of();
/*
** A unit exiting a building is always considered to be "locked". That means, it
** will be considered as to have legally entered the visible map domain.
*/
base->IsLocked = true;
/*
** Find a good cell to unload the object to. The object, probably a vehicle
** will drive/walk to the adjacent free cell.
*/
CELL cell = 0;
switch (base->What_Am_I()) {
case RTTI_AIRCRAFT:
if (!In_Radio_Contact()) {
AircraftClass * air = (AircraftClass *)base;
air->Height = 0;
ScenarioInit++;
if (air->Unlimbo(Docking_Coord(), air->Pose_Dir())) {
Transmit_Message(RADIO_HELLO, air);
Transmit_Message(RADIO_TETHER);
ScenarioInit--;
return(2);
}
ScenarioInit--;
} else {
AircraftClass * air = (AircraftClass *)base;
if (Cell_X(Coord_Cell(Center_Coord())) - Map.MapCellX < Map.MapCellWidth/2) {
cell = XY_Cell(Map.MapCellX-1, Random_Pick(0, Map.MapCellHeight-1)+Map.MapCellY);
} else {
cell = XY_Cell(Map.MapCellX+Map.MapCellWidth, Random_Pick(0, Map.MapCellHeight-1)+Map.MapCellY);
}
ScenarioInit++;
if (air->Unlimbo(Cell_Coord(cell), DIR_N)) {
//BG air->Assign_Destination(::As_Target(Nearby_Location(air)));
/*BG*/ air->Assign_Destination(::As_Target(air->Nearby_Location(this)));
air->Assign_Mission(MISSION_MOVE);
ScenarioInit--;
return(2);
}
ScenarioInit--;
}
break;
case RTTI_VESSEL:
switch (Class->Type) {
case STRUCT_SUB_PEN:
case STRUCT_SHIP_YARD:
ScenarioInit++;
cell = Find_Exit_Cell(base);
if (cell != 0 && base->Unlimbo(Cell_Coord(cell), Direction(Cell_Coord(cell)))) {
base->Assign_Mission(MISSION_GUARD);
ScenarioInit--;
return(2);
}
ScenarioInit--;
break;
default:
break;
}
break;
case RTTI_INFANTRY:
case RTTI_UNIT:
switch (Class->Type) {
case STRUCT_REFINERY:
if (base->What_Am_I() == RTTI_UNIT) {
cell = Coord_Cell(Center_Coord());
UnitClass * unit = (UnitClass *)base;
cell = Adjacent_Cell(cell, FACING_SW);
ScenarioInit++;
if (unit->Unlimbo(Cell_Coord(Adjacent_Cell(cell, DIR_S)), DIR_SW_X2)) {
unit->PrimaryFacing = DIR_S;
unit->Assign_Mission(MISSION_HARVEST);
}
ScenarioInit--;
} else {
base->Scatter(0, true);
}
break;
case STRUCT_WEAP:
if (Mission == MISSION_UNLOAD) {
for(int index = 0; index < Buildings.Count(); index++) {
BuildingClass *bldg = Buildings.Ptr(index);
if (bldg->Owner() == Owner() && *bldg == STRUCT_WEAP && bldg != this && bldg->Mission == MISSION_GUARD && !bldg->Factory) {
FactoryClass * temp = Factory;
bldg->Factory = Factory;
Factory = 0;
int retval = (bldg->Exit_Object(base));
bldg->Factory = 0;
Factory = temp;
return(retval);
}
}
return(1); // fail while we're still unloading previous
}
ScenarioInit++;
if (base->Unlimbo(Exit_Coord(), DIR_S)) {
base->Mark(MARK_UP);
base->Coord = Exit_Coord();
base->Mark(MARK_DOWN);
Transmit_Message(RADIO_HELLO, base);
Transmit_Message(RADIO_TETHER);
Assign_Mission(MISSION_UNLOAD);
ScenarioInit--;
return(2);
}
ScenarioInit--;
break;
case STRUCT_BARRACKS:
case STRUCT_TENT:
case STRUCT_KENNEL:
cell = Find_Exit_Cell(base);
if (cell != 0) {
DirType dir = Direction(cell);
COORDINATE start = Exit_Coord();
ScenarioInit++;
if (base->Unlimbo(start, dir)) {
base->Assign_Mission(MISSION_MOVE);
/*
** When disembarking from a transport then guard an area around the
** center of the base.
*/
base->Assign_Destination(::As_Target(cell));
if (House->IQ >= Rule.IQGuardArea) {
base->Assign_Mission(MISSION_GUARD_AREA);
base->ArchiveTarget = ::As_Target(House->Where_To_Go((FootClass *)base));
}
/*
** Establish radio contact so unload coordination can occur. This
** radio contact should always succeed.
*/
if (Transmit_Message(RADIO_HELLO, base) == RADIO_ROGER) {
Transmit_Message(RADIO_UNLOAD);
}
ScenarioInit--;
return(2);
}
ScenarioInit--;
}
break;
default:
cell = Find_Exit_Cell(base);
if (cell != 0) {
DirType dir = Direction(cell);
COORDINATE start = Exit_Coord();
ScenarioInit++;
if (base->Unlimbo(start, dir)) {
base->Assign_Mission(MISSION_MOVE);
/*
** When disembarking from a transport then guard an area around the
** center of the base.
*/
base->Assign_Destination(::As_Target(cell));
if (House->IQ >= Rule.IQGuardArea) {
base->Assign_Mission(MISSION_GUARD_AREA);
base->ArchiveTarget = ::As_Target(House->Where_To_Go((FootClass *)base));
}
ScenarioInit--;
return(2);
}
ScenarioInit--;
}
break;
}
break;
case RTTI_BUILDING:
if (!House->IsHuman) {
/*
** Find the next available spot to place this newly created building. If the
** building could be placed at the desired location, fine. If not, then this
** routine will return failure. The calling routine will probably abandon this
** building in preference to building another.
*/
BaseNodeClass * node = Base.Next_Buildable(((BuildingClass *)base)->Class->Type);
COORDINATE coord = 0;
if (node) {
coord = Cell_Coord(node->Cell);
} else {
/*
** Find a suitable new spot to place.
*/
coord = House->Find_Build_Location((BuildingClass *)base);
}
if (coord) {
if (Flush_For_Placement(base, Coord_Cell(coord))) {
return(1);
}
if (base->Unlimbo(coord)) {
if (node && ((BuildingClass *)base)->Class->Type == House->BuildStructure) {
House->BuildStructure = STRUCT_NONE;
}
return(2);
}
}
}
break;
default:
break;
}
/*
** Failure to exit the object results in a false return value.
*/
return(0);
}
/***********************************************************************************************
* BuildingClass::Update_Buildables -- Informs sidebar of additional construction options. *
* *
* This routine will tell the sidebar of objects that can be built. The function is called *
* whenever a building matures. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 11/11/1994 JLB : Created. *
* 12/23/1994 JLB : Only updates for PLAYER buildings. *
*=============================================================================================*/
void BuildingClass::Update_Buildables(void)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
/*
** Only do this for real human players. ST - 3/22/2019 1:38PM
*/
if (PlayerPtr != House) {
if (Session.Type != GAME_GLYPHX_MULTIPLAYER || House->IsHuman == false) {
return;
}
}
bool buildable_via_capture = (IsCaptured && ActLike != House->ActLike) ? true : false;
if (!IsInLimbo && Is_Discovered_By_Player()) {
switch (Class->ToBuild) {
int i;
int u;
int f;
int a;
int v;
case RTTI_VESSELTYPE:
for (v = VESSEL_FIRST; v < VESSEL_COUNT; v++) {
if (PlayerPtr->Can_Build(&VesselTypeClass::As_Reference((VesselType)v), ActLike)) {
if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
Sidebar_Glyphx_Add(RTTI_VESSELTYPE, v, House, buildable_via_capture);
} else {
Map.Add(RTTI_VESSELTYPE, v, buildable_via_capture);
}
}
}
break;
case RTTI_BUILDINGTYPE:
for (i = STRUCT_FIRST; i < STRUCT_COUNT; i++) {
if (PlayerPtr->Can_Build(&BuildingTypeClass::As_Reference((StructType)i), ActLike)) {
if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
Sidebar_Glyphx_Add(RTTI_BUILDINGTYPE, i, House, buildable_via_capture);
} else {
Map.Add(RTTI_BUILDINGTYPE, i, buildable_via_capture);
}
}
}
break;
case RTTI_UNITTYPE:
for (u = UNIT_FIRST; u < UNIT_COUNT; u++) {
if (PlayerPtr->Can_Build(&UnitTypeClass::As_Reference((UnitType)u), ActLike)) {
if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
Sidebar_Glyphx_Add(RTTI_UNITTYPE, u, House, buildable_via_capture);
} else {
Map.Add(RTTI_UNITTYPE, u, buildable_via_capture);
}
}
}
break;
case RTTI_INFANTRYTYPE:
for (f = INFANTRY_FIRST; f < INFANTRY_COUNT; f++) {
if (PlayerPtr->Can_Build(&InfantryTypeClass::As_Reference((InfantryType)f), ActLike)) {
if (InfantryTypeClass::As_Reference((InfantryType)f).IsDog) {
if (*this == STRUCT_KENNEL) {
if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
Sidebar_Glyphx_Add(RTTI_INFANTRYTYPE, f, House, buildable_via_capture);
} else {
Map.Add(RTTI_INFANTRYTYPE, f, buildable_via_capture);
}
}
} else {
if (*this != STRUCT_KENNEL) {
if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
Sidebar_Glyphx_Add(RTTI_INFANTRYTYPE, f, House, buildable_via_capture);
} else {
Map.Add(RTTI_INFANTRYTYPE, f, buildable_via_capture);
}
}
}
}
}
break;
case RTTI_AIRCRAFTTYPE:
for (a = AIRCRAFT_FIRST; a < AIRCRAFT_COUNT; a++) {
if (PlayerPtr->Can_Build(&AircraftTypeClass::As_Reference((AircraftType)a), ActLike)) {
if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
Sidebar_Glyphx_Add(RTTI_AIRCRAFTTYPE, a, House, buildable_via_capture);
} else {
Map.Add(RTTI_AIRCRAFTTYPE, a, buildable_via_capture);
}
}
}
break;
default:
break;
}
}
}
#if (0) //Old code for reference. ST - 8/2/2019 2:41PM
/***********************************************************************************************
* BuildingClass::Update_Buildables -- Informs sidebar of additional construction options. *
* *
* This routine will tell the sidebar of objects that can be built. The function is called *
* whenever a building matures. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 11/11/1994 JLB : Created. *
* 12/23/1994 JLB : Only updates for PLAYER buildings. *
*=============================================================================================*/
void BuildingClass::Update_Buildables(void)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (House == PlayerPtr && !IsInLimbo && IsDiscoveredByPlayer) {
switch (Class->ToBuild) {
int i;
int u;
int f;
int a;
int v;
case RTTI_VESSELTYPE:
for (v = VESSEL_FIRST; v < VESSEL_COUNT; v++) {
if (PlayerPtr->Can_Build(&VesselTypeClass::As_Reference((VesselType)v), ActLike)) {
Map.Add(RTTI_VESSELTYPE, v);
}
}
break;
case RTTI_BUILDINGTYPE:
for (i = STRUCT_FIRST; i < STRUCT_COUNT; i++) {
if (PlayerPtr->Can_Build(&BuildingTypeClass::As_Reference((StructType)i), ActLike)) {
Map.Add(RTTI_BUILDINGTYPE, i);
}
}
break;
case RTTI_UNITTYPE:
for (u = UNIT_FIRST; u < UNIT_COUNT; u++) {
if (PlayerPtr->Can_Build(&UnitTypeClass::As_Reference((UnitType)u), ActLike)) {
Map.Add(RTTI_UNITTYPE, u);
}
}
break;
case RTTI_INFANTRYTYPE:
for (f = INFANTRY_FIRST; f < INFANTRY_COUNT; f++) {
if (PlayerPtr->Can_Build(&InfantryTypeClass::As_Reference((InfantryType)f), ActLike)) {
if (InfantryTypeClass::As_Reference((InfantryType)f).IsDog) {
if (*this == STRUCT_KENNEL) {
Map.Add(RTTI_INFANTRYTYPE, f);
}
} else {
if (*this != STRUCT_KENNEL) {
Map.Add(RTTI_INFANTRYTYPE, f);
}
}
}
}
break;
case RTTI_AIRCRAFTTYPE:
for (a = AIRCRAFT_FIRST; a < AIRCRAFT_COUNT; a++) {
if (PlayerPtr->Can_Build(&AircraftTypeClass::As_Reference((AircraftType)a), ActLike)) {
Map.Add(RTTI_AIRCRAFTTYPE, a);
}
}
break;
default:
break;
}
}
}
#endif
/***********************************************************************************************
* BuildingClass::Fire_Out -- Handles when attached animation expires. *
* *
* This routine is used to perform any fixups necessary when the attached animation has *
* terminated. This occurs when the fire & smoke animation that a SAM site produces stops. *
* At that point, normal reload procedures can commence. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 11/30/1994 JLB : Created. *
*=============================================================================================*/
void BuildingClass::Fire_Out(void)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
}
/***********************************************************************************************
* BuildingClass::Limbo -- Handles power adjustment as building goes into limbo. *
* *
* This routine will handle the power adjustments for the associated house when the *
* building goes into limbo. This means that its power drain or production is subtracted *
* from the house accumulated totals. *
* *
* INPUT: none *
* *
* OUTPUT: bool; Was the building limboed? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/24/1994 JLB : Created. *
*=============================================================================================*/
bool BuildingClass::Limbo(void)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (!IsInLimbo) {
/*
** Update the total factory type, assuming this building has a factory.
*/
House->Active_Remove(this);
House->IsRecalcNeeded = true;
House->Recalc_Center();
/*
** Update the power status of the owner's house.
*/
House->Adjust_Power(-Power_Output());
House->Adjust_Drain(-Class->Drain);
House->Adjust_Capacity(-Class->Capacity, true);
if (House == PlayerPtr) {
Map.PowerClass::IsToRedraw = true;
Map.Flag_To_Redraw(false);
}
/*
** This could be a building that builds. If so, then the sidebar may need adjustment.
** Set IsInLimbo to true to "fool" the sidebar into knowing that this building
** isn't available. Set it back to false so the rest of the Limbo code works.
** Otherwise, the sidebar won't properly remove non-available buildables.
*/
// if (IsOwnedByPlayer && !ScenarioInit) {
// IsInLimbo = true;
// Map.Recalc();
// IsInLimbo = false;
// }
}
return(TechnoClass::Limbo());
}
/***********************************************************************************************
* BuildingClass::Turret_Facing -- Fetches the turret facing for this building. *
* *
* This will return the turret facing for this building. Some buildings don't have a *
* visual turret (e.g., pillbox) so they return a turret facing that always faces their *
* current target. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the current facing of the turret. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/29/1996 JLB : Created. *
*=============================================================================================*/
DirType BuildingClass::Turret_Facing(void) const
{
if (!Class->IsTurretEquipped && Target_Legal(TarCom)) {
return(::Direction(Center_Coord(), As_Coord(TarCom)));
}
return(PrimaryFacing.Current());
}
/***********************************************************************************************
* BuildingClass::Greatest_Threat -- Searches for target that building can fire upon. *
* *
* This routine intercepts the Greatest_Threat function so that it can add the ability *
* to search for ground targets, if this isn't a SAM site. *
* *
* INPUT: threat -- The base threat control value. Typically, it might be THREAT_RANGE *
* or THREAT_NORMAL. *
* *
* OUTPUT: Returns with a suitable target. If none could be found, then TARGET_NONE is *
* returned instead. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 01/01/1995 JLB : Created. *
*=============================================================================================*/
TARGET BuildingClass::Greatest_Threat(ThreatType threat) const
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (Class->PrimaryWeapon != NULL) {
threat = threat | Class->PrimaryWeapon->Allowed_Threats();
}
if (Class->SecondaryWeapon != NULL) {
threat = threat | Class->SecondaryWeapon->Allowed_Threats();
}
if (House->IsHuman) {
threat = threat & ~THREAT_BUILDINGS;
}
threat = threat | THREAT_RANGE;
// if (Class->PrimaryWeapon != NULL) {
// if (Class->PrimaryWeapon->Bullet->IsAntiAircraft) {
// threat = threat | THREAT_AIR;
// }
// if (Class->PrimaryWeapon->Bullet->IsAntiGround) {
// threat = threat | THREAT_BUILDINGS|THREAT_INFANTRY|THREAT_BOATS|THREAT_VEHICLES;
// }
// threat = threat | THREAT_RANGE;
// }
return(TechnoClass::Greatest_Threat(threat));
}
/***********************************************************************************************
* BuildingClass::Grand_Opening -- Handles construction completed special operations. *
* *
* This routine is called when construction has finished. Typically, this enables *
* new production options for factories. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 01/08/1995 JLB : Created. *
* 06/13/1995 JLB : Added helipad. *
*=============================================================================================*/
void BuildingClass::Grand_Opening(bool captured)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (!HasOpened || captured) {
HasOpened = true;
/*
** Adjust the owning house according to the power, drain, and Tiberium capacity that
** this building has.
*/
House->Adjust_Drain(Class->Drain);
House->Adjust_Capacity(Class->Capacity);
House->IsRecalcNeeded = true;
/* SPECIAL CASE:
** Tiberium Refineries get a free harvester. Add a harvester to the
** reinforcement list at this time.
*/
if (*this == STRUCT_REFINERY && !ScenarioInit && !captured && !Debug_Map && (!House->IsHuman || PurchasePrice == 0 || PurchasePrice > Class->Raw_Cost())) {
CELL cell = Coord_Cell(Adjacent_Cell(Center_Coord(), DIR_S));
UnitClass * unit = new UnitClass(UNIT_HARVESTER, House->Class->House);
if (unit != NULL) {
/*
** Try to place down the harvesters. If it could not be placed, then try
** to place it in a nearby location.
*/
if (!unit->Unlimbo(Cell_Coord(cell), DIR_W)) {
/*
** Check multiple times for clear locations.
*/
for (int i = 0; i < 10; i++) {
cell = unit->Nearby_Location(this, i);
if (unit->Unlimbo(Cell_Coord(cell), DIR_SW)) {
break;
}
}
/*
** If the harvester could still not be placed, then refund the money
** to the owner and then bail.
*/
if (unit->IsInLimbo) {
House->Refund_Money(unit->Class->Cost_Of());
delete unit;
}
}
} else {
/*
** If the harvester could not be created in the first place, then give
** the full refund price to the owning player.
*/
House->Refund_Money(UnitTypeClass::As_Reference(UNIT_HARVESTER).Cost_Of());
}
}
/*
** Helicopter pads get a free attack helicopter.
*/
if (!Rule.IsSeparate && *this == STRUCT_HELIPAD && !captured) {
ScenarioInit++;
AircraftClass * air = 0;
if (House->ActLike == HOUSE_USSR || House->ActLike == HOUSE_BAD || House->ActLike == HOUSE_UKRAINE) {
air = new AircraftClass(AIRCRAFT_HIND, House->Class->House);
} else {
air = new AircraftClass(AIRCRAFT_LONGBOW, House->Class->House);
}
if (air) {
air->Height = 0;
if (air->Unlimbo(Docking_Coord(), air->Pose_Dir())) {
air->Assign_Mission(MISSION_GUARD);
air->Transmit_Message(RADIO_HELLO, this);
Transmit_Message(RADIO_TETHER);
}
}
ScenarioInit--;
}
}
}
/***********************************************************************************************
* BuildingClass::Repair -- Initiates or terminates the repair process. *
* *
* This routine will start, stop, or toggle the repair process. When a building repairs, it *
* occurs incrementally over time. *
* *
* INPUT: control -- Determines how to control the repair process. *
* 0: Turns repair process off (if it was on). *
* 1: Turns repair process on (if it was off). *
* -1:Toggles repair process to other state. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 01/08/1995 JLB : Created. *
*=============================================================================================*/
void BuildingClass::Repair(int control)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
switch (control) {
case -1:
IsRepairing = (IsRepairing == false);
break;
case 1:
if (IsRepairing) return;
IsRepairing = true;
break;
case 0:
if (!IsRepairing) return;
IsRepairing = false;
break;
default:
break;
}
/*
** At this point, we know that the repair state has changed. Perform
** appropriate action.
*/
VocType soundid = VOC_NONE;
if (IsRepairing) {
if (Strength == Class->MaxStrength) {
soundid = VOC_SCOLD;
} else {
soundid = VOC_CLICK;
if (House->IsPlayerControl) {
Clicked_As_Target(PlayerPtr->Class->House); // 2019/09/20 JAS - Added record of who clicked on the object
}
IsWrenchVisible = true;
}
} else {
soundid = VOC_CLICK;
}
if (House->IsPlayerControl) {
Sound_Effect(soundid, Coord);
}
}
/***********************************************************************************************
* BuildingClass::Sell_Back -- Controls the sell back (demolish) operation. *
* *
* This routine will initiate or stop the sell back process for a building. It is called *
* when the player clicks on a building when the sell mode is active. *
* *
* INPUT: control -- The action to perform. 0 = turn deconstruction off, 1 = deconstruct, *
* -1 = toggle deconstruction state. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/25/1995 JLB : Created. *
*=============================================================================================*/
void BuildingClass::Sell_Back(int control)
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
if (Class->Get_Buildup_Data()) {
bool decon = false;
switch (control) {
case -1:
decon = (Mission != MISSION_DECONSTRUCTION);
break;
case 1:
if (Mission == MISSION_DECONSTRUCTION) return;