diggingInvaders: cleaned up pick creation.

develop
expwnent 2013-06-09 17:20:23 -04:00
parent 638affee06
commit d26b11eb40
1 changed files with 62 additions and 58 deletions

@ -3,6 +3,7 @@
#include "modules/Buildings.h" #include "modules/Buildings.h"
#include "modules/Items.h" #include "modules/Items.h"
#include "modules/Job.h" #include "modules/Job.h"
#include "modules/Materials.h"
#include "df/building.h" #include "df/building.h"
#include "df/coord.h" #include "df/coord.h"
@ -11,6 +12,7 @@
#include "df/general_ref_unit.h" #include "df/general_ref_unit.h"
//#include "df/general_ref_unit_holderst.h" //#include "df/general_ref_unit_holderst.h"
#include "df/general_ref_unit_workerst.h" #include "df/general_ref_unit_workerst.h"
#include "df/historical_entity.h"
#include "df/item.h" #include "df/item.h"
#include "df/itemdef_weaponst.h" #include "df/itemdef_weaponst.h"
#include "df/item_quality.h" #include "df/item_quality.h"
@ -19,8 +21,12 @@
#include "df/job.h" #include "df/job.h"
#include "df/job_skill.h" #include "df/job_skill.h"
#include "df/job_type.h" #include "df/job_type.h"
#include "df/reaction_product_itemst.h"
#include "df/reaction_reagent.h"
#include "df/ui.h"
#include "df/unit.h" #include "df/unit.h"
#include "df/unit_inventory_item.h" #include "df/unit_inventory_item.h"
#include "df/world_site.h"
void getRidOfOldJob(df::unit* unit) { void getRidOfOldJob(df::unit* unit) {
if ( unit->job.current_job == NULL ) { if ( unit->job.current_job == NULL ) {
@ -202,66 +208,64 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_map<df:
break; break;
} }
if ( !hasPick ) { if ( hasPick )
//based on createitem return firstInvader->id;
//df::reaction_product_itemst *prod
#if 1 //create and give a pick
//create and give a pick //based on createitem.cpp
df::item_weaponst* pick = new df::item_weaponst; df::reaction_product_itemst *prod = NULL;
pick->pos = firstInvader->pos; //TODO: consider filtering based on entity/civ stuff
pick->flags.bits.forbid = 1; for ( size_t a = 0; a < df::global::world->raws.itemdefs.weapons.size(); a++ ) {
pick->flags.bits.on_ground = 1; df::itemdef_weaponst* oldType = df::global::world->raws.itemdefs.weapons[a];
pick->id = (*df::global::item_next_id)++; if ( oldType->skill_melee != df::enums::job_skill::MINING )
pick->ignite_point = -1; continue;
pick->heatdam_point = -1; prod = df::allocate<df::reaction_product_itemst>();
pick->colddam_point = -1; prod->item_type = df::item_type::WEAPON;
pick->boiling_point = 11000; prod->item_subtype = a;
pick->melting_point = 10500; break;
pick->fixed_temp = -1; }
pick->weight = 0; if ( prod == NULL ) {
pick->weight_fraction = 0; out.print("%s, %d: no valid item.\n", __FILE__, __LINE__);
pick->stack_size = 1; return -1;
pick->temperature.whole = 10059; }
pick->temperature.fraction = 0;
pick->mat_type = 0; DFHack::MaterialInfo material;
pick->mat_index = 5; if ( !material.find("WATER") ) {
pick->maker_race = 0; //hehe out.print("%s, %d: no water.\n", __FILE__, __LINE__);
pick->quality = (df::enums::item_quality::item_quality)0; return -1;
pick->skill_used = (df::enums::job_skill::job_skill)0; }
pick->maker = -1; prod->mat_type = material.type;
df::itemdef_weaponst* itemdef = NULL; prod->mat_index = material.index;
for ( size_t a = 0; a < df::global::world->raws.itemdefs.weapons.size(); a++ ) { prod->probability = 100;
df::itemdef_weaponst* candidate = df::global::world->raws.itemdefs.weapons[a]; prod->count = 1;
if ( candidate->skill_melee != df::enums::job_skill::MINING ) prod->product_dimension = 1;
continue;
vector<df::item*> out_items;
itemdef = candidate; vector<df::reaction_reagent*> in_reag;
} vector<df::item*> in_items;
if ( itemdef == NULL ) { prod->produce(firstInvader, &out_items, &in_reag, &in_items, 1, df::job_skill::NONE,
out.print("%s, %d: null itemdef.\n", __FILE__, __LINE__); df::historical_entity::find(firstInvader->civ_id),
return -1; df::world_site::find(df::global::ui->site_id));
}
pick->subtype = itemdef; if ( out_items.size() != 1 ) {
pick->sharpness = 5000; out.print("%s, %d: wrong size: %d.\n", __FILE__, __LINE__, out_items.size());
pick->categorize(true); return -1;
}
int32_t part = -1; out_items[0]->moveToGround(firstInvader->pos.x, firstInvader->pos.y, firstInvader->pos.z);
part = firstInvader->body.weapon_bp; //weapon_bp
if ( part == -1 ) { #if 0
out.print("%s, %d: no grasp part.\n", __FILE__, __LINE__); //check for existing item there
return -1; for ( size_t a = 0; a < firstInvader->inventory.size(); a++ ) {
} df::unit_inventory_item* inv_item = firstInvader->inventory[a];
//check for existing item there if ( false || inv_item->body_part_id == part ) {
for ( size_t a = 0; a < firstInvader->inventory.size(); a++ ) { //throw it on the ground
df::unit_inventory_item* inv_item = firstInvader->inventory[a]; Items::moveToGround(cache, inv_item->item, firstInvader->pos);
if ( false || inv_item->body_part_id == part ) {
//throw it on the GROUND
Items::moveToGround(cache, inv_item->item, firstInvader->pos);
}
} }
#endif
Items::moveToInventory(cache, pick, firstInvader, df::unit_inventory_item::T_mode::Weapon, part);
} }
#endif
Items::moveToInventory(cache, out_items[0], firstInvader, df::unit_inventory_item::T_mode::Weapon, firstInvader->body.weapon_bp);
delete prod;
} }
} }