12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349 |
- enum ConstructionMaterialType
- {
- MATERIAL_NONE = 0,
- MATERIAL_LOG = 1,
- MATERIAL_WOOD = 2,
- MATERIAL_STAIRS = 3,
- MATERIAL_METAL = 4,
- MATERIAL_WIRE = 5
- }
- class Construction
- {
- static const float REPAIR_MATERIAL_PERCENTAGE = 0.15;
- static const float DECONSTURCT_MATERIAL_LOSS = 0.2;
- protected ref map<string, ref ConstructionPart> m_ConstructionParts; //string - part name; int - 0-not constructed, 1-constructed
- protected BaseBuildingBase m_Parent;
-
- //Debug
- protected Shape m_CollisionBox;
- //Collision detectection
- protected ConstructionBoxTrigger m_ConstructionBoxTrigger;
-
- //============================================
- // Construction
- //============================================
- void Construction( BaseBuildingBase parent )
- {
- m_ConstructionParts = new ref map<string, ref ConstructionPart>;
-
- //set parent object
- SetParent( parent );
- }
-
- void Init()
- {
- UpdateConstructionParts();
- }
-
- //parent
- protected BaseBuildingBase GetParent()
- {
- return m_Parent;
- }
- protected void SetParent( BaseBuildingBase parent )
- {
- m_Parent = parent;
- }
- //============================================
- // Construction process
- //============================================
- //constructed parts
- void AddToConstructedParts( string part_name )
- {
- ConstructionPart constrution_part = GetConstructionPart( part_name );
-
- if ( constrution_part )
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction " + Object.GetDebugName(m_Parent) + " AddToConstructedParts part=" + constrution_part.GetPartName());
- constrution_part.SetBuiltState( true );
- }
- }
-
- void RemoveFromConstructedParts( string part_name )
- {
- ConstructionPart constrution_part = GetConstructionPart( part_name );
-
- if ( constrution_part )
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction " + Object.GetDebugName(m_Parent) + " RemoveFromConstructedParts part=" + constrution_part.GetPartName());
- constrution_part.SetBuiltState( false );
- }
- }
-
- //BuildPart
- void BuildPartServer( notnull Man player, string part_name, int action_id )
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction BuildPartServer | " + part_name);
- //reset DamageZone health
- string damage_zone;
- if (DamageSystem.GetDamageZoneFromComponentName(GetParent(),part_name,damage_zone))
- {
- GetParent().SetAllowDamage(true);
- GetParent().SetHealthMax(damage_zone);
- GetParent().ProcessInvulnerabilityCheck(GetParent().GetInvulnerabilityTypeString());
- }
-
- //on action
- TakeMaterialsServer( part_name );
- //destroy build collision check trigger
- DestroyCollisionTrigger();
- //call event
- GetParent().OnPartBuiltServer( player, part_name, action_id );
- }
-
- //DismantlePart
- void DismantlePartServer( notnull Man player, string part_name, int action_id )
- {
- string damage_zone;
- DamageSystem.GetDamageZoneFromComponentName( GetParent(),part_name,damage_zone );
-
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction DismantlePartServer | " + part_name);
- //receive materials
- ReceiveMaterialsServer( player, part_name, damage_zone );
-
- //drop non-usable materials
- DropNonUsableMaterialsServer( player, part_name );
-
- //call event
- GetParent().OnPartDismantledServer( player, part_name, action_id );
-
- //set DamageZone health to zero (redundant?)
- /*if ( GetParent().GetHealth(damage_zone,"Health") > 0 )
- {
- GetParent().SetHealth(damage_zone,"Health",0);
- }*/
- }
-
- //DestroyPart
- void DestroyPartServer( Man player, string part_name, int action_id, bool destroyed_by_connected_part = false )
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction DestroyPartServer | " + part_name);
- //destroy attached materials (if locked)
- DestroyMaterialsServer( player, part_name );
-
- //drop non-usable materials
- DropNonUsableMaterialsServer( player, part_name );
-
- //call event
- GetParent().OnPartDestroyedServer( player, part_name, action_id, destroyed_by_connected_part );
-
- //set DamageZone health to zero (redundant?)
- string damage_zone;
- if ( DamageSystem.GetDamageZoneFromComponentName(GetParent(),part_name,damage_zone) && GetParent().GetHealth(damage_zone,"Health") > 0 )
- {
- GetParent().SetHealth(damage_zone,"Health",0);
- }
- }
-
- void DestroyConnectedParts(string part_name)
- {
- array<string> parts;// = new array<string>;
- parts = GetValidDepenentPartsArray(part_name);
- if (parts)
- {
- for (int i = 0; i < parts.Count(); i++)
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction DestroyConnectedParts | " + parts.Get(i));
- if (!ExceptionCheck(parts.Get(i)))
- DestroyPartServer(null,parts.Get(i),AT_DESTROY_PART,true);
- }
- }
- }
-
- //!Exceptions from 'dependent parts' hierarchy are handled here
- bool ExceptionCheck(string part_name)
- {
- //gate hack
- ConstructionPart part = GetConstructionPart(part_name);
- if( /*Fence.Cast(m_Parent) && */part.IsGate() )
- {
- if( GetConstructionPart("wall_base_down").IsBuilt() || GetConstructionPart("wall_base_up").IsBuilt() )
- return true;
- }
- return false;
- }
-
- //============================================
- // Update construction
- //============================================
- //update visual
- void InitVisuals()
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction " + Object.GetDebugName(m_Parent) + " InitVisuals");
- for ( int i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- string key = m_ConstructionParts.GetKey( i );
- ConstructionPart value = m_ConstructionParts.Get( key );
-
- if ( value.IsBuilt() )
- {
- ShowConstructionPart( value.GetPartName() );
- }
- }
- }
- void UpdateVisuals()
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction " + Object.GetDebugName(m_Parent) + " UpdateVisuals");
- for ( int i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- string key = m_ConstructionParts.GetKey( i );
- ConstructionPart value = m_ConstructionParts.Get( key );
- if ( value.IsBuilt() )
- {
- ShowConstructionPart( value.GetPartName() );
- }
- else
- {
- HideConstructionPart( value.GetPartName() );
- }
- }
- }
-
- //update physics (only)
- void UpdatePhysics()
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction " + Object.GetDebugName(m_Parent) + " UpdatePhysics m_ConstructionParts=" + m_ConstructionParts.Count());
- for ( int i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- string key = m_ConstructionParts.GetKey( i );
- ConstructionPart value = m_ConstructionParts.Get( key );
-
- if ( value.IsBuilt() )
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] GetType=" + m_Parent.GetType() + " i=" + i + " ADD");
- ShowConstructionPartPhysics( value.GetPartName() );
- }
- else
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] GetType=" + m_Parent.GetType() + " i=" + i + " RM");
- HideConstructionPartPhysics( value.GetPartName() );
- }
- }
- }
-
- void InitBaseState ()
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction " + Object.GetDebugName(m_Parent) + " InitBaseState");
- InitVisuals();
- }
-
- //update construction parts
- protected void UpdateConstructionParts()
- {
- m_ConstructionParts.Clear();
-
- string construction_path = "cfgVehicles" + " " + GetParent().GetType() + " " + "Construction";
-
- if ( GetGame().ConfigIsExisting( construction_path ) )
- {
- //main parts
- for ( int i = 0; i < GetGame().ConfigGetChildrenCount( construction_path ); ++i )
- {
- string main_part_name;
- GetGame().ConfigGetChildName( construction_path, i, main_part_name );
- string part_path = construction_path + " " + main_part_name;
-
- //parts
- for ( int j = 0; j < GetGame().ConfigGetChildrenCount( part_path ); ++j )
- {
- string part_name;
- GetGame().ConfigGetChildName( part_path, j, part_name );
-
- string name;
- GetGame().ConfigGetTextRaw( part_path + " " + part_name + " " + "name", name ); //name
- GetGame().FormatRawConfigStringKeys(name);
- bool show_on_init = GetGame().ConfigGetInt( part_path + " " + part_name + " " + "show_on_init" ); //show on init
- int id = GetGame().ConfigGetInt( part_path + " " + part_name + " " + "id" ); //part id
- bool is_base = GetGame().ConfigGetInt( part_path + " " + part_name + " " + "is_base" ); //is base (part)
- bool is_gate = GetGame().ConfigGetInt( part_path + " " + part_name + " " + "is_gate" ); //is gate (part)
-
- m_ConstructionParts.Insert( part_name, new ConstructionPart( name, part_name, main_part_name, id, show_on_init, is_base, is_gate, GetRequiredParts(part_name,main_part_name) ) );
-
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction name=" + name + " part_name=" + part_name + " show=" + show_on_init + " base=" + is_base + " gate=" + is_gate);
- }
- }
- }
- }
-
- //============================================
- // Parts
- //============================================
- map<string, ref ConstructionPart> GetConstructionParts()
- {
- return m_ConstructionParts;
- }
-
- ConstructionPart GetConstructionPart( string part_name )
- {
- return m_ConstructionParts.Get( part_name );
- }
- //CONSTRUCTION
- /*ConstructionPart GetConstructionPartToBuild( string part_name, ItemBase tool )
- {
- if ( CanBuildPart( part_name, tool ) )
- {
- return GetConstructionPart( part_name );
- }
-
- return NULL;
- }*/
-
- bool CanBuildPart( string part_name, ItemBase tool, bool use_tool )
- {
- if ( !IsPartConstructed( part_name ) && HasRequiredPart( part_name ) && !HasConflictPart( part_name ) && HasMaterials( part_name ) && (!use_tool || CanUseToolToBuildPart( part_name, tool )) && !MaterialIsRuined(part_name) )
- {
- return true;
- }
-
- return false;
- }
-
- bool MaterialIsRuined(string part_name)
- {
- string main_part_name = GetConstructionPart( part_name ).GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "Materials";
-
- if ( GetGame().ConfigIsExisting( cfg_path ) )
- {
- int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
-
- for ( int i = 0; i < child_count; i++ )
- {
- string child_name;
- GetGame().ConfigGetChildName( cfg_path, i, child_name );
-
- //get type, quantity from material
- string config_path;
- string slot_name;
- config_path = cfg_path + " " + child_name + " " + "slot_name";
- GetGame().ConfigGetText( config_path, slot_name );
- config_path = cfg_path + " " + child_name + " " + "quantity";
- float quantity = GetGame().ConfigGetFloat( config_path );
- config_path = cfg_path + " " + child_name + " " + "lockable";
- bool lockable = GetGame().ConfigGetInt( config_path );
-
- ItemBase attachment = ItemBase.Cast( GetParent().FindAttachmentBySlotName( slot_name ) );
- if (attachment.IsRuined())
- return true;
- }
- }
- return false;
- }
-
- //Get all construction parts that can be build (at that current time)
- void GetConstructionPartsToBuild( string main_part_name, out array<ConstructionPart> construction_parts, ItemBase tool, out string real_constructionTarget, bool use_tool )
- {
- construction_parts.Clear();
- string part_name;
- ConstructionPart value;
- string key;
-
- for ( int i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- key = m_ConstructionParts.GetKey( i );
- value = m_ConstructionParts.Get( key );
-
- if ( main_part_name == value.GetMainPartName() && CanBuildPart( value.GetPartName(), tool, use_tool ) )
- {
- construction_parts.Insert( value );
- }
-
- if ( main_part_name == value.GetPartName() )
- {
- part_name = value.GetMainPartName();
- }
- }
-
- if( construction_parts.Count() == 0 && part_name )
- {
- for ( i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- key = m_ConstructionParts.GetKey( i );
- value = m_ConstructionParts.Get( key );
-
- if ( part_name == value.GetMainPartName() && CanBuildPart( value.GetPartName(), tool, use_tool ) )
- {
- construction_parts.Insert( value );
- }
- }
- }
- }
-
- //Returns (first found) base construction part
- ConstructionPart GetBaseConstructionPart()
- {
- for ( int i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- string key = m_ConstructionParts.GetKey( i );
- ConstructionPart value = m_ConstructionParts.Get( key );
-
- if ( value.IsBase() )
- {
- return value;
- }
- }
-
- return NULL;
- }
-
- //Returns (first found) gate construction part
- ConstructionPart GetGateConstructionPart()
- {
- for ( int i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- string key = m_ConstructionParts.GetKey( i );
- ConstructionPart value = m_ConstructionParts.Get( key );
-
- if ( value.IsGate() )
- {
- return value;
- }
- }
-
- return NULL;
- }
-
- //checks if construction part has required part already built
- protected bool HasRequiredPart( string part_name )
- {
- string main_part_name = GetConstructionPart( part_name ).GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "required_parts";
-
- ref array<string> required_parts = new array<string>;
- GetGame().ConfigGetTextArray( cfg_path, required_parts );
-
- //check if parts are already built
- for ( int i = 0; i < required_parts.Count(); ++i )
- {
- if ( !IsPartConstructed( required_parts.Get( i ) ) )
- {
- return false;
- }
- //hack - gate
- /*else if (part_name == "wall_gate" && (IsPartConstructed("wall_base_down") || IsPartConstructed("wall_base_up")))
- {
- return true;
- }*/
- }
-
- return true;
- }
-
- //checks if there are conflict parts already built
- protected bool HasConflictPart( string part_name )
- {
- string main_part_name = GetConstructionPart( part_name ).GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "conflicted_parts";
- ref array<string> conflict_parts = new array<string>;
- GetGame().ConfigGetTextArray( cfg_path, conflict_parts );
- //check if parts are already built
- for ( int i = 0; i < conflict_parts.Count(); i++ )
- {
- if ( IsPartConstructed( conflict_parts.Get( i ) ) )
- {
- return true;
- }
- }
-
- return false;
- }
-
- //DECONSTRUCTION
- ConstructionPart GetConstructionPartToDismantle( string part_name, ItemBase tool )
- {
- if ( CanDismantlePart( part_name, tool ) )
- {
- return GetConstructionPart( part_name );
- }
-
- return NULL;
- }
- bool CanDismantlePart( string part_name, ItemBase tool )
- {
- if ( IsPartConstructed( part_name ) && !HasDependentPart( part_name ) && CanUseToolToDismantlePart( part_name, tool ) )
- {
- return true;
- }
-
- return false;
- }
-
- //checks if construction part has dependent part (that is already built) because of which it cannot be deconstruct
- //TODO return whole array of dependent parts/dependencies (one or the other), should be used to eventually destroy all dependent parts instead
- bool HasDependentPart( string part_name )
- {
- for ( int i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- string key = m_ConstructionParts.GetKey( i );
- ConstructionPart construction_part = m_ConstructionParts.Get( key );
-
- if ( construction_part.IsBuilt() )
- {
- if ( construction_part.GetRequiredParts().Find( part_name ) > -1 )
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- //returns array of BUILT parts that directly depend on 'part_name'
- protected array<string> GetValidDepenentPartsArray( string part_name, array<string> recurs = null )
- {
- string name;
- string cfg_path;
- ref array<string> dependent_parts;
-
- for ( int i = 0; i < m_ConstructionParts.Count(); ++i )
- {
- name = m_ConstructionParts.GetKey( i );
- ConstructionPart construction_part = m_ConstructionParts.Get( name );
-
- if ( construction_part.IsBuilt() && construction_part.GetRequiredParts() && construction_part.GetRequiredParts().Find( part_name ) > -1 ) //does the construction part need 'part_name' to exist?
- {
- if ( !dependent_parts )
- {
- dependent_parts = new array<string>;
- }
-
- if ( !recurs || (recurs.Find(name) == -1 ) )
- {
- dependent_parts.Insert(name);
- }
- // Print("part #" + i + ": " + name);
- }
- }
-
- //fully recursive search, disconnected (unnescessary)
- /*if (dependent_parts)
- {
- if ( dependent_parts.Count() > 0 )
- {
- ref array<string> temp = new array<string>;
- for ( i = 0; i < dependent_parts.Count(); i++ )
- {
- temp = GetValidDepenentPartsArray(dependent_parts.Get(i),dependent_parts);
- if (temp.Count() > 0)
- {
- dependent_parts.InsertAll(temp);
- }
- }
- }
- Print("dependent_parts.Count(): " + dependent_parts.Count());
- }*/
- return dependent_parts;
- }
-
- //gets all required parts of a construction part; fills into ConstructionPart on init
- array<string> GetRequiredParts( string part_name, string main_part_name )
- {
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " " + "Construction" + " " + main_part_name + " " + part_name + " " + "required_parts";
- ref array<string> required_parts = new array<string>;
- GetGame().ConfigGetTextArray( cfg_path, required_parts );
-
- return required_parts;
- }
-
- //DESTROY
- ConstructionPart GetConstructionPartToDestroy( string part_name )
- {
- if ( CanDestroyPart( part_name ) )
- {
- return GetConstructionPart( part_name );
- }
-
- return NULL;
- }
- bool CanDestroyPart( string part_name )
- {
- if ( IsPartConstructed( part_name ) && !HasDependentPart( part_name ) )
- {
- return true;
- }
-
- return false;
- }
-
- //CONSTRUCTION PART STATE
- //show/hide construction part
- protected void ShowConstructionPart( string part_name )
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction ShowConstructionPart - " + part_name);
- GetParent().SetAnimationPhase( part_name, 0 );
- }
-
- protected void HideConstructionPart( string part_name )
- {
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] Construction HideConstructionPart - " + part_name);
- GetParent().SetAnimationPhase( part_name, 1 );
- }
-
- //show/hide physics
- void ShowConstructionPartPhysics( string part_name )
- {
- GetParent().AddProxyPhysics( part_name );
- }
-
- void HideConstructionPartPhysics( string part_name )
- {
- GetParent().RemoveProxyPhysics( part_name );
- }
-
- //is part constructed
- bool IsPartConstructed( string part_name )
- {
- ConstructionPart construction_part = GetConstructionPart( part_name );
- if ( construction_part && construction_part.IsBuilt() )
- {
- return true;
- }
-
- return false;
- }
-
- //============================================
- // Materials for construction
- //============================================
- //has materials
- bool HasMaterials( string part_name, bool repairing = false )
- {
- string main_part_name = GetConstructionPart( part_name ).GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "Materials";
-
- if ( GetGame().ConfigIsExisting( cfg_path ) )
- {
- int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
-
- for ( int i = 0; i < child_count; i++ )
- {
- string child_name;
- GetGame().ConfigGetChildName( cfg_path, i, child_name );
-
- //get type, quantity from material
- string material_path;
- string slot_name;
- float quantity;
- material_path = cfg_path + " " + child_name + " " + "slot_name";
- GetGame().ConfigGetText( material_path, slot_name );
- material_path = cfg_path + " " + child_name + " " + "quantity";
- quantity = GetGame().ConfigGetFloat( material_path );
-
- if (repairing)
- {
- quantity *= REPAIR_MATERIAL_PERCENTAGE;
- quantity = Math.Max(Math.Floor(quantity),1);
- }
-
- //if the selected material (or its quantity) is not available
- if ( !HasMaterialWithQuantityAttached( slot_name, quantity ) )
- {
- return false;
- }
- }
- }
-
- return true; //return true even if no material required
- }
-
- //check if parent object has attachment of required quantity attached to it
- protected bool HasMaterialWithQuantityAttached( string slot_name, float quantity )
- {
- ItemBase attachment = ItemBase.Cast( GetParent().FindAttachmentBySlotName( slot_name ) );
-
- if ( attachment && attachment.GetQuantity() >= quantity )
- {
- return true;
- }
-
- return false;
- }
-
- //take materials when building
- void TakeMaterialsServer( string part_name, bool repairing = false )
- {
- string main_part_name = GetConstructionPart( part_name ).GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "Materials";
-
- if ( GetGame().ConfigIsExisting( cfg_path ) )
- {
- int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
-
- for ( int i = 0; i < child_count; i++ )
- {
- string child_name;
- GetGame().ConfigGetChildName( cfg_path, i, child_name );
-
- //get type, quantity from material
- string config_path;
- string slot_name;
- config_path = cfg_path + " " + child_name + " " + "slot_name";
- GetGame().ConfigGetText( config_path, slot_name );
- config_path = cfg_path + " " + child_name + " " + "quantity";
- float quantity = GetGame().ConfigGetFloat( config_path );
- config_path = cfg_path + " " + child_name + " " + "lockable";
- bool lockable = GetGame().ConfigGetInt( config_path );
-
- ItemBase attachment = ItemBase.Cast( GetParent().FindAttachmentBySlotName( slot_name ) );
- if ( lockable )
- {
- //lock attachment
- InventoryLocation inventory_location = new InventoryLocation;
- attachment.GetInventory().GetCurrentInventoryLocation( inventory_location );
-
- GetParent().GetInventory().SetSlotLock( inventory_location.GetSlot(), true );
- }
- else
- {
- if ( quantity > -1 ) //0 - ignores quantity
- {
- if (repairing)
- {
- quantity *= REPAIR_MATERIAL_PERCENTAGE;
- quantity = Math.Max(Math.Floor(quantity),1);
- }
- //subtract quantity
- attachment.AddQuantity( -quantity );
- }
- else //-1 - deletes the object
- {
- GetGame().ObjectDelete( attachment );
- }
- }
- }
- }
- }
-
- //receive materials when dismantling
- protected void ReceiveMaterialsServer( notnull Man player, string part_name, string damagezone_name )
- {
- ConstructionPart construction_part = GetConstructionPart( part_name );
- bool is_base = construction_part.IsBase();
- string main_part_name = construction_part.GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "Materials";
-
- if ( GetGame().ConfigIsExisting( cfg_path ) )
- {
- StaticConstructionMethods.SpawnConstructionMaterialPiles(GetParent(),player,cfg_path,part_name,damagezone_name,is_base);
- }
- }
-
- //destroy lockable materials when destroying
- protected void DestroyMaterialsServer( Man player, string part_name )
- {
- ConstructionPart cPart = GetConstructionPart( part_name );
- string main_part_name = cPart.GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "Materials";
-
- if ( GetGame().ConfigIsExisting( cfg_path ) )
- {
- int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
-
- for ( int i = 0; i < child_count; i++ )
- {
- string child_name;
- GetGame().ConfigGetChildName( cfg_path, i, child_name );
-
- //get type, quantity from material
- string config_path;
- string type;
- string slot_name;
- config_path = cfg_path + " " + child_name + " " + "type";
- GetGame().ConfigGetText( config_path, type );
- config_path = cfg_path + " " + child_name + " " + "slot_name";
- GetGame().ConfigGetText( config_path, slot_name );
- config_path = cfg_path + " " + child_name + " " + "quantity";
- float quantity = GetGame().ConfigGetFloat( config_path );
- config_path = cfg_path + " " + child_name + " " + "lockable";
- bool lockable = GetGame().ConfigGetInt( config_path );
-
- //get material
- ItemBase attachment = ItemBase.Cast( GetParent().FindAttachmentBySlotName( slot_name ) );
-
- //material still attached
- if ( lockable ) //if lockable
- {
- if ( attachment )
- {
- InventoryLocation inventory_location = new InventoryLocation;
- attachment.GetInventory().GetCurrentInventoryLocation( inventory_location );
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] " + Object.GetDebugName(GetParent()) + " DestroyMaterialsServer unlock slot=" + inventory_location.GetSlot());
-
- GetParent().GetInventory().SetSlotLock( inventory_location.GetSlot() , false );
- GetGame().ObjectDelete( attachment ); //delete object
- }
- }
- }
- }
- }
-
- void DropNonUsableMaterialsServer( Man player, string part_name )
- {
- ConstructionPart construction_part = GetConstructionPart( part_name );
-
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " " + "Construction" + " " + construction_part.GetMainPartName() + " " + construction_part.GetPartName() + " " + "platform_support";
- string platform_support;
-
- if ( GetGame().ConfigIsExisting( cfg_path ) )
- {
- GetGame().ConfigGetText( cfg_path, platform_support );
- }
-
- if ( platform_support.Length() > 0 || construction_part.IsBase() )
- {
- string at_cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "GUIInventoryAttachmentsProps";
-
- if ( GetGame().ConfigIsExisting( at_cfg_path ) )
- {
- int child_count = GetGame().ConfigGetChildrenCount( at_cfg_path );
-
- for ( int i = 0; i < child_count; i++ )
- {
- string child_name;
- GetGame().ConfigGetChildName( at_cfg_path, i, child_name );
- child_name.ToLower();
-
- if ( child_name.Contains( platform_support ) )
- {
- ref array<string> attachment_slots = new array<string>;
- GetGame().ConfigGetTextArray( at_cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
-
- for ( int j = 0; j < attachment_slots.Count(); ++j )
- {
- //get material
- ItemBase attachment = ItemBase.Cast( GetParent().FindAttachmentBySlotName( attachment_slots.Get( j ) ) );
-
- //material still attached
- if ( attachment )
- {
- InventoryLocation inventory_location = new InventoryLocation;
- attachment.GetInventory().GetCurrentInventoryLocation( inventory_location );
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] " + Object.GetDebugName(GetParent()) + " DropNonUsableMaterials UNlocking slot=" + inventory_location.GetSlot());
-
- //unlock slot
- GetParent().GetInventory().SetSlotLock( inventory_location.GetSlot() , false );
-
- EntityAI parent = GetParent();
- if (!parent)
- parent = player;
-
- int quantity_max = attachment.GetTargetQuantityMax(-1);
- InventoryLocation dst = new InventoryLocation;
- vector mat[4];
- attachment.GetTransform(mat);
-
- if ( parent.MemoryPointExists("" + part_name + "_materials") )
- {
- vector destination = parent.GetMemoryPointPos("" + part_name + "_materials");
- destination = GetGame().ObjectModelToWorld(parent,destination);
- float health = attachment.GetHealth("","Health");
- float quantity = attachment.GetQuantity() - 1;
- if (quantity < 1.0)
- quantity = 1.0;
- float dir[4];
- inventory_location.GetDir(dir);
- dst.SetGroundEx(attachment,destination,dir);
- //Print(dst.DumpToString());
- MiscGameplayFunctions.CreateItemBasePiles(attachment.GetType(),destination,quantity,health,true);
- attachment.AddQuantity( -quantity );
- }
- else
- {
- dst.SetGround(attachment,mat);
-
- for ( int k = attachment.GetQuantity(); k > quantity_max; )
- {
- Object o = parent.GetInventory().LocationCreateEntity( dst, attachment.GetType(), ECE_PLACE_ON_SURFACE, RF_DEFAULT );
- ItemBase new_item = ItemBase.Cast( o );
-
- if( new_item )
- {
- MiscGameplayFunctions.TransferItemProperties( attachment, new_item );
- attachment.AddQuantity( -quantity_max );
- new_item.SetQuantity( quantity_max );
- }
- k -= quantity_max;
- }
- }
-
- //drop
- if (attachment.GetQuantity() > 0)
- {
- if ( GetGame().IsMultiplayer() )
- {
- parent.ServerTakeToDst( inventory_location, dst );
- }
- else
- {
- parent.LocalTakeToDst( inventory_location, dst );
- }
- }
- else
- {
- attachment.Delete();
- }
- }
- }
- }
- }
- }
- }
- }
-
- //set lock on materials that are attached and cannot be locked/unlocked
- void SetLockOnAttachedMaterials( string part_name, bool lock_slot )
- {
- string main_part_name = GetConstructionPart( part_name ).GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "Materials";
-
- if ( GetGame().ConfigIsExisting( cfg_path ) )
- {
- int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
-
- for ( int i = 0; i < child_count; i++ )
- {
- string child_name;
- GetGame().ConfigGetChildName( cfg_path, i, child_name );
-
- //get type, quantity from material
- string config_path;
- string type;
- string slot_name;
- config_path = cfg_path + " " + child_name + " " + "type";
- GetGame().ConfigGetText( config_path, type );
- config_path = cfg_path + " " + child_name + " " + "slot_name";
- GetGame().ConfigGetText( config_path, slot_name );
- config_path = cfg_path + " " + child_name + " " + "quantity";
- float quantity = GetGame().ConfigGetFloat( config_path );
- config_path = cfg_path + " " + child_name + " " + "lockable";
- bool lockable = GetGame().ConfigGetInt( config_path );
-
- //get material
- ItemBase attachment = ItemBase.Cast( GetParent().FindAttachmentBySlotName( slot_name ) );
-
- //material still attached
- if ( lockable ) //if lockable
- {
- if ( attachment )
- {
- InventoryLocation inventory_location = new InventoryLocation;
- attachment.GetInventory().GetCurrentInventoryLocation( inventory_location );
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] " + Object.GetDebugName(GetParent()) + " SetLockOnAttachedMaterials lock=" + lock_slot +" slot=" + inventory_location.GetSlot());
- GetParent().GetInventory().SetSlotLock( inventory_location.GetSlot(), lock_slot );
- }
- }
- }
- }
- }
-
- //============================================
- // Construction tools
- //============================================
- bool CanUseToolToBuildPart( string part_name, ItemBase tool )
- {
- ConstructionPart construction_part = GetConstructionPart( part_name );
- string part_cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + construction_part.GetMainPartName() + " " + construction_part.GetPartName() + " " + "build_action_type";
- if ( GetGame().ConfigIsExisting( part_cfg_path ) )
- {
- int part_build_action_type = GetGame().ConfigGetInt( part_cfg_path );
- string tool_cfg_path = "cfgVehicles" + " " + tool.GetType() + " " + "build_action_type";
-
- if ( GetGame().ConfigIsExisting( tool_cfg_path ) )
- {
- int tool_build_action_type = GetGame().ConfigGetInt( tool_cfg_path );
-
- if ( ( part_build_action_type & tool_build_action_type ) > 0 )
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- bool CanUseToolToDismantlePart( string part_name, ItemBase tool )
- {
- ConstructionPart construction_part = GetConstructionPart( part_name );
- string part_cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + construction_part.GetMainPartName() + " " + construction_part.GetPartName() + " " + "dismantle_action_type";
- if ( GetGame().ConfigIsExisting( part_cfg_path ) )
- {
- int part_dismantle_action_type = GetGame().ConfigGetInt( part_cfg_path );
- string tool_cfg_path = "cfgVehicles" + " " + tool.GetType() + " " + "dismantle_action_type";
-
- if ( GetGame().ConfigIsExisting( tool_cfg_path ) )
- {
- int tool_dismantle_action_type = GetGame().ConfigGetInt( tool_cfg_path );
-
- if ( ( part_dismantle_action_type & tool_dismantle_action_type ) > 0 )
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- ConstructionMaterialType GetMaterialType( string part_name )
- {
- ConstructionPart construction_part = GetConstructionPart( part_name );
- string part_cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + construction_part.GetMainPartName() + " " + construction_part.GetPartName() + " " + "material_type";
- if ( GetGame().ConfigIsExisting( part_cfg_path ) )
- {
- return GetGame().ConfigGetInt( part_cfg_path );
- }
-
- return ConstructionMaterialType.MATERIAL_NONE;
- }
-
- //============================================
- // Collision check
- //============================================
- //Collisions (BBox and Trigger); deprecated
- bool IsColliding( string part_name )
- {
- if (CfgGameplayHandler.GetDisableIsCollidingCheck())
- return false;
- ConstructionPart construction_part = GetConstructionPart( part_name );
-
- if ( construction_part )
- {
- vector center;
- float absolute_ofset = 0.05; //we need to lift BBox even more, because it colliddes with house floors due to various reasons (probably geometry or float imperfections)
- vector edge_length;
- vector min_max[2]; //data used for creating trigger
- ref array<Object> excluded_objects = new array<Object>;
- ref array<Object> collided_objects = new array<Object>;
-
- excluded_objects.Insert( GetParent() );
-
- //get min_max and center from config and memory points
- GetCollisionBoxData( part_name, min_max );
-
- center = GetBoxCenter( min_max );
- center = GetParent().ModelToWorld( center ); //convert to world coordinates
- edge_length = GetCollisionBoxSize( min_max );
-
- //Create trigger
- //CreateCollisionTrigger( part_name, min_max, center );
-
- //check collision on box trigger and collision box
- //IsTrigger colliding was turned off (for now) for easier way to build something with other players around
- if ( /* IsTriggerColliding() || */ GetGame().IsBoxCollidingGeometry( Vector( center[0], center[1] + absolute_ofset, center[2] ), GetParent().GetOrientation(), edge_length, ObjIntersectView, ObjIntersectGeom, excluded_objects, collided_objects ) )
- {
- //Debug
- // DrawDebugCollisionBox( min_max, ARGB( 150, 255, 0, 0 ) );
- //
- for (int i = 0; i < collided_objects.Count(); i++)
- {
- //Print(collided_objects.Get(i).GetType());
- EntityAI entity = EntityAI.Cast(collided_objects.Get(i));
- if ( entity && !entity.IsIgnoredByConstruction() )
- return true;
- }
- }
- //Debug
- // DrawDebugCollisionBox( min_max, ARGB( 150, 255, 255, 255 ) );
- }
- return false;
- }
-
- //! Collision check for building part
- bool IsCollidingEx( CollisionCheckData check_data )
- {
- if (CfgGameplayHandler.GetDisableIsCollidingCheck())
- return false;
- ConstructionPart construction_part = GetConstructionPart( check_data.m_PartName );
-
- if ( construction_part )
- {
- vector center;
- float absolute_ofset = 0.05; //we need to lift BBox even more, because it colliddes with house floors due to various reasons (probably geometry or float imperfections)
- vector edge_length;
- vector min_max[2]; //data used for creating trigger
- ref array<Object> excluded_objects = new array<Object>;
- ref array<Object> collided_objects = new array<Object>;
-
- excluded_objects.Insert( GetParent() );
- if (check_data.m_AdditionalExcludes.Count() > 0)
- {
- excluded_objects.InsertAll(check_data.m_AdditionalExcludes);
- }
-
- GetCollisionBoxData( check_data.m_PartName, min_max );
- center = GetBoxCenter( min_max );
- center = GetParent().ModelToWorld( center ); //convert to world coordinates
- edge_length = GetCollisionBoxSize( min_max );
-
- if ( GetGame().IsBoxCollidingGeometry( Vector( center[0], center[1] + absolute_ofset, center[2] ), GetParent().GetOrientation(), edge_length, check_data.m_PrimaryGeometry, check_data.m_SecondaryGeometry, excluded_objects, collided_objects ) )
- {
- //Debug
- //DrawDebugCollisionBox( min_max, ARGB( 150, 255, 0, 0 ) );
- for (int i = 0; i < collided_objects.Count(); i++)
- {
- EntityAI entity = EntityAI.Cast(collided_objects.Get(i));
- if ( entity && !entity.IsIgnoredByConstruction() )
- return true;
- }
- }
- //Debug
- //DrawDebugCollisionBox( min_max, ARGB( 150, 255, 255, 255 ) );
- }
- return false;
- }
- vector GetCollisionBoxSize( vector min_max[2] )
- {
- vector box_size = Vector( 0, 0, 0 );
-
- box_size[0] = Math.AbsFloat( min_max[1][0] - min_max[0][0] );
- box_size[1] = Math.AbsFloat( min_max[1][1] - min_max[0][1] );
- box_size[2] = Math.AbsFloat( min_max[1][2] - min_max[0][2] );
-
- return box_size;
- }
-
- //returns collision box data from construction config and model p3d
- protected void GetCollisionBoxData( string part_name, out vector min_max[2] )
- {
- string main_part_name = GetConstructionPart( part_name ).GetMainPartName();
- string cfg_path = "cfgVehicles" + " " + GetParent().GetType() + " "+ "Construction" + " " + main_part_name + " " + part_name + " " + "collision_data";
- ref array<string> collision_data = new array<string>;
- GetGame().ConfigGetTextArray( cfg_path, collision_data );
-
- if ( collision_data.Count() > 0 )
- {
- if ( GetParent().MemoryPointExists( collision_data[0] ) )
- {
- min_max[0] = GetParent().GetMemoryPointPos( collision_data[0] );
- }
- if ( GetParent().MemoryPointExists( collision_data[1] ) )
- {
- min_max[1] = GetParent().GetMemoryPointPos( collision_data[1] );
- }
- }
- }
-
- //returns center point of box defined by min/max values
- vector GetBoxCenter( vector min_max[2] )
- {
- vector center;
-
- center[0] = ( min_max[1][0] - min_max[0][0] ) / 2;
- center[1] = ( min_max[1][1] - min_max[0][1] ) / 2;
- center[2] = ( min_max[1][2] - min_max[0][2] ) / 2;
- center = Vector( min_max[1][0] - center[0], min_max[1][1] - center[1], min_max[1][2] - center[2] ); //offset to box center
-
- return center;
- }
-
- void GetTriggerExtents( vector min_max[2], out vector extents[2] )
- {
- vector egde_length = GetCollisionBoxSize( min_max );
- extents[0][0] = -egde_length[0] / 2; //min
- extents[0][1] = -egde_length[1] / 2;
- extents[0][2] = -egde_length[2] / 2;
- extents[1][0] = egde_length[0] / 2; //max
- extents[1][1] = egde_length[1] / 2;
- extents[1][2] = egde_length[2] / 2;
- }
-
- //Debug
- protected void DrawDebugCollisionBox( vector min_max[2], int color )
- {
- DestroyDebugCollisionBox();
-
- vector mat[4];
- GetParent().GetTransform( mat );
-
- m_CollisionBox = Debug.DrawBox( min_max[0], min_max[1], color );
- m_CollisionBox.SetMatrix( mat );
- }
-
- protected void DestroyDebugCollisionBox()
- {
- if ( m_CollisionBox )
- {
- m_CollisionBox.Destroy();
- m_CollisionBox = NULL;
- }
- }
-
- void CreateCollisionTrigger( string part_name, vector min_max[2], vector center )
- {
- if ( m_ConstructionBoxTrigger )
- {
- if ( m_ConstructionBoxTrigger.GetPartName() == part_name ) //already created
- {
- return;
- }
- else
- {
- DestroyCollisionTrigger();
- }
- }
-
- //get proper trigger extents (min<max)
- vector extents[2];
- GetTriggerExtents( min_max, extents );
-
- //create trigger
- m_ConstructionBoxTrigger = ConstructionBoxTrigger.Cast( GetGame().CreateObject( "ConstructionBoxTrigger", center, false, false, false ) );
- m_ConstructionBoxTrigger.SetPosition( center );
- m_ConstructionBoxTrigger.SetOrientation( GetParent().GetOrientation() );
- m_ConstructionBoxTrigger.SetExtents( extents[0], extents[1] );
-
- m_ConstructionBoxTrigger.SetPartName( part_name );
- }
- //
-
- void DestroyCollisionTrigger()
- {
- GetGame().ObjectDelete( m_ConstructionBoxTrigger );
- m_ConstructionBoxTrigger = NULL;
- }
-
- bool IsTriggerColliding()
- {
- return m_ConstructionBoxTrigger.IsColliding();
- }
- }
- class StaticConstructionMethods
- {
- //! spawns material from any construction; 'player' parameter optional
- static void SpawnConstructionMaterialPiles(notnull EntityAI entity, Man player, string cfg_path, string main_part_name, string damagezone_name = "", bool is_base = false )
- {
- int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
-
- for ( int i = 0; i < child_count; i++ )
- {
- string child_name;
- GetGame().ConfigGetChildName( cfg_path, i, child_name );
-
- //get type, quantity from material
- string config_path;
- string type;
- string slot_name;
- config_path = cfg_path + " " + child_name + " " + "type";
- GetGame().ConfigGetText( config_path, type );
- config_path = cfg_path + " " + child_name + " " + "slot_name";
- GetGame().ConfigGetText( config_path, slot_name );
- config_path = cfg_path + " " + child_name + " " + "quantity";
- float quantity = GetGame().ConfigGetFloat( config_path );
- config_path = cfg_path + " " + child_name + " " + "lockable";
- bool lockable = GetGame().ConfigGetInt( config_path );
-
- //receive material quantity
- ItemBase attachment = ItemBase.Cast( entity.FindAttachmentBySlotName( slot_name ) );
- int slot_id;
-
- //material still attached
- if ( lockable ) //if lockable
- {
- if ( attachment )
- {
- InventoryLocation src = new InventoryLocation;
- attachment.GetInventory().GetCurrentInventoryLocation( src );
- if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] " + Object.GetDebugName( entity) + " DropNonUsableMaterials UNlocking slot=" + src.GetSlot() );
- entity.GetInventory().SetSlotLock( src.GetSlot() , false );
-
- //detach if base
- if ( is_base )
- {
- if ( GetGame().IsMultiplayer() && player )
- {
- InventoryLocation dst = new InventoryLocation;
- GameInventory.SetGroundPosByOwner( player, src.GetItem(), dst );
- player.ServerTakeToDst( src, dst );
- }
- else
- {
- entity.GetInventory().DropEntity( InventoryMode.PREDICTIVE, entity, attachment );
- }
- }
- }
- }
- else
- {
- float pile_health;
- float qty_coef;
- vector destination = entity.GetPosition();
- //placed on helper memory point, if available
- if ( entity.MemoryPointExists("" + main_part_name + "_materials") )
- {
- destination = entity.GetMemoryPointPos("" + main_part_name + "_materials");
- destination = GetGame().ObjectModelToWorld(entity,destination);
- }
- else if ( entity.MemoryPointExists(main_part_name) )
- {
- destination = entity.GetMemoryPointPos(main_part_name);
- destination = GetGame().ObjectModelToWorld(entity,destination);
- }
- //pile_health = GameConstants.DAMAGE_WORN_VALUE * MiscGameplayFunctions.GetTypeMaxGlobalHealth(type);
- pile_health = entity.GetHealth01(damagezone_name,"Health") * MiscGameplayFunctions.GetTypeMaxGlobalHealth(type);
- qty_coef = 1 - (entity.GetHealthLevel(damagezone_name) * Construction.DECONSTURCT_MATERIAL_LOSS) - Construction.DECONSTURCT_MATERIAL_LOSS;
- quantity *= qty_coef;
- quantity = Math.Max(Math.Floor(quantity),1);
- MiscGameplayFunctions.CreateItemBasePiles(type,destination,quantity,pile_health,true);
- }
- }
- }
- }
- //! Data structure for passing parameters (extendable, modable)
- class CollisionCheckData
- {
- ref array<Object> m_AdditionalExcludes;
- string m_PartName;
- int m_PrimaryGeometry;
- int m_SecondaryGeometry;
-
- void CollisionCheckData()
- {
- m_AdditionalExcludes = new array<Object>;
- m_PartName = "";
- m_PrimaryGeometry = ObjIntersectGeom;
- m_SecondaryGeometry = ObjIntersectView;
- }
- }
- class ConstructionBoxTrigger : ManTrigger
- {
- string m_PartName;
-
- void SetPartName( string part_name )
- {
- m_PartName = part_name;
- }
-
- string GetPartName()
- {
- return m_PartName;
- }
-
- override protected void UpdateInsiders( int timeout )
- {
- super.UpdateInsiders( 20 );
- }
-
- bool IsColliding()
- {
- if ( GetInsiders().Count() > 0 )
- {
- return true;
- }
-
- return false;
- }
- }
|