Skip to content

Commit

Permalink
set-armor-value:
Browse files Browse the repository at this point in the history
	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 6f4e501
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
79 changes: 77 additions & 2 deletions code/parse/sexp.cpp
Expand Up @@ -469,6 +469,7 @@ sexp_oper Operators[] = {


//Armor and Damage Types Sub-Category //Armor and Damage Types Sub-Category
{ "set-armor-type", OP_SET_ARMOR_TYPE, 4, INT_MAX, SEXP_ACTION_OPERATOR, }, // FUBAR { "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 { "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-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 { "ship-set-shockwave-damage-type", OP_SHIP_SHOCKWAVE_SET_DAMAGE_TYPE, 3, INT_MAX, SEXP_ACTION_OPERATOR, }, // FUBAR
Expand Down Expand Up @@ -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 // 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) ){ if ( !stricmp( CTEXT(node), SEXP_HULL_STRING) || !stricmp( CTEXT(node), SEXP_SIM_HULL_STRING) ){
break; break;
} }
} }
// check for special "shields" value for armor types // 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) ){ if ( !stricmp( CTEXT(node), SEXP_SHIELD_STRING) || !stricmp( CTEXT(node), SEXP_SIM_HULL_STRING) ){
break; break;
} }
Expand Down Expand Up @@ -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) void sexp_weapon_set_damage_type(int node)
{ {
int windex, damage, swave, rset; int windex, damage, swave, rset;
Expand Down Expand Up @@ -23579,6 +23632,11 @@ int eval_sexp(int cur_node, int referenced_node)
sexp_set_armor_type(node); sexp_set_armor_type(node);
break; break;


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

case OP_WEAPON_SET_DAMAGE_TYPE: case OP_WEAPON_SET_DAMAGE_TYPE:
sexp_val = SEXP_TRUE; sexp_val = SEXP_TRUE;
sexp_weapon_set_damage_type(node); sexp_weapon_set_damage_type(node);
Expand Down Expand Up @@ -25021,6 +25079,7 @@ int query_operator_return_type(int op)
case OP_TURRET_SET_TARGET_PRIORITIES: case OP_TURRET_SET_TARGET_PRIORITIES:
case OP_TURRET_SET_TARGET_ORDER: case OP_TURRET_SET_TARGET_ORDER:
case OP_SET_ARMOR_TYPE: case OP_SET_ARMOR_TYPE:
case OP_SET_ARMOR_VALUE:
case OP_WEAPON_SET_DAMAGE_TYPE: case OP_WEAPON_SET_DAMAGE_TYPE:
case OP_SHIP_SET_DAMAGE_TYPE: case OP_SHIP_SET_DAMAGE_TYPE:
case OP_SHIP_SHOCKWAVE_SET_DAMAGE_TYPE: case OP_SHIP_SHOCKWAVE_SET_DAMAGE_TYPE:
Expand Down Expand Up @@ -26622,6 +26681,15 @@ int query_operator_argument_type(int op, int argnum)
return OPF_SUBSYSTEM; 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: case OP_WEAPON_SET_DAMAGE_TYPE:
if(argnum == 0) { if(argnum == 0) {
return OPF_BOOL; return OPF_BOOL;
Expand Down Expand Up @@ -28762,6 +28830,7 @@ int get_subcategory(int sexp_id)




case OP_SET_ARMOR_TYPE: case OP_SET_ARMOR_TYPE:
case OP_SET_ARMOR_VALUE:
case OP_WEAPON_SET_DAMAGE_TYPE: case OP_WEAPON_SET_DAMAGE_TYPE:
case OP_SHIP_SET_DAMAGE_TYPE: case OP_SHIP_SET_DAMAGE_TYPE:
case OP_SHIP_SHOCKWAVE_SET_DAMAGE_TYPE: case OP_SHIP_SHOCKWAVE_SET_DAMAGE_TYPE:
Expand Down Expand Up @@ -31498,6 +31567,12 @@ sexp_help_struct Sexp_help[] = {
"\t3: Armor type to set or <none>\r\n" "\t3: Armor type to set or <none>\r\n"
"\trest: Subsystems to set (hull for ship, shield for shields)\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" { OP_WEAPON_SET_DAMAGE_TYPE, "weapon-set-damage-type\r\n"
"\tSets the damage type for weapons or their shockwaves\r\n" "\tSets the damage type for weapons or their shockwaves\r\n"
"\t1: True = set weapon, False = set shockwave\r\n" "\t1: True = set weapon, False = set shockwave\r\n"
Expand Down
1 change: 1 addition & 0 deletions code/parse/sexp.h
Expand Up @@ -722,6 +722,7 @@ class waypoint_list;
#define OP_SET_MOTION_DEBRIS (0x0025 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // The E #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_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_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 // defined for AI goals
#define OP_AI_CHASE (0x0000 | OP_CATEGORY_AI | OP_NONCAMPAIGN_FLAG) #define OP_AI_CHASE (0x0000 | OP_CATEGORY_AI | OP_NONCAMPAIGN_FLAG)
Expand Down
9 changes: 9 additions & 0 deletions code/ship/ship.cpp
Expand Up @@ -5168,6 +5168,8 @@ void ship::clear()


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


shipp->armor_type_idx = sip->armor_type_idx; shipp->armor_type_idx = sip->armor_type_idx;
shipp->shield_armor_type_idx = sip->shield_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->collision_damage_type_idx = sip->collision_damage_type_idx;
shipp->debris_damage_type_idx = sip->debris_damage_type_idx; shipp->debris_damage_type_idx = sip->debris_damage_type_idx;


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


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


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


ship_system->subsys_guardian_threshold = 0; ship_system->subsys_guardian_threshold = 0;
ship_system->armor_type_idx = model_system->armor_type_idx; 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_fire_stamp = timestamp(0);
ship_system->turret_next_enemy_check_stamp = timestamp(0); ship_system->turret_next_enemy_check_stamp = timestamp(0);
ship_system->turret_enemy_objnum = -1; ship_system->turret_enemy_objnum = -1;
Expand Down Expand Up @@ -9130,6 +9136,9 @@ int ship_create(matrix *orient, vec3d *pos, int ship_type, char *ship_name)
sip->flags |= SIF_PATH_FIXUP; sip->flags |= SIF_PATH_FIXUP;
} }


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

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


Expand Down
3 changes: 3 additions & 0 deletions code/ship/ship.h
Expand Up @@ -321,6 +321,7 @@ class ship_subsys


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


// turret info // turret info
//Important -WMC //Important -WMC
Expand Down Expand Up @@ -789,6 +790,8 @@ class ship
int ammo_low_complaint_count; // number of times this ship has complained about low ammo int ammo_low_complaint_count; // number of times this ship has complained about low ammo
int armor_type_idx; int armor_type_idx;
int shield_armor_type_idx; int shield_armor_type_idx;
float armor_value;
float shield_armor_value;
int collision_damage_type_idx; int collision_damage_type_idx;
int debris_damage_type_idx; int debris_damage_type_idx;
ushort debris_net_sig; // net signiture of the first piece of debris this ship has ushort debris_net_sig; // net signiture of the first piece of debris this ship has
Expand Down
3 changes: 3 additions & 0 deletions code/ship/shiphit.cpp
Expand Up @@ -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 *= ss_dif_scale;
} }


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


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


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


Expand Down

0 comments on commit 6f4e501

Please sign in to comment.