EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FactoryDB.cpp
Go to the documentation of this file.
1 
10 /*
11  * # Manufacturing Logging:
12  * MANUF__ERROR
13  * MANUF__WARNING
14  * MANUF__MESSAGE
15  * MANUF__INFO
16  * MANUF__DEBUG
17  * MANUF__TRACE
18  * MANUF__DUMP
19  */
20 
21 
22 #include "eve-server.h"
23 
24 #include "EVEServerConfig.h"
25 #include "character/Character.h"
27 
29 bool FactoryDB::IsProducableBy(const uint32 assemblyLineID, const ItemType *pType) {
30  Rsp_InstallJob into;
31  return FactoryDB::GetMultipliers(assemblyLineID, pType, into);
32 }
33 
35 {
36  if (!sDatabase.RunQuery(res, "SELECT typeID, typeName FROM invTypes WHERE groupID IN (754, 966)"))
37  codelog(DATABASE__ERROR, "Error in GetSalvage query: %s", res.error.c_str());
38 }
39 
41 {
42  if (!sDatabase.RunQuery(res, "SELECT typeID, typeName FROM invTypes WHERE groupID IN (282, 333, 423, 427, 530, 711, 712)"))
43  codelog(DATABASE__ERROR, "Error in GetCompounds query: %s", res.error.c_str());
44 }
45 
47 {
48  if (!sDatabase.RunQuery(res, "SELECT typeID, typeName FROM invTypes WHERE groupID = 18 AND published = 1")) // minerals
49  codelog(DATABASE__ERROR, "Error in GetMinerals query: %s", res.error.c_str());
50 }
51 
53 {
54  if (!sDatabase.RunQuery(res, "SELECT typeID, typeName FROM invTypes WHERE groupID IN (280, 283, 313, 334, 428, 429, 526, 536, 873, 886, 913, 964)")) // components
55  codelog(DATABASE__ERROR, "Error in GetComponents query: %s", res.error.c_str());
56 }
57 
59 {
60  if (!sDatabase.RunQuery(res, "SELECT typeID, typeName FROM invTypes WHERE groupID IN (1042, 1034, 1040, 1041)")) // PI Commodities
61  codelog(DATABASE__ERROR, "Error in GetCommodities query: %s", res.error.c_str());
62 }
63 
65 {
66  if (!sDatabase.RunQuery(res, "SELECT typeID, typeName FROM invTypes WHERE groupID = 314"))
67  codelog(DATABASE__ERROR, "Error in GetMinerals query: %s", res.error.c_str());
68 }
69 
71 {
72  if (!sDatabase.RunQuery(res, "SELECT typeID, typeName FROM invTypes WHERE groupID IN (1031, 1032, 1033, 1035)")) // PI Resources
73  codelog(DATABASE__ERROR, "Error in GetResources query: %s", res.error.c_str());
74 }
75 
77 {
78  if (!sDatabase.RunQuery(res, "SELECT typeID, materialTypeID, quantity FROM invTypeMaterials"))
79  codelog(DATABASE__ERROR, "Error in GetRAMMaterials query: %s", res.error.c_str());
80 }
81 
83 {
84  if (!sDatabase.RunQuery(res, "SELECT typeID, activityID, requiredTypeID, quantity, damagePerJob, extra FROM ramTypeRequirements"))
85  codelog(DATABASE__ERROR, "Error in GetRAMRequirements query: %s", res.error.c_str());
86 }
87 
88 void FactoryDB::SetJobEventID(const uint32 jobID, const uint32 eventID)
89 {
90  DBerror err;
91  sDatabase.RunQuery(err, "UPDATE ramJobs SET eventID=%u WHERE jobID=%u", eventID, jobID);
92 }
93 
95  DBerror err;
96  if(!sDatabase.RunQuery(err, "DELETE FROM invBlueprints WHERE itemID=%u", blueprintID)) {
97  _log(DATABASE__ERROR, "Failed to delete blueprint %u: %s.", blueprintID, err.c_str());
98  return false;
99  }
100  return true;
101 }
102 
104  DBQueryResult res;
105 
106  if(!sDatabase.RunQuery(res,
107  "SELECT requiredTypeID AS typeID, quantity"
108  " FROM ramTypeRequirements"
109  " WHERE typeID = (SELECT blueprintTypeID FROM invBlueprintTypes WHERE productTypeID = %u)"
110  " AND activityID = 1 AND damagePerJob = 1",
111  typeID))
112  {
113  _log(DATABASE__ERROR, "Could not retrieve material composition for type %u : %s", typeID, res.error.c_str());
114  return nullptr;
115  }
116 
117  return DBResultToRowset(res);
118 }
119 
121  DBerror err;
122  if(!sDatabase.RunQuery(err,
123  "INSERT INTO invBlueprints"
124  " (itemID, copy, mLevel, pLevel, runs)"
125  " VALUES"
126  " (%u, %u, %i, %i, %i)"
127  "ON DUPLICATE KEY UPDATE "
128  "mLevel=VALUES(mLevel), "
129  "pLevel=VALUES(pLevel), "
130  "runs=VALUES(runs) ",
131  blueprintID, data.copy, data.mLevel, data.pLevel, data.runs))
132  {
133  codelog(DATABASE__ERROR, "Error in SaveBlueprint query: %s.", err.c_str());
134  return false;
135  }
136 
137  return true;
138 }
139 
141  DBQueryResult res;
142  if(!sDatabase.RunQuery(res,
143  "SELECT"
144  " copy,"
145  " mLevel,"
146  " pLevel,"
147  " runs"
148  " FROM invBlueprints"
149  " WHERE itemID=%u",
150  blueprintID))
151  {
152  codelog(DATABASE__ERROR, "Error in GetBlueprint query: %s.", res.error.c_str());
153  return false;
154  }
155 
156  DBResultRow row;
157  if (!res.GetRow(row)) {
158  _log(DATABASE__MESSAGE, "Blueprint %u not found.", blueprintID);
159  return false;
160  }
161 
162  into.copy = row.GetBool(0);
163  into.mLevel = row.GetInt(1);
164  into.pLevel = row.GetInt(2);
165  into.runs = row.GetInt(3);
166 
167  return true;
168 }
169 
171  if (!sDatabase.RunQuery(res,
172  "SELECT"
173  " blueprintTypeID,"
174  " parentBlueprintTypeID,"
175  " productTypeID,"
176  " productionTime,"
177  " techLevel,"
178  " researchProductivityTime,"
179  " researchMaterialTime,"
180  " researchCopyTime,"
181  " researchTechTime,"
182  " productivityModifier,"
183  " materialModifier,"
184  " wasteFactor,"
185  " maxProductionLimit, "
186  " chanceOfRE,"
187  " g.categoryID"
188  " FROM invBlueprintTypes AS bt"
189  " LEFT JOIN invTypes AS t ON t.typeID = bt.blueprintTypeID"
190  " LEFT JOIN invGroups AS g USING (groupID)"))
191  //" WHERE t.published = 1" ))
192  {
193  codelog(DATABASE__ERROR, "Error in GetBlueprintType query: %s.", res.error.c_str());
194  }
195 }
196 
197 PyRep *FactoryDB::GetJobs2(const int32 ownerID, const bool completed)
198 {
199  DBQueryResult res;
200 
201  if (!sDatabase.RunQuery(res,
202  "SELECT"
203  " job.jobID,"
204  " job.assemblyLineID,"
205  " assemblyLine.containerID,"
206  " job.installedItemID,"
207  " installedItem.typeID AS installedItemTypeID,"
208  " installedItem.ownerID AS installedItemOwnerID,"
209  " blueprint.pLevel AS installedItemProductivityLevel,"
210  " blueprint.mLevel AS installedItemMaterialLevel,"
211  // quite ugly, but lets us use DBResultToRowset
212  " IF(assemblyLine.activityID = 1, blueprintType.productTypeID, installedItem.typeID) AS outputTypeID,"
213  " job.outputFlag,"
214  " job.installerID,"
215  " assemblyLine.activityID,"
216  " job.runs,"
217  " job.installTime,"
218  " job.beginProductionTime,"
219  " job.pauseProductionTime,"
220  " job.endProductionTime,"
221  " job.completedStatusID != 0 AS completed,"
222  " job.licensedProductionRuns,"
223  " station.solarSystemID AS installedInSolarSystemID,"
224  " job.completedStatusID AS completedStatus,"
225  " station.stationTypeID AS containerTypeID,"
226  " station.solarSystemID AS containerLocationID"
227  " FROM ramJobs AS job"
228  " LEFT JOIN entity AS installedItem ON job.installedItemID = installedItem.itemID"
229  " LEFT JOIN ramAssemblyLines AS assemblyLine ON job.assemblyLineID = assemblyLine.assemblyLineID"
230  " LEFT JOIN invBlueprints AS blueprint ON installedItem.itemID = blueprint.itemID"
231  " LEFT JOIN invBlueprintTypes AS blueprintType ON installedItem.typeID = blueprintType.blueprintTypeID"
232  " LEFT JOIN ramAssemblyLineStations AS station ON assemblyLine.containerID = station.stationID"
233  " WHERE job.ownerID = %u"
234  " AND job.completedStatusID %s 0"
235  " GROUP BY job.jobID",
236  ownerID, (completed ? "!=" : "=") ))
237  {
238  _log(DATABASE__ERROR, "Failed to query jobs for owner %u: %s", ownerID, res.error.c_str());
239  return nullptr;
240  }
241 
242  return DBResultToRowset(res);
243 }
244 
246  DBQueryResult res;
247 
248  if (!sDatabase.RunQuery(res,
249  "SELECT"
250  " station.stationID AS containerID,"
251  " station.stationTypeID AS containerTypeID,"
252  " station.solarSystemID AS containerLocationID,"
253  " station.assemblyLineTypeID,"
254  " station.quantity,"
255  " station.ownerID,"
256  " types.activityID"
257  " FROM ramAssemblyLineStations AS station"
258  " LEFT JOIN crpNPCCorporations AS corp ON station.ownerID = corp.corporationID"
259  " LEFT JOIN ramAssemblyLineTypes as types ON station.assemblyLineTypeID = types.assemblyLineTypeID"
260  " WHERE station.ownerID = corp.corporationID"
261  " AND station.regionID = %u",
262  regionID))
263  {
264  _log(DATABASE__ERROR, "Failed to query public assembly lines for region %u: %s.", regionID, res.error.c_str());
265  return nullptr;
266  }
267 
268  return DBResultToCRowset(res);
269 }
270 
272  DBQueryResult res;
273 
274  if (!sDatabase.RunQuery(res,
275  "SELECT"
276  " station.stationID AS containerID,"
277  " station.stationTypeID AS containerTypeID,"
278  " station.solarSystemID AS containerLocationID,"
279  " station.assemblyLineTypeID,"
280  " station.quantity,"
281  " station.ownerID"
282  " FROM ramAssemblyLineStations AS station"
283  " LEFT JOIN ramAssemblyLines AS line ON station.stationID = line.containerID AND station.assemblyLineTypeID = line.assemblyLineTypeID AND station.ownerID = line.ownerID"
284  " WHERE station.ownerID = %u"
285  " AND (line.restrictionMask & %u) = %u",
287  {
288  _log(DATABASE__ERROR, "Failed to query personal assembly lines for char %u: %s.", charID, res.error.c_str());
289  return nullptr;
290  }
291 
292  return DBResultToCRowset(res);
293 }
294 
296  DBQueryResult res;
297 
298  if (!sDatabase.RunQuery(res,
299  "SELECT"
300  " station.stationID AS containerID,"
301  " station.stationTypeID AS containerTypeID,"
302  " station.solarSystemID AS containerLocationID,"
303  " station.assemblyLineTypeID,"
304  " station.quantity,"
305  " station.ownerID"
306  " FROM ramAssemblyLineStations AS station"
307  " LEFT JOIN ramAssemblyLines AS line ON station.stationID = line.containerID AND station.assemblyLineTypeID = line.assemblyLineTypeID AND station.ownerID = line.ownerID"
308  " WHERE station.ownerID = %u",
309  charID))
310  {
311  _log(DATABASE__ERROR, "Failed to query private assembly lines for char %u: %s.", charID, res.error.c_str());
312  return nullptr;
313  }
314 
315  return DBResultToCRowset(res);
316 }
317 
320  DBQueryResult res;
321 
322  if (!sDatabase.RunQuery(res,
323  "SELECT"
324  " station.stationID AS containerID,"
325  " station.stationTypeID AS containerTypeID,"
326  " station.solarSystemID AS containerLocationID,"
327  " station.assemblyLineTypeID,"
328  " station.quantity,"
329  " station.ownerID"
330  " FROM ramAssemblyLineStations AS station"
331  " LEFT JOIN ramAssemblyLines AS line ON station.stationID = line.containerID AND station.assemblyLineTypeID = line.assemblyLineTypeID AND station.ownerID = line.ownerID"
332  " WHERE station.ownerID = %u"
333  " AND (line.restrictionMask & %u) = %u",
335  {
336  _log(DATABASE__ERROR, "Failed to query corporation assembly lines for corp %u: %s.", corpID, res.error.c_str());
337  return nullptr;
338  }
339 
340  return DBResultToCRowset(res);
341 }
342 
345  DBQueryResult res;
346 
347  if (!sDatabase.RunQuery(res,
348  "SELECT"
349  " station.stationID AS containerID,"
350  " station.stationTypeID AS containerTypeID,"
351  " station.solarSystemID AS containerLocationID,"
352  " station.assemblyLineTypeID,"
353  " station.quantity,"
354  " station.ownerID"
355  " FROM ramAssemblyLineStations AS station"
356  " LEFT JOIN crpCorporation AS crp ON station.ownerID = crp.corporationID"
357  " LEFT JOIN ramAssemblyLines AS line ON station.stationID = line.containerID AND station.assemblyLineTypeID = line.assemblyLineTypeID AND station.ownerID = line.ownerID"
358  " WHERE crp.allianceID = %u"
359  " AND (line.restrictionMask & %u) = %u",
361  {
362  _log(DATABASE__ERROR, "Failed to query alliance assembly lines for alliance %u: %s.", allianceID, res.error.c_str());
363  return nullptr;
364  }
365 
366  return DBResultToCRowset(res);
367 }
368 
371  DBQueryResult res;
372 
373  if (!sDatabase.RunQuery(res,
374  "SELECT"
375  " assemblyLineID,"
376  " assemblyLineTypeID,"
377  " containerID,"
378  " nextFreeTime,"
379  " costInstall,"
380  " costPerHour,"
381  " restrictionMask,"
382  " discountPerGoodStandingPoint,"
383  " surchargePerBadStandingPoint,"
384  " minimumStanding,"
385  " minimumCharSecurity,"
386  " minimumCorpSecurity,"
387  " maximumCharSecurity,"
388  " maximumCorpSecurity"
389  " FROM ramAssemblyLines"
390  " WHERE containerID = %u",
391  containerID)) {
392  _log(DATABASE__ERROR, "Failed to query assembly lines for container %u: %s.", containerID, res.error.c_str());
393  return nullptr;
394  }
395 
396  return DBResultToCRowset(res);
397 }
398 
400 bool FactoryDB::GetAssemblyLineProperties(const uint32 assemblyLineID, Character* pChar, Rsp_InstallJob& into, bool isCorpJob/*false*/) {
401  DBQueryResult res;
402  if (!sDatabase.RunQuery(res,
403  "SELECT"
404  " alt.baseMaterialMultiplier,"
405  " alt.baseTimeMultiplier,"
406  " al.costInstall,"
407  " alt.minCostPerHour,"
408  " al.costPerHour,"
409  " al.ownerID," //5
410  " al.discountPerGoodStandingPoint,"
411  " al.surchargePerBadStandingPoint"
412  " FROM ramAssemblyLines AS al"
413  " LEFT JOIN ramAssemblyLineTypes AS alt USING (assemblyLineTypeID)"
414  " WHERE al.assemblyLineID = %u",
415  assemblyLineID))
416  {
417  _log(DATABASE__ERROR, "Failed to query properties for assembly line %u: %s.", assemblyLineID, res.error.c_str());
418  return false;
419  }
420 
421  DBResultRow row;
422  if (!res.GetRow(row)) {
423  _log(DATABASE__ERROR, "No properties found for assembly line %u.", assemblyLineID);
424  return false;
425  }
426 
427  into.materialMultiplier = row.GetFloat(0);
428  into.timeMultiplier = row.GetFloat(1);
429  into.installCost = row.GetFloat(2);
430  if (row.GetFloat(3) > row.GetFloat(4)) { //min of base cost/hr vs minimum cost/hr
431  into.usageCost = row.GetFloat(3);
432  } else {
433  into.usageCost = row.GetFloat(4);
434  }
435 
436  // verify line standings modifiers (some have no modifiers)
437  if ((row.GetFloat(6) == 0) and (row.GetFloat(7) == 0))
438  return true;
439 
440  float standing(1), costModifier(1);
441  uint32 factionID(sDataMgr.GetCorpFaction(row.GetInt(5)));
442  if (isCorpJob) {
443  // this is only for PC corps. take higher of (npc faction to pc corp)/2 or npc corp to pc corp
444  float cStanding(StandingDB::GetStanding(row.GetInt(5), pChar->corporationID()));
445  float fStanding(StandingDB::GetStanding(factionID, pChar->corporationID()));
446  fStanding /= 2;
447  // this works for negative standings also
448  if (cStanding > fStanding) {
449  standing = cStanding;
450  } else {
451  standing = fStanding;
452  }
453 
455  // modify end result by 25% for char standings with station owner
456  standing *= (1 - (0.025f * StandingDB::GetStanding(row.GetInt(5), pChar->itemID())));
457  } else {
458  // else take personal standings with station corp only
459  standing = StandingDB::GetStanding(row.GetInt(5), pChar->itemID());
460  }
461 
462  if (standing < 0) {
463  costModifier += row.GetFloat(7) * -standing;
464  } else {
465  costModifier -= row.GetFloat(6) * standing;
466  }
467 
468  // make sure costModifier isnt 0 (some lines have 0 as modifier)
469  if (costModifier == 0)
470  costModifier = 1;
471 
472  _log(MANUF__MESSAGE, "FactoryDB::GetALProps() - Cost Modifier %.2f, standing %.2f", costModifier, standing);
473 
474  // modify setup cost based on standings
475  into.installCost *= costModifier;
476 
477  return true;
478 }
479 
482  DBQueryResult res;
483 
484  if (!sDatabase.RunQuery(res,
485  "SELECT"
486  " ownerID,"
487  " minimumStanding,"
488  " minimumCharSecurity,"
489  " maximumCharSecurity,"
490  " minimumCorpSecurity,"
491  " maximumCorpSecurity,"
492  " restrictionMask,"
493  " activityID"
494  " FROM ramAssemblyLines"
495  " WHERE assemblyLineID = %i",
496  assemblyLineID))
497  {
498  _log(DATABASE__ERROR, "Failed to query verify properties for assembly line %u: %s.", assemblyLineID, res.error.c_str());
499  return false;
500  }
501 
502  DBResultRow row;
503  if (!res.GetRow(row)) {
504  _log(DATABASE__ERROR, "No verify properties found for assembly line %u.", assemblyLineID);
505  return false;
506  }
507 
508  data.ownerID = row.GetUInt(0);
509  data.minStanding = row.GetFloat(1);
510  data.minCharSec = row.GetFloat(2);
511  data.maxCharSec = row.GetFloat(3);
512  data.minCorpSec = row.GetFloat(4);
513  data.maxCorpSec = row.GetFloat(5);
514  data.rMask = row.GetUInt(6);
515  data.activityID = row.GetUInt(7);
516 
517  return true;
518 }
519 
520 uint32 FactoryDB::InstallJob(const uint32 ownerID, const uint32 installerID, Call_InstallJob& args,
521  const int64 beginTime, const int64 endTime, const uint32 systemID)
522 {
523  DBerror err;
524  uint32 jobID(0);
525  // insert job
526  if (!sDatabase.RunQueryLID(err, jobID,
527  "INSERT INTO ramJobs"
528  " (ownerID, installerID, assemblyLineID, installedItemID, installTime, beginProductionTime, endProductionTime,"
529  " runs, outputFlag, licensedProductionRuns, completedStatusID, installedInSolarSystemID)"
530  " VALUES"
531  " (%u, %u, %i, %i, %.0f, %li, %li,"
532  " %i, %i, %i, 0, %i)",
533  ownerID, installerID, args.AssemblyLineID, args.bpItemID, GetFileTimeNow(), beginTime, endTime,
534  args.runs, args.outputFlag, args.copyRuns, systemID))
535  {
536  _log(DATABASE__ERROR, "Failed to insert new job to database: %s.", err.c_str());
537  return 0;
538  }
539 
540  // update nextFreeTime
541  if (!sDatabase.RunQuery(err,
542  "UPDATE ramAssemblyLines"
543  " SET nextFreeTime = %li"
544  " WHERE assemblyLineID = %i",
545  endTime, args.AssemblyLineID))
546  {
547  _log(DATABASE__ERROR, "Failed to update next free time for assembly line %u: %s.", args.AssemblyLineID, err.c_str());
548  return 0;
549  }
550 
551  return jobID;
552 }
553 
555  DBQueryResult res;
556 
557  if (!sDatabase.RunQuery(res,
558  "SELECT"
559  " COUNT(job.jobID)"
560  " FROM ramJobs AS job"
561  " LEFT JOIN ramAssemblyLines AS line USING (assemblyLineID)"
562  " WHERE job.installerID = %u"
563  " AND job.completedStatusID = 0"
564  " AND line.activityID = 1",
565  installerID))
566  {
567  _log(DATABASE__ERROR, "Failed to count manufacturing jobs for installer %u.", installerID);
568  return 0;
569  }
570 
571  DBResultRow row;
572  if (!res.GetRow(row)) {
573  _log(DATABASE__ERROR, "No rows returned while counting manufacturing jobs for installer %u.", installerID);
574  return 0;
575  }
576 
577  return row.GetUInt(0);
578 }
580  DBQueryResult res;
581 
582  if (!sDatabase.RunQuery(res,
583  "SELECT"
584  " COUNT(job.jobID)"
585  " FROM ramJobs AS job"
586  " LEFT JOIN ramAssemblyLines AS line USING (assemblyLineID)"
587  " WHERE job.installerID = %u"
588  " AND job.completedStatusID = 0"
589  " AND line.activityID != 1", // is this accurate?
590  installerID))
591  {
592  _log(DATABASE__ERROR, "Failed to count research jobs for installer %u.", installerID);
593  return 0;
594  }
595 
596  DBResultRow row;
597  if (!res.GetRow(row))
598  return 0;
599 
600  return row.GetUInt(0);
601 }
602 
604  DBQueryResult res;
605  if (!sDatabase.RunQuery(res,
606  "SELECT job.installedItemID, job.ownerID, job.outputFlag, job.runs, job.licensedProductionRuns,"
607  " job.endProductionTime, job.completedStatusID, line.activityID, job.eventID"
608  " FROM ramJobs AS job"
609  " LEFT JOIN ramAssemblyLines AS line USING (assemblyLineID)"
610  " WHERE job.jobID = %u",
611  jobID))
612  {
613  _log(DATABASE__ERROR, "Failed to query properties of job %u: %s.", jobID, res.error.c_str());
614  return false;
615  }
616 
617  DBResultRow row;
618  if (!res.GetRow(row)) {
619  _log(DATABASE__ERROR, "No properties found for job %u.", jobID);
620  return false;
621  }
622 
623  data.itemID = row.GetUInt(0);
624  data.ownerID = row.GetUInt(1);
625  data.outputFlag = (EVEItemFlags)row.GetUInt(2);
626  data.jobRuns = row.GetInt(3);
627  data.licensedRuns = row.GetInt(4);
628  data.endTime = row.GetInt64(5);
629  data.status = row.GetInt(6);
630  data.activity = row.GetUInt(7);
631  data.eventID = row.GetUInt(8);
632 
633  return true;
634 }
635 
636 bool FactoryDB::CompleteJob(const uint32 jobID, const int8 completedStatus) {
637  DBerror err;
638 
639  if (!sDatabase.RunQuery(err, "UPDATE ramJobs SET completedStatusID = %i WHERE jobID = %u", completedStatus, jobID)) {
640  _log(DATABASE__ERROR, "Failed to complete job %u (status = %i): %s.", jobID, completedStatus, err.c_str());
641  return false;
642  }
643 
644  return true;
645 }
646 
648  DBQueryResult res;
649 
650  if (!sDatabase.RunQuery(res, "SELECT blueprintTypeID FROM invBlueprintTypes WHERE parentBlueprintTypeID = %u", blueprintTypeID)) {
651  _log(DATABASE__ERROR, "Unable to get T2 type for type ID %u: %s", blueprintTypeID, res.error.c_str());
652  return 0;
653  }
654 
655  DBResultRow row;
656  if (!res.GetRow(row))
657  return 0;
658 
659  return row.GetUInt(0);
660 }
661 
662 int64 FactoryDB::GetNextFreeTime(const uint32 assemblyLineID) {
663  DBQueryResult res;
664  if (!sDatabase.RunQuery(res, "SELECT nextFreeTime FROM ramAssemblyLines WHERE assemblyLineID = %u", assemblyLineID)) {
665  _log(DATABASE__ERROR, "Failed to query next free time for assembly line %u: %s.", assemblyLineID, res.error.c_str());
666  return 0;
667  }
668 
669  DBResultRow row;
670  if (!res.GetRow(row)) {
671  _log(DATABASE__ERROR, "Assembly line %u not found.", assemblyLineID);
672  return 0;
673  }
674 
675  return (row.IsNull(0) ? 0 : row.GetInt64(0));
676 }
677 
678 bool FactoryDB::GetMultipliers(const uint32 assemblyLineID, const ItemType* pType, Rsp_InstallJob& into) {
679  DBQueryResult res;
680  // check Category first
681  if (!sDatabase.RunQuery(res,
682  "SELECT alc.materialMultiplier, alc.timeMultiplier"
683  " FROM ramAssemblyLineTypeDetailPerCategory AS alc"
684  " LEFT JOIN ramAssemblyLines AS al USING (assemblyLineTypeID)"
685  " WHERE al.assemblyLineID = %u AND alc.categoryID = %u",
686  assemblyLineID, pType->categoryID()))
687  {
688  _log(DATABASE__ERROR, "Failed to check producability of cat %u by line %u: %s", pType->categoryID(), assemblyLineID, res.error.c_str());
689  return false;
690  }
691 
692  DBResultRow row;
693  if (res.GetRow(row)) {
694  into.materialMultiplier *= row.GetDouble(0);
695  into.timeMultiplier *= row.GetDouble(1);
696  }
697 
698  // then Group (all materialMultiplier = 1)
699  if (!sDatabase.RunQuery(res,
700  "SELECT alg.materialMultiplier, alg.timeMultiplier"
701  " FROM ramAssemblyLineTypeDetailPerGroup AS alg"
702  " LEFT JOIN ramAssemblyLines AS al USING (assemblyLineTypeID)"
703  " WHERE al.assemblyLineID = %u"
704  " AND alg.groupID = %u",
705  assemblyLineID, pType->groupID()))
706  {
707  _log(DATABASE__ERROR, "Failed to check producability of group %u by line %u: %s", pType->groupID(), assemblyLineID, res.error.c_str());
708  return false;
709  }
710 
711  if (res.GetRow(row)) {
712  into.materialMultiplier *= row.GetDouble(0);
713  into.timeMultiplier *= row.GetDouble(1);
714  }
715 
716  return true;
717 }
718 
720  DBQueryResult res;
721  if (!sDatabase.RunQuery(res,
722  "SELECT NULL"
723  " FROM ramTypeRequirements"
724  " WHERE typeID=%u"
725  " AND extra = 0"
726  " LIMIT 1",
727  typeID))
728  {
729  _log(DATABASE__ERROR, "Failed to check ore type ID: %s.", res.error.c_str());
730  return false;
731  }
732 
733  DBResultRow row;
734  return (res.GetRow(row));
735 }
736 
738  DBQueryResult res;
739  if (!sDatabase.RunQuery(res,
740  "SELECT NULL FROM ramTypeRequirements"
741  " LEFT JOIN invBlueprintTypes ON typeID = blueprintTypeID"
742  " WHERE damagePerJob = 1 AND activityID = 6 AND typeID = %u"
743  " AND extra = 1"
744  " LIMIT 1",
745  typeID))
746  {
747  _log(DATABASE__ERROR, "Failed to check item type ID: %s.", res.error.c_str());
748  return false;
749  }
750 
751  DBResultRow row;
752  if (res.GetRow(row))
753  return true;
754 
755  if (!sDatabase.RunQuery(res,
756  "SELECT NULL FROM ramTypeRequirements"
757  " LEFT JOIN invBlueprintTypes ON typeID = blueprintTypeID"
758  " WHERE damagePerJob = 1 AND activityID = 1 AND productTypeID = %u"
759  " AND extra = 1"
760  " LIMIT 1",
761  typeID))
762  {
763  _log(DATABASE__ERROR, "Failed to check item type ID: %s.", res.error.c_str());
764  return false;
765  }
766 
767  return (res.GetRow(row));
768 }
static float GetStanding(uint32 fromID, uint32 toID)
Definition: StandingDB.cpp:142
Base Python wire object.
Definition: PyRep.h:66
static PyRep * GetMaterialCompositionOfItemType(const uint32 typeID)
Definition: FactoryDB.cpp:103
static PyRep * AssemblyLinesSelectCorporation(const uint32 corporationID)
Definition: FactoryDB.cpp:319
#define sDatabase
Definition: dbcore.h:199
static void GetMinerals(DBQueryResult &res)
Definition: FactoryDB.cpp:46
static bool GetMultipliers(const uint32 assemblyLineID, const ItemType *pType, Rsp_InstallJob &into)
Definition: FactoryDB.cpp:678
#define _log(type, fmt,...)
Definition: logsys.h:124
float GetFloat(uint32 index) const
Definition: dbcore.cpp:682
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
uint16 groupID() const
Definition: ItemType.h:64
static uint32 CountManufacturingJobs(const uint32 installerID)
Definition: FactoryDB.cpp:554
static bool IsProducableBy(const uint32 assemblyLineID, const ItemType *pType)
Definition: FactoryDB.cpp:29
uint32 ownerID() const
Definition: InventoryItem.h:99
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
double GetDouble(uint32 index) const
Definition: dbcore.cpp:693
EVEItemFlags
Definition: EVE_Flags.h:13
static bool IsRecyclable(const uint16 typeID)
Definition: FactoryDB.cpp:737
static void GetComponents(DBQueryResult &res)
Definition: FactoryDB.cpp:52
static uint32 GetTech2Blueprint(const uint32 blueprintTypeID)
Definition: FactoryDB.cpp:647
static PyRep * AssemblyLinesSelectPersonal(const uint32 charID)
Definition: FactoryDB.cpp:271
static void GetRAMMaterials(DBQueryResult &res)
Definition: FactoryDB.cpp:76
static uint32 InstallJob(const uint32 ownerID, const uint32 installerID, Call_InstallJob &args, const int64 beginTime, const int64 endTime, const uint32 systemID)
Definition: FactoryDB.cpp:520
static PyRep * AssemblyLinesSelectPublic(const uint32 regionID)
Definition: FactoryDB.cpp:245
static bool GetBlueprint(uint32 blueprintID, EvERam::bpData &into)
Definition: FactoryDB.cpp:140
signed __int8 int8
Definition: eve-compat.h:45
static bool IsRefinable(const uint16 typeID)
Definition: FactoryDB.cpp:719
static bool GetJobProperties(const uint32 jobID, EvERam::JobProperties &data)
Definition: FactoryDB.cpp:603
uint8 categoryID() const
Definition: ItemType.h:66
signed __int32 int32
Definition: eve-compat.h:49
* args
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
static PyRep * GetJobs2(const int32 ownerID, const bool completed)
Definition: FactoryDB.cpp:197
bool GetBool(uint32 index) const
Definition: dbcore.cpp:647
static void GetBlueprintType(DBQueryResult &res)
Definition: FactoryDB.cpp:170
static bool DeleteBlueprint(uint32 blueprintID)
Definition: FactoryDB.cpp:94
static uint32 CountResearchJobs(const uint32 installerID)
Definition: FactoryDB.cpp:579
const char * c_str() const
Definition: dbcore.h:48
static int64 GetNextFreeTime(const uint32 assemblyLineID)
Definition: FactoryDB.cpp:662
#define codelog(type, fmt,...)
Definition: logsys.h:128
PyObject * DBResultToRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:81
static void GetCommodities(DBQueryResult &res)
Definition: FactoryDB.cpp:58
static bool SaveBlueprintData(uint32 blueprintID, EvERam::bpData &data)
Definition: FactoryDB.cpp:120
bool IsNull(uint32 index) const
Definition: dbcore.h:102
EVEItemFlags outputFlag
Definition: EVE_RAM.h:102
unsigned __int32 uint32
Definition: eve-compat.h:50
uint32 corporationID() const
Definition: Character.h:300
static void GetRAMRequirements(DBQueryResult &res)
Definition: FactoryDB.cpp:82
double GetFileTimeNow()
Definition: utils_time.cpp:84
static void GetCompounds(DBQueryResult &res)
Definition: FactoryDB.cpp:40
static PyRep * AssemblyLinesGet(const uint32 containerID)
Definition: FactoryDB.cpp:370
DBerror error
Definition: dbcore.h:69
static PyRep * AssemblyLinesSelectAlliance(const int32 allianceID)
Definition: FactoryDB.cpp:344
signed __int64 int64
Definition: eve-compat.h:51
static void GetResources(DBQueryResult &res)
Definition: FactoryDB.cpp:70
static void SetJobEventID(const uint32 jobID, const uint32 eventID)
Definition: FactoryDB.cpp:88
static bool GetAssemblyLineProperties(const uint32 assemblyLineID, Character *pChar, Rsp_InstallJob &into, bool isCorpJob=false)
Definition: FactoryDB.cpp:400
static bool GetAssemblyLineRestrictions(const int32 assemblyLineID, EvERam::LineRestrictions &data)
Definition: FactoryDB.cpp:481
static PyRep * AssemblyLinesSelectPrivate(const uint32 charID)
Definition: FactoryDB.cpp:295
int16 runs
Definition: EVE_RAM.h:110
static void GetSalvage(DBQueryResult &res)
Definition: FactoryDB.cpp:34
int64 GetInt64(uint32 index) const
Definition: dbcore.cpp:670
unsigned __int16 uint16
Definition: eve-compat.h:48
uint16 typeID() const
static void GetMiscCommodities(DBQueryResult &res)
Definition: FactoryDB.cpp:64
Definition: dbcore.h:39
uint32 itemID() const
Definition: InventoryItem.h:98
#define sDataMgr
static bool CompleteJob(const uint32 jobID, const int8 completedStatus)
Definition: FactoryDB.cpp:636