mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
342 lines
10 KiB
Plaintext
342 lines
10 KiB
Plaintext
/**********************************************************************
|
|
* Copyright (c)2000-2002 Sony Online Entertainment Inc.
|
|
* All Rights Reserved
|
|
*
|
|
* Title: destructible_building
|
|
* Description: script that goes destructible buildings.
|
|
*
|
|
* @author $Author:$
|
|
* @version $Revision:$
|
|
**********************************************************************/
|
|
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
include library.battlefield;
|
|
include library.player_structure;
|
|
include library.factions;
|
|
include library.sui;
|
|
include library.utils;
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
const string VAR_SMOKE_LEVEL = "battlefield.smoke_level";
|
|
const string_id SID_CONSTRUCTION_SITE = new string_id("battlefield", "construction_site");
|
|
const string_id SID_DESTROY_STRUCTURE = new string_id("battlefield", "destroy_structure");
|
|
const string_id SID_REPAIR_STRUCTURE = new string_id("battlefield", "repair_structure");
|
|
|
|
/***** TRIGGERS ********************************************************/
|
|
|
|
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
|
|
{
|
|
if (hasObjVar(self, battlefield.VAR_BUILDTIME))
|
|
{
|
|
int construction_root = mi.addRootMenu (menu_info_types.SERVER_TERMINAL_MANAGEMENT_STATUS, SID_CONSTRUCTION_SITE);
|
|
}
|
|
|
|
if (battlefield.isBattlefieldConstructed(self))
|
|
{
|
|
if (battlefield.isSameBattlefieldFaction(self, player))
|
|
{
|
|
int destroy_root = mi.addRootMenu (menu_info_types.SERVER_TERMINAL_MANAGEMENT_DESTROY, SID_DESTROY_STRUCTURE);
|
|
}
|
|
}
|
|
// Offer option to repair if the structure is damaged
|
|
if (getHitpoints(self) < getMaxHitpoints(self))
|
|
{
|
|
if (battlefield.isSameBattlefieldFaction(self, player))
|
|
{
|
|
int repair_root = mi.addRootMenu (menu_info_types.SERVER_TERMINAL_MANAGEMENT_PAY, SID_REPAIR_STRUCTURE);
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
if (item == menu_info_types.SERVER_TERMINAL_MANAGEMENT_STATUS)
|
|
{
|
|
// Get battlefield info
|
|
region bf = battlefield.getBattlefield(self);
|
|
obj_id master_object = battlefield.getMasterObjectFromRegion(bf);
|
|
int faction_id = pvpBattlefieldGetFaction(self, bf);
|
|
string faction = factions.getFactionNameByHashCode(faction_id);
|
|
string name = getStringObjVar(self, battlefield.VAR_NAME);
|
|
|
|
// Determine % complete
|
|
int build_time = getIntObjVar(self, battlefield.VAR_BUILDTIME);
|
|
int timestamp = getIntObjVar(self, battlefield.VAR_TIMESTAMP);
|
|
int current_time = getGameTime();
|
|
int time_passed = current_time - timestamp;
|
|
int percent = time_passed * 100 / build_time;
|
|
|
|
// Determine time remaining.
|
|
int time = build_time - time_passed;
|
|
if (time > 0)
|
|
{
|
|
int[] conv_time = player_structure.convertSecondsTime(time);
|
|
string time_str = player_structure.assembleTimeRemaining(conv_time);
|
|
|
|
string[] dsrc = new string[5];
|
|
dsrc[0] = "Structure: " + name;
|
|
dsrc[1] = "Faction: " + faction;
|
|
dsrc[2] = "This structure is " + percent + "% complete";
|
|
dsrc[3] = "";
|
|
dsrc[4] = "Time Remaining: " + time_str;
|
|
sui.listbox(player, "Structure Construction Status", "Structure Construction Status", dsrc);
|
|
}
|
|
}
|
|
|
|
if (item == menu_info_types.SERVER_TERMINAL_MANAGEMENT_DESTROY)
|
|
{
|
|
// Remove the structure if of the same faction
|
|
if (battlefield.isSameBattlefieldFaction(self, player))
|
|
battlefield.removeBattlefieldObject(self);
|
|
}
|
|
|
|
if (item == menu_info_types.SERVER_TERMINAL_MANAGEMENT_PAY)
|
|
{
|
|
if (battlefield.isSameBattlefieldFaction(self, player))
|
|
queueCommand(player, ##"repairBattlefieldStructure", self, "", COMMAND_PRIORITY_DEFAULT);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectDamaged(obj_id attacker, obj_id weapon, int damage)
|
|
{
|
|
// Deactivate repair on damage
|
|
if (hasObjVar(self, battlefield.VAR_REPAIRING))
|
|
removeObjVar(self, battlefield.VAR_REPAIRING);
|
|
|
|
/*
|
|
// Play some smoke effects.
|
|
int hitpoints = getHitpoints(self);
|
|
int max_hitpoints = getMaxHitpoints(self);
|
|
float percent_hp = (float)hitpoints / (float)max_hitpoints;
|
|
location loc = getLocation (self);
|
|
|
|
region bf = battlefield.getBattlefield(self);
|
|
if (bf == null)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
obj_id master_object = battlefield.getMasterObjectFromRegion(bf);
|
|
|
|
int smoke_level = 0;
|
|
|
|
if (hasObjVar(self, VAR_SMOKE_LEVEL))
|
|
smoke_level = getIntObjVar(self, VAR_SMOKE_LEVEL);
|
|
|
|
if (smoke_level == 0)
|
|
{
|
|
if (percent_hp < .5)
|
|
{
|
|
obj_id[] players = battlefield.getPlayersOnBattlefield(master_object);
|
|
if (players != null)
|
|
{
|
|
// Send smoke effect to all players.
|
|
for (int i = 0; i < players.length; i++)
|
|
playClientEffectLoc(players[i], "clienteffect/lair_med_damage_smoke.cef" , loc, 0);
|
|
}
|
|
|
|
messageTo(self, "msgRefreshSmoke", null, 5.0f, true);
|
|
setObjVar(self, VAR_SMOKE_LEVEL, 1);
|
|
}
|
|
}
|
|
|
|
if (smoke_level == 1)
|
|
{
|
|
if (percent_hp < .25)
|
|
{
|
|
obj_id[] players = battlefield.getPlayersOnBattlefield(master_object);
|
|
if (players != null)
|
|
{
|
|
// Send smoke effect to all players.
|
|
for (int i = 0; i < players.length; i++)
|
|
playClientEffectLoc(players[i], "clienteffect/lair_hvy_damage_fire.cef" , loc, 0);
|
|
}
|
|
messageTo(self, "msgRefreshSmoke", null, 8.0f, true);
|
|
setObjVar(self, VAR_SMOKE_LEVEL, 2);
|
|
}
|
|
} */
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectDisabled (obj_id killer)
|
|
{
|
|
LOG("LOG_CHANNEL", "battlefield.destructible_building::OnObjectDisabled -- " + self);
|
|
|
|
region bf = battlefield.getBattlefield(self);
|
|
obj_id master_object = battlefield.getMasterObjectFromRegion(bf);
|
|
if (!isIdValid(master_object))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
if (hasObjVar(self, battlefield.VAR_GAME_CRITICAL))
|
|
{
|
|
// Mark the object has having been destroyed by a player and not the game.
|
|
// (needed for some critical objects).
|
|
setObjVar(self, battlefield.VAR_COMBAT_DESTROYED, 1);
|
|
|
|
// Display destroy messaging for game critical objects.
|
|
string name = getName(self);
|
|
int faction_id = pvpBattlefieldGetFaction(self, bf);
|
|
string faction = factions.getFactionNameByHashCode(faction_id);
|
|
|
|
battlefield.sendBattlefieldMessage(master_object, "The " + faction + "'s " + name + " was destroyed by " + getFirstName(killer));
|
|
}
|
|
|
|
obj_id[] players = battlefield.getPlayersOnBattlefield(master_object);
|
|
if (players != null)
|
|
{
|
|
location loc = getLocation(self);
|
|
for (int i = 0; i < players.length; i++)
|
|
playClientEffectLoc(killer, "clienteffect/combat_explosion_lair_large.cef", loc, 0);
|
|
}
|
|
|
|
messageTo( self, "battlefieldObjectDestroyed", null, 2.5f, false );
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** MESSAGEHANDLERS *************************************************/
|
|
messageHandler msgRefreshSmoke()
|
|
{
|
|
int smoke_level = 0;
|
|
if (hasObjVar(self, VAR_SMOKE_LEVEL))
|
|
smoke_level = getIntObjVar(self, VAR_SMOKE_LEVEL);
|
|
|
|
location loc = getLocation(self);
|
|
region bf = battlefield.getBattlefield(self);
|
|
if (bf == null)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
obj_id master_object = battlefield.getMasterObjectFromRegion(bf);
|
|
|
|
if (smoke_level == 1)
|
|
{
|
|
obj_id[] players = battlefield.getPlayersOnBattlefield(master_object);
|
|
// Send smoke effect to all players.
|
|
if (players != null)
|
|
{
|
|
for (int i = 0; i < players.length; i++)
|
|
playClientEffectLoc(players[i], "clienteffect/lair_med_damage_smoke.cef" , loc, 0);
|
|
}
|
|
messageTo(self, "msgRefreshSmoke", null, 5.0f, true);
|
|
}
|
|
|
|
else if (smoke_level == 2)
|
|
{
|
|
obj_id[] players = battlefield.getPlayersOnBattlefield(master_object);
|
|
// Send smoke effect to all players.
|
|
if (players != null)
|
|
{
|
|
for (int i = 0; i < players.length; i++)
|
|
playClientEffectLoc(players[i], "clienteffect/lair_hvy_damage_fire.cef" , loc, 0);
|
|
}
|
|
messageTo(self, "msgRefreshSmoke", null, 8.0f, true);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler msgConstructionComplete()
|
|
{
|
|
// This handler is used for player constructed buildings.
|
|
|
|
LOG("LOG_CHANNEL", "battlefield.destructible_building::msgConstructionComplete");
|
|
|
|
location loc = getLocation(self);
|
|
float yaw = getYaw(self);
|
|
string template = params.getString("template");
|
|
float height = params.getFloat("height");
|
|
|
|
region bf = battlefield.getBattlefield(self);
|
|
obj_id master_object = battlefield.getMasterObjectFromRegion(bf);
|
|
|
|
int faction_id = pvpBattlefieldGetFaction(self, bf);
|
|
string faction = factions.getFactionNameByHashCode(faction_id);
|
|
string name = params.getString("name");
|
|
int repair_cost = params.getInt("cost") / 10;
|
|
|
|
// Determine % damage of the construction site
|
|
float hitpoints = (float)getHitpoints(self);
|
|
float maxHitpoints = (float)getMaxHitpoints(self);
|
|
int percent = (int)((hitpoints / maxHitpoints) * 100.0f);
|
|
if (percent < 5)
|
|
percent = 5;
|
|
|
|
// Remove the old site and add the new one.
|
|
battlefield.removeBattlefieldObject(self);
|
|
|
|
// Add the new one
|
|
loc.y = height;
|
|
obj_id structure = battlefield.addBattlefieldObject(master_object, template, loc, yaw, faction);
|
|
setObjVar(structure, battlefield.VAR_CONSTRUCTED, 1);
|
|
setObjVar(structure, battlefield.VAR_NAME, name);
|
|
setObjVar(structure, battlefield.VAR_REPAIR_COST, repair_cost);
|
|
|
|
// Reduce its hitpoints by the % damage of the construction site.
|
|
int hitpoint_mod = (getMaxHitpoints(structure) * percent) / 100;
|
|
setHitpoints(structure, hitpoint_mod);
|
|
|
|
if (structure == null)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
// Send a faction message
|
|
battlefield.sendFactionMessage(master_object, faction, "Construction complete on " + name);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler msgRepairPulse()
|
|
{
|
|
LOG("LOG_CHANNEL", "battlefield.destructible_building::msgRepairPulse -- " + self);
|
|
|
|
if (!hasObjVar(self, battlefield.VAR_REPAIRING))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
// Each repair pulse increases hitpoints by 5%.
|
|
int hitpoints = getHitpoints(self);
|
|
int max_hitpoints = getMaxHitpoints(self);
|
|
int repair_amt = max_hitpoints / 20;
|
|
|
|
hitpoints = hitpoints + repair_amt;
|
|
if (hitpoints >= max_hitpoints)
|
|
hitpoints = max_hitpoints;
|
|
else
|
|
{
|
|
// Send the next repair pulse
|
|
messageTo(self, "msgRepairPulse", null, battlefield.REPAIR_PULSE, true);
|
|
}
|
|
|
|
setHitpoints(self, hitpoints);
|
|
|
|
// Adjust smoke level
|
|
if (hasObjVar(self, VAR_SMOKE_LEVEL))
|
|
{
|
|
float percent_hp = (float)hitpoints / (float)max_hitpoints;
|
|
|
|
if (percent_hp > .5)
|
|
removeObjVar(self, VAR_SMOKE_LEVEL);
|
|
|
|
if ((percent_hp <= .5) && (percent_hp > .25))
|
|
setObjVar(self, VAR_SMOKE_LEVEL, 1);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler battlefieldObjectDestroyed()
|
|
{
|
|
battlefield.removeBattlefieldObject(self);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** COMMANDHANDLERS *************************************************/
|
|
|
|
|
|
/***** FUNCTIONS *******************************************************/
|
|
|
|
|