Skip to content
Permalink
Browse files

set-armor-value:

	armor_value attributes added to ship and ship_subsys
	the set-armor-value SEXP allows FREDers to manipulate these
	attributes
  • Loading branch information...
X3N0-Life-Form committed May 7, 2014
1 parent b42f468 commit 6f4e50126e5a7d9829e623346c57111f6e1f669b
Showing with 93 additions and 2 deletions.
  1. +77 −2 code/parse/sexp.cpp
  2. +1 −0 code/parse/sexp.h
  3. +9 −0 code/ship/ship.cpp
  4. +3 −0 code/ship/ship.h
  5. +3 −0 code/ship/shiphit.cpp
@@ -469,6 +469,7 @@ sexp_oper Operators[] = {

//Armor and Damage Types Sub-Category
{ "set-armor-type", OP_SET_ARMOR_TYPE, 4, INT_MAX, SEXP_ACTION_OPERATOR, }, // FUBAR
{ "set-armor-value", OP_SET_ARMOR_VALUE, 3, INT_MAX, SEXP_ACTION_OPERATOR }, // X3N0-Life-Form
{ "weapon-set-damage-type", OP_WEAPON_SET_DAMAGE_TYPE, 4, INT_MAX, SEXP_ACTION_OPERATOR, }, // FUBAR
{ "ship-set-damage-type", OP_SHIP_SET_DAMAGE_TYPE, 4, INT_MAX, SEXP_ACTION_OPERATOR, }, // FUBAR
{ "ship-set-shockwave-damage-type", OP_SHIP_SHOCKWAVE_SET_DAMAGE_TYPE, 3, INT_MAX, SEXP_ACTION_OPERATOR, }, // FUBAR
@@ -2060,13 +2061,13 @@ int check_sexp_syntax(int node, int return_type, int recursive, int *bad_node, i
}

// check for the special "hull" value
if ( (Operators[op].value == OP_SABOTAGE_SUBSYSTEM) || (Operators[op].value == OP_REPAIR_SUBSYSTEM) || (Operators[op].value == OP_SET_SUBSYSTEM_STRNGTH) || (Operators[op].value == OP_SET_ARMOR_TYPE) || (Operators[op].value == OP_BEAM_FIRE)) {
if ( (Operators[op].value == OP_SABOTAGE_SUBSYSTEM) || (Operators[op].value == OP_REPAIR_SUBSYSTEM) || (Operators[op].value == OP_SET_SUBSYSTEM_STRNGTH) || (Operators[op].value == OP_SET_ARMOR_TYPE) || (Operators[op].value == OP_BEAM_FIRE) || (Operators[op].value == OP_SET_ARMOR_VALUE)) {
if ( !stricmp( CTEXT(node), SEXP_HULL_STRING) || !stricmp( CTEXT(node), SEXP_SIM_HULL_STRING) ){
break;
}
}
// check for special "shields" value for armor types
if (Operators[op].value == OP_SET_ARMOR_TYPE) {
if (Operators[op].value == OP_SET_ARMOR_TYPE || (Operators[op].value == OP_SET_ARMOR_VALUE)) {
if ( !stricmp( CTEXT(node), SEXP_SHIELD_STRING) || !stricmp( CTEXT(node), SEXP_SIM_HULL_STRING) ){
break;
}
@@ -17174,6 +17175,58 @@ void sexp_set_armor_type(int node)
}
}

void sexp_set_armor_value(int node)
{
int sindex;
float a_value;
ship_subsys *ss = NULL;
ship *shipp = NULL;
ship_info *sip = NULL;

// get ship
sindex = ship_name_lookup(CTEXT(node));
if(sindex < 0) {
return;
}
if(Ships[sindex].objnum < 0) {
return;
}
shipp = &Ships[sindex];
sip = &Ship_info[shipp->ship_info_index];

// get value
a_value = ((float)eval_num(CDR(node))) / 100;

node = CDR(node);
// set value
while (node != -1)
{
if (!stricmp(SEXP_HULL_STRING, CTEXT(node)))
{
// we are setting the ship itself
shipp->armor_value = a_value;
}
else if (!stricmp(SEXP_SHIELD_STRING, CTEXT(node)))
{
// we are setting the ships shields
shipp->shield_armor_value = a_value;
}
else
{
// get the subsystem
ss = ship_get_subsys(&Ships[sindex], CTEXT(node));
if(ss == NULL){
node = CDR(node);
continue;
}
// set the value
ss->armor_value = a_value;
}
// next
node = CDR(node);
}
}

void sexp_weapon_set_damage_type(int node)
{
int windex, damage, swave, rset;
sexp_set_armor_type(node);
break;

case OP_SET_ARMOR_VALUE:
sexp_val = SEXP_TRUE;
sexp_set_armor_value(node);
break;

case OP_WEAPON_SET_DAMAGE_TYPE:
sexp_val = SEXP_TRUE;
sexp_weapon_set_damage_type(node);
case OP_TURRET_SET_TARGET_PRIORITIES:
case OP_TURRET_SET_TARGET_ORDER:
case OP_SET_ARMOR_TYPE:
case OP_SET_ARMOR_VALUE:
case OP_WEAPON_SET_DAMAGE_TYPE:
case OP_SHIP_SET_DAMAGE_TYPE:
case OP_SHIP_SHOCKWAVE_SET_DAMAGE_TYPE:
return OPF_SUBSYSTEM;
}

case OP_SET_ARMOR_VALUE:
if (argnum == 0) {
return OPF_SHIP;
} else if (argnum == 1) {
return OPF_NUMBER;
} else {
return OPF_SUBSYSTEM;
}

case OP_WEAPON_SET_DAMAGE_TYPE:
if(argnum == 0) {
return OPF_BOOL;


case OP_SET_ARMOR_TYPE:
case OP_SET_ARMOR_VALUE:
case OP_WEAPON_SET_DAMAGE_TYPE:
case OP_SHIP_SET_DAMAGE_TYPE:
case OP_SHIP_SHOCKWAVE_SET_DAMAGE_TYPE:
"\t3: Armor type to set or <none>\r\n"
"\trest: Subsystems to set (hull for ship, shield for shields)\r\n"},

{OP_SET_ARMOR_VALUE, "set-armor-value\r\n"
"\tSets the armor value for a ship or subsystem. The armor value is factored in after regular armor type calculations.\r\n"
"\t1: Ship subsystem is on\r\n"
"\t2: Armor value to set (in %; <100 reduces damage taken, >100 increases it)\r\n"
"\trest: Subsystems to set (hull for ship, shield for shields)\r\n"},

{ OP_WEAPON_SET_DAMAGE_TYPE, "weapon-set-damage-type\r\n"
"\tSets the damage type for weapons or their shockwaves\r\n"
"\t1: True = set weapon, False = set shockwave\r\n"
@@ -722,6 +722,7 @@ class waypoint_list;
#define OP_SET_MOTION_DEBRIS (0x0025 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // The E
#define OP_HUD_SET_CUSTOM_GAUGE_ACTIVE (0x0026 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // The E, just revamped a bit by Axem
#define OP_HUD_SET_RETAIL_GAUGE_ACTIVE (0x0027 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // The E, just revamped a bit by Axem
#define OP_SET_ARMOR_VALUE (0x0028 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) //X3N0-Life-Form

// defined for AI goals
#define OP_AI_CHASE (0x0000 | OP_CATEGORY_AI | OP_NONCAMPAIGN_FLAG)
@@ -5168,6 +5168,8 @@ void ship::clear()

armor_type_idx = -1;
shield_armor_type_idx = -1;
armor_value = 1.0f;
shield_armor_value = 1.0f;
collision_damage_type_idx = -1;
debris_damage_type_idx = -1;
debris_net_sig = 0;
@@ -5312,6 +5314,8 @@ void ship_set(int ship_index, int objnum, int ship_type)

shipp->armor_type_idx = sip->armor_type_idx;
shipp->shield_armor_type_idx = sip->shield_armor_type_idx;
shipp->armor_value = 1.0f;
shipp->shield_armor_value = 1.0f;
shipp->collision_damage_type_idx = sip->collision_damage_type_idx;
shipp->debris_damage_type_idx = sip->debris_damage_type_idx;

@@ -5494,6 +5498,7 @@ void ship_subsys::clear()

subsys_guardian_threshold = 0;
armor_type_idx = -1;
armor_value = 1.0f;

turret_best_weapon = -1;
turret_last_fire_direction = vmd_zero_vector;
@@ -5670,6 +5675,7 @@ int subsys_set(int objnum, int ignore_subsys_info)

ship_system->subsys_guardian_threshold = 0;
ship_system->armor_type_idx = model_system->armor_type_idx;
ship_system->armor_value = 1.0f;
ship_system->turret_next_fire_stamp = timestamp(0);
ship_system->turret_next_enemy_check_stamp = timestamp(0);
ship_system->turret_enemy_objnum = -1;
@@ -9130,6 +9136,9 @@ int ship_create(matrix *orient, vec3d *pos, int ship_type, char *ship_name)
sip->flags |= SIF_PATH_FIXUP;
}

shipp->armor_value = 1.0f;
shipp->shield_armor_value = 1.0f;

// Add this ship to Ship_obj_list
shipp->ship_list_index = ship_obj_list_add(objnum);

@@ -321,6 +321,7 @@ class ship_subsys

int subsys_guardian_threshold; // Goober5000
int armor_type_idx; // FUBAR
float armor_value;

// turret info
//Important -WMC
@@ -789,6 +790,8 @@ class ship
int ammo_low_complaint_count; // number of times this ship has complained about low ammo
int armor_type_idx;
int shield_armor_type_idx;
float armor_value;
float shield_armor_value;
int collision_damage_type_idx;
int debris_damage_type_idx;
ushort debris_net_sig; // net signiture of the first piece of debris this ship has
@@ -728,6 +728,7 @@ float do_subobj_hit_stuff(object *ship_objp, object *other_obj, vec3d *hitpos, i
damage_to_apply *= ss_dif_scale;
}

damage_to_apply *= subsystem->armor_value;
subsystem->current_hits -= damage_to_apply;
if (!(subsystem->flags & SSF_NO_AGGREGATE)) {
ship_p->subsys_info[subsystem->system_info->type].aggregate_current_hits -= damage_to_apply;
@@ -2097,6 +2098,7 @@ static void ship_do_damage(object *ship_objp, object *other_obj, vec3d *hitpos,
damage *= difficulty_scale_factor;
}

damage *= shipp->shield_armor_value;
damage = apply_damage_to_shield(ship_objp, quadrant, damage);

if(damage > 0.0f){
@@ -2199,6 +2201,7 @@ static void ship_do_damage(object *ship_objp, object *other_obj, vec3d *hitpos,
return;
}
}
damage *= shipp->armor_value;
ship_objp->hull_strength -= damage;
}

0 comments on commit 6f4e501

Please sign in to comment.
You can’t perform that action at this time.