rig_weapon.c
src/rig_weapon.c · 4.0 KB
From the archive cyhawk_mud.tar.gz
Download the archive « Back to the archive contents
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "interp.h"
#include "tables.h"
#include "rig_tables.h"
#include "rig.h"
/*
* create_weapon()
*
* Generates a weapon!
*
* force_type - If set to random, will generate a random weapon
* force_material - If set, will force that material
* quaility - If previous unset, determine quaility (poor = iron/steel, decent = steel/sivler, etc)
* is_for_shop - Flags ITEM_INVENTORY Flag
*/
OBJ_DATA * create_weapon(OBJ_DATA * obj, int force_type, int force_material, int quaility, bool is_for_shop)
{
char name_set[MSL]; /* Used for naming purposes */
char shor_set[MSL];
char long_set[MSL];
char mate_set[MSL];
char temp[MSL];
int obj_type = -1; /* Used for generation type */
int material_type = -1;
free_string(obj->name);
free_string(obj->short_descr);
free_string(obj->description);
free_string(obj->material);
/* Ok determine if forced, if not random */
if (force_type == RIG_RANDOM)
obj_type = number_range(0, rig_weapon_max());
else
obj_type = force_type;
/* Also make sure we dont get armor only materials.. */
if (force_material == RIG_RANDOM)
material_type = number_range(0, rig_material_max() - 1);
else
material_type = force_material;
/* Ok, so we got an armor only, lets default to uh, Iron! */
if (rig_material_table[material_type].armor_only == material_type)
material_type = material_lookup("iron");
sprintf(name_set, rig_weapons_table[obj_type].name, rig_material_table[material_type].name);
sprintf(temp, "%s %s", rig_material_table[material_type].prefix, rig_material_table[material_type].name);
sprintf(shor_set, rig_weapons_table[obj_type].short_descr, temp);
sprintf(long_set, rig_weapons_table[obj_type].long_descr, temp);
sprintf(mate_set, rig_material_table[material_type].name);
obj->name = str_dup (name_set);
obj->short_descr = str_dup (shor_set);
obj->description = str_dup (long_set);
obj->material = str_dup (mate_set);
obj->item_type = ITEM_WEAPON;
obj->wear_flags = ITEM_TAKE | ITEM_WIELD;
obj->value[0] = rig_weapons_table[obj_type].value[0];
obj->value[1] = rig_weapons_table[obj_type].value[1];
obj->value[2] = rig_weapons_table[obj_type].value[2];
obj->value[3] = rig_weapons_table[obj_type].value[3];
obj->cost = 1 + rig_weapons_table[obj_type].cost * rig_material_table[material_type].cost_multi / 100;
obj->weight = 1 + rig_weapons_table[obj_type].weight * rig_material_table[material_type].weight_multi / 100;
/* Add the material bonuses to the weapon */
fix_material_bonus(obj, material_type);
/* Cant be too careful*/
name_set[0] = '\0';
shor_set[0] = '\0';
long_set[0] = '\0';
mate_set[0] = '\0';
temp[0] = '\0';
return obj;
}
/*
* fix_material_bonus()
*
* Tidies up hit/dam bonus for weapon based on material
*/
OBJ_DATA * fix_material_bonus(OBJ_DATA * obj, int material_type)
{
obj->value[1] += rig_material_table[material_type].weapon_damage;
obj->value[2] += rig_material_table[material_type].weapon_damage;
item_hit_dam_bonus2(obj, rig_material_table[material_type].weapon_damage);
return obj;
}
/*
* item_hit_dam_bonus()
*
* adds an affect data for bonus hit/dam
*/
OBJ_DATA * item_hit_dam_bonus2(OBJ_DATA * obj, int value)
{
AFFECT_DATA af;
af.where = TO_OBJECT;
af.location = APPLY_HITROLL;
af.modifier = value;
af.level = obj->level;
af.type = 13;
af.duration = -1;
af.bitvector = 0;
affect_to_obj (obj, &af);
af.location = APPLY_DAMROLL;
affect_to_obj (obj, &af);
return (obj);
}