Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d26b11e

Browse files
committed
diggingInvaders: cleaned up pick creation.
1 parent 638affe commit d26b11e

1 file changed

Lines changed: 62 additions & 58 deletions

File tree

plugins/diggingInvaders/assignJob.cpp

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "modules/Buildings.h"
44
#include "modules/Items.h"
55
#include "modules/Job.h"
6+
#include "modules/Materials.h"
67

78
#include "df/building.h"
89
#include "df/coord.h"
@@ -11,6 +12,7 @@
1112
#include "df/general_ref_unit.h"
1213
//#include "df/general_ref_unit_holderst.h"
1314
#include "df/general_ref_unit_workerst.h"
15+
#include "df/historical_entity.h"
1416
#include "df/item.h"
1517
#include "df/itemdef_weaponst.h"
1618
#include "df/item_quality.h"
@@ -19,8 +21,12 @@
1921
#include "df/job.h"
2022
#include "df/job_skill.h"
2123
#include "df/job_type.h"
24+
#include "df/reaction_product_itemst.h"
25+
#include "df/reaction_reagent.h"
26+
#include "df/ui.h"
2227
#include "df/unit.h"
2328
#include "df/unit_inventory_item.h"
29+
#include "df/world_site.h"
2430

2531
void getRidOfOldJob(df::unit* unit) {
2632
if ( unit->job.current_job == NULL ) {
@@ -202,66 +208,64 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_map<df:
202208
break;
203209
}
204210

205-
if ( !hasPick ) {
206-
//based on createitem
207-
//df::reaction_product_itemst *prod
208-
#if 1
209-
//create and give a pick
210-
df::item_weaponst* pick = new df::item_weaponst;
211-
pick->pos = firstInvader->pos;
212-
pick->flags.bits.forbid = 1;
213-
pick->flags.bits.on_ground = 1;
214-
pick->id = (*df::global::item_next_id)++;
215-
pick->ignite_point = -1;
216-
pick->heatdam_point = -1;
217-
pick->colddam_point = -1;
218-
pick->boiling_point = 11000;
219-
pick->melting_point = 10500;
220-
pick->fixed_temp = -1;
221-
pick->weight = 0;
222-
pick->weight_fraction = 0;
223-
pick->stack_size = 1;
224-
pick->temperature.whole = 10059;
225-
pick->temperature.fraction = 0;
226-
pick->mat_type = 0;
227-
pick->mat_index = 5;
228-
pick->maker_race = 0; //hehe
229-
pick->quality = (df::enums::item_quality::item_quality)0;
230-
pick->skill_used = (df::enums::job_skill::job_skill)0;
231-
pick->maker = -1;
232-
df::itemdef_weaponst* itemdef = NULL;
233-
for ( size_t a = 0; a < df::global::world->raws.itemdefs.weapons.size(); a++ ) {
234-
df::itemdef_weaponst* candidate = df::global::world->raws.itemdefs.weapons[a];
235-
if ( candidate->skill_melee != df::enums::job_skill::MINING )
236-
continue;
237-
238-
itemdef = candidate;
239-
}
240-
if ( itemdef == NULL ) {
241-
out.print("%s, %d: null itemdef.\n", __FILE__, __LINE__);
242-
return -1;
243-
}
244-
pick->subtype = itemdef;
245-
pick->sharpness = 5000;
246-
pick->categorize(true);
247-
248-
int32_t part = -1;
249-
part = firstInvader->body.weapon_bp; //weapon_bp
250-
if ( part == -1 ) {
251-
out.print("%s, %d: no grasp part.\n", __FILE__, __LINE__);
252-
return -1;
253-
}
254-
//check for existing item there
255-
for ( size_t a = 0; a < firstInvader->inventory.size(); a++ ) {
256-
df::unit_inventory_item* inv_item = firstInvader->inventory[a];
257-
if ( false || inv_item->body_part_id == part ) {
258-
//throw it on the GROUND
259-
Items::moveToGround(cache, inv_item->item, firstInvader->pos);
260-
}
211+
if ( hasPick )
212+
return firstInvader->id;
213+
214+
//create and give a pick
215+
//based on createitem.cpp
216+
df::reaction_product_itemst *prod = NULL;
217+
//TODO: consider filtering based on entity/civ stuff
218+
for ( size_t a = 0; a < df::global::world->raws.itemdefs.weapons.size(); a++ ) {
219+
df::itemdef_weaponst* oldType = df::global::world->raws.itemdefs.weapons[a];
220+
if ( oldType->skill_melee != df::enums::job_skill::MINING )
221+
continue;
222+
prod = df::allocate<df::reaction_product_itemst>();
223+
prod->item_type = df::item_type::WEAPON;
224+
prod->item_subtype = a;
225+
break;
226+
}
227+
if ( prod == NULL ) {
228+
out.print("%s, %d: no valid item.\n", __FILE__, __LINE__);
229+
return -1;
230+
}
231+
232+
DFHack::MaterialInfo material;
233+
if ( !material.find("WATER") ) {
234+
out.print("%s, %d: no water.\n", __FILE__, __LINE__);
235+
return -1;
236+
}
237+
prod->mat_type = material.type;
238+
prod->mat_index = material.index;
239+
prod->probability = 100;
240+
prod->count = 1;
241+
prod->product_dimension = 1;
242+
243+
vector<df::item*> out_items;
244+
vector<df::reaction_reagent*> in_reag;
245+
vector<df::item*> in_items;
246+
prod->produce(firstInvader, &out_items, &in_reag, &in_items, 1, df::job_skill::NONE,
247+
df::historical_entity::find(firstInvader->civ_id),
248+
df::world_site::find(df::global::ui->site_id));
249+
250+
if ( out_items.size() != 1 ) {
251+
out.print("%s, %d: wrong size: %d.\n", __FILE__, __LINE__, out_items.size());
252+
return -1;
253+
}
254+
out_items[0]->moveToGround(firstInvader->pos.x, firstInvader->pos.y, firstInvader->pos.z);
255+
256+
#if 0
257+
//check for existing item there
258+
for ( size_t a = 0; a < firstInvader->inventory.size(); a++ ) {
259+
df::unit_inventory_item* inv_item = firstInvader->inventory[a];
260+
if ( false || inv_item->body_part_id == part ) {
261+
//throw it on the ground
262+
Items::moveToGround(cache, inv_item->item, firstInvader->pos);
261263
}
262-
#endif
263-
Items::moveToInventory(cache, pick, firstInvader, df::unit_inventory_item::T_mode::Weapon, part);
264264
}
265+
#endif
266+
Items::moveToInventory(cache, out_items[0], firstInvader, df::unit_inventory_item::T_mode::Weapon, firstInvader->body.weapon_bp);
267+
268+
delete prod;
265269
}
266270
}
267271

0 commit comments

Comments
 (0)