Planeshift
workmanager.h
Go to the documentation of this file.
1 /*
2 * workmanager.h
3 *
4 * Copyright (C) 2001-2002 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 #ifndef __WORKMANAGER_H__
21 #define __WORKMANAGER_H__
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 #include <csutil/sysfunc.h>
27 
28 //=============================================================================
29 // Project Includes
30 //=============================================================================
31 
32 //=============================================================================
33 // Local Includes
34 //=============================================================================
35 #include "msgmanager.h" // Parent class
36 #include "gem.h"
37 
38 class psWorkGameEvent;
39 class WorkManager;
40 class psItem;
41 class Client;
43 
44 // Define the work event types
45 #define MANUFACTURE 0
46 #define PRODUCTION 1
47 #define LOCKPICKING 2
48 #define CLEANUP 3
49 #define REPAIR 4
50 
51 #define GARBAGE_PATTERNID 1
52 #define CLEANUP_DELAY 600
53 //#define CLEANUP_DELAY 10
54 
55 
61 {
62  TRANSFORM_MATCH = 0x0000,
75  TRANSFORM_BAD_USE = 0x1000,
79 };
80 
85 {
95 };
96 
97 //-----------------------------------------------------------------------------
98 
103 {
104  int sector;
105  csVector3 loc;
106  float radius;
108  float probability;
111  unsigned int item_cat_id;
112  float item_quality;
113  csString anim;
115  int reward;
116  csString reward_nickname;
117  size_t action;
118 };
120 
121 
126 {
127 public:
128  NearNaturalResource(NaturalResource* res, float distance) : resource(res), dist(distance) {}
130  float dist;
131  bool operator<(const NearNaturalResource &oth) const
132  {
133  if(oth.dist > dist)
134  return true;
135  if(oth.resource->probability > resource->probability)
136  return true;
137  if(oth.resource->skill_level > resource->skill_level)
138  return true;
139  return false;
140  }
141 };
142 
143 //-----------------------------------------------------------------------------
144 
146 {
147  bool (*constraintFunction)(WorkManager* that, char* param);
148  const char* name;
149  const char* message;
150 };
151 
152 //-----------------------------------------------------------------------------
153 
159 class WorkManager : public MessageManager<WorkManager>
160 {
161 public:
162 
163  WorkManager(CacheManager* cachemanager, EntityManager* entitymanager);
164  virtual ~WorkManager();
165 
166 //-----------------------------------------------------------------------------
167 // Entry points
168 //-----------------------------------------------------------------------------
169 
177  void HandleUse(Client* client);
178 
185  void HandleCombine(Client* client);
186 
194  void HandleConstruct(Client* client);
195 
208  void StartAutoWork(Client* client, gemContainer* container, psItem* autoItem, int count);
209 
218  bool StartScriptWork(Client* client, gemObject* target, csString pattern);
219 
228  void StopWork(Client* client, psItem* item);
229 
240  void HandleWorkEvent(psWorkGameEvent* workEvent);
241 
249  void HandleCleanupEvent(psWorkGameEvent* workEvent);
250 
258  void HandleProductionEvent(psWorkGameEvent* workEvent);
259 
273  void HandleRepairEvent(psWorkGameEvent* workEvent);
274  void LockpickComplete(psWorkGameEvent* workEvent);
275 
281  static bool constraintTime(WorkManager* that, char* param);
282  static bool constraintFriends(WorkManager* that,char* param);
283  static bool constraintLocation(WorkManager* that,char* param);
284  static bool constraintMode(WorkManager* that,char* param);
285  static bool constraintGender(WorkManager* that,char* param);
286  static bool constraintRace(WorkManager* that,char* param);
290  void StartLockpick(Client* client,psItem* item);
292 
293 
304  bool LoadLocalVars(Client* client, gemObject* target=NULL);
305 
306  /*
307  * Send clear client view message to remove items from autocontainers.
308  *
309  * @param slotID The slot number to clear.
310  * @param containerID The container ID that has item that needs to be cleared.
311  *
312  * @return False if there is a problem sending message.
313  *
314  bool SendClearUpdate( unsigned int slotID, unsigned int containerID ); */
315 
316 
318  void HandleProduction(gemActor* actor,const char* type,const char* reward);
319 
320 protected:
321  csPDelArray<NaturalResource> resources;
322 
326  csStringArray resourcesActions;
341 
342 
343  void HandleLockPick(MsgEntry* me,Client* client);
344  void HandleWorkCommand(MsgEntry* me,Client* client);
345 
355  void StopAutoWork(Client* client, psItem* autoItem);
356 
364  void StopUseWork(MsgEntry* me,Client* client);
365 
371  void StartUseWork(Client* client);
372 
379  void StopCombineWork(Client* client);
380 
386  void StartCombineWork(Client* client);
387 
393  void StartConstructWork(Client* client);
394 
401  void StopConstructWork(Client* client);
402 
410  void StopCleanupWork(Client* client, psItem* cleanItem);
411 
422  void SendTransformError(uint32_t clientNum, unsigned int result, uint32 curItemId = 0, int CurItemQty = 0);
423 
436  bool IsContainerCombinable(uint32 &resultId, int &resultQty);
437 
450  bool IsHandCombinable(uint32 &resultId, int &resultQty);
451 
462  bool ValidateCombination(csArray<psItem*> itemArray, uint32 &resultId, int &resultQty);
463 
474  bool AnyCombination(csArray<psItem*> itemArray, uint32 &resultId, int &resultQty);
475 
485  bool MatchCombinations(csArray<psItem*> itemArray, CombinationConstruction* current, int &multiplier);
486 
497  unsigned int AnyTransform(csArray<psTradePatterns*> &patterns, float &KFactor, uint32 targetId, int targetQty);
498 
508  unsigned int IsTransformable(uint32 patternId, uint32 targetId, int targetQty);
509 
510  bool ScriptNoTarget();
511  bool ScriptActor(gemActor* gemAct);
512  bool ScriptItem(gemItem* gemItm);
513  bool ScriptAction(gemActionLocation* gemAction);
514 
515  bool CombineWork();
516  bool IsIngredient(uint32 patternId, uint32 targetId);
517 
526  psItem* TransformSelfContainerItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process, psTradeTransformations* trans);
527 
536  psItem* TransformContainedItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process, psTradeTransformations* trans);
537 
545  psItem* CombineContainedItem(uint32 newId, int newQty, float itemQuality, psItem* containerItem);
546 
555  psItem* TransformSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process, psTradeTransformations* trans);
556 
565  psItem* TransformTargetSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process, psTradeTransformations* trans);
566 
575  psItem* TransformTargetItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process, psTradeTransformations* trans);
576 
577  void TransformTargetItemToNpc(psItem* workItem, Client* client);
578 
594  void ApplyProcessScript(psItem* oldItem, psItem* newItem, gemActor* worker, psTradeProcesses* process, psTradeTransformations* trans);
595 // bool TransformHandItem(uint32 newId, int newQty, float itemQuality);
596  //bool SendItemUpdate( INVENTORY_SLOT_NUMBER slotID, psItem *newItem );
597 
598  void StartTransformationEvent(int transType, INVENTORY_SLOT_NUMBER transSlot, int resultQty,
599  float resultQuality, psItem* autoItem);
600  void StartCleanupEvent(int transType, Client* client, psItem* item, gemActor* worker);
601 
602  bool ValidateTarget(Client* client);
603  bool ValidateWork();
604  bool ValidateMind();
605  bool ValidateStamina(Client* client);
606  bool IsOnHand(uint32 equipId);
607  psItem* CreateTradeItem(uint32 newId, int newQty, float itemQuality, bool transient = false);
608  bool ValidateTraining(psTradeTransformations* transCandidate, psTradeProcesses* processCandidate);
609  bool ValidateSkills(psTradeTransformations* transCandidate, psTradeProcesses* processCandidate);
610  bool ValidateNotOverSkilled(psTradeTransformations* transCandidate, psTradeProcesses* processCandidate);
611  bool ValidateConstraints(psTradeTransformations* transCandidate, psTradeProcesses* processCandidate);
612 
622  int CalculateEventDuration(psTradeTransformations* trans, psTradeProcesses* process, psItem* transItem, gemActor* worker);
623 
624  bool CheckStamina(psCharacter* owner) const;
625 
626  void Initialize();
627 
631  bool CalculateQuality(float factor, psItem* transItem, gemActor* worker, bool amountModifier, float &currentQuality, psTradeProcesses* process, psTradeTransformations* trans, csTicks time);
632 
647  void HandleRepair(gemActor* actor, Client* client, const csString &repairSlotName);
648 
667  void HandleProduction(gemActor* actor, size_t type,const char* reward, Client* client = NULL);
668 
669  bool SameProductionPosition(gemActor* actor, const csVector3 &startPos);
670 
679  csArray<NearNaturalResource> FindNearestResource(iSector* sector, csVector3 &pos, const size_t action, const char* reward = NULL);
680 
681 private:
682 
683  csWeakRef<gemActor> worker;
684 
685  uint32_t clientNum;
686  psItem* workItem;
687  psItem* autoItem;
688  gemActor* owner;
689  gemObject* gemTarget;
690  csArray<psTradePatterns*> patterns;
691  uint32 groupPatternId;
692  float patternKFactor;
693  float currentQuality;
694  psTradeTransformations* trans;
695  psTradeProcesses* process;
696  const char* preworkModeString;
697  bool secure;
698 
699  CacheManager* cacheManager;
700  EntityManager* entityManager;
701 };
702 
703 
704 
705 //-----------------------------------------------------------------------------
706 
709 {
710 public:
712  gemActor* worker,
713  int delayticks,
714  int cat,
715  csVector3 &pos,
716  csArray<NearNaturalResource>* natres=NULL,
717  Client* c=NULL,
718  psItem* object=NULL,
719  float repairAmount=0.0F);
720  virtual ~psWorkGameEvent();
721 
722  void Interrupt();
723 
724  virtual void Trigger();
725 
726  virtual void DeleteObjectCallback(iDeleteNotificationObject* object);
727 
730  {
731  transformation = t;
732  }
733 
736  {
737  return transformation;
738  }
739 
742  {
743  process = p;
744  }
745 
748  {
749  return process;
750  }
751 
754  {
755  return resultQuantity;
756  }
757  void SetResultQuantity(int newQuantity)
758  {
759  resultQuantity = newQuantity;
760  }
761 
764  {
765  return resultQuality;
766  }
767  void SetResultQuality(float newQuality)
768  {
769  resultQuality = newQuality;
770  }
771 
773  float GetKFactor()
774  {
775  return KFactor;
776  }
777  void SetKFactor(float newFactor)
778  {
779  KFactor = newFactor;
780  }
781 
784  {
785  return transSlot;
786  }
788  {
789  transSlot = curSlot;
790  }
791 
793  {
794  return item;
795  }
797  {
798  item = i;
799  }
800 
802  {
803  return workItem;
804  }
806  {
807  workItem = w;
808  }
809 
811  {
812  return gemTarget;
813  }
815  {
816  gemTarget = g;
817  }
818 
821  {
822  return transType;
823  }
825  {
826  transType = t;
827  }
828 
830  csWeakRef<gemActor> worker;
831  csArray<NearNaturalResource> nrr;
834  int category;
835  csVector3 position;
840 
841  uint32_t effectID;
842  csArray<PublishDestination> multi;
843 
844 private:
845  int resultQuantity;
846  float resultQuality;
847  float KFactor;
848  INVENTORY_SLOT_NUMBER transSlot;
849  psItem* item;
850  psItem* workItem;
851  int transType;
852 };
853 
854 #endif
int anim_duration_seconds
Length of time the animation should play.
Definition: workmanager.h:114
There was a any item garbage transform that matched correctly.
Definition: workmanager.h:78
This class keeps the hit of natural resources found for the player and allows ordering of them in an ...
Definition: workmanager.h:125
void SetResultQuantity(int newQuantity)
Definition: workmanager.h:757
size_t action
The action you need to take to get this resource. < Id Corresponding to resourcesActions index...
Definition: workmanager.h:117
csPDelArray< NaturalResource > resources
list of all natural resources in game.
Definition: workmanager.h:321
Manages CEL entities on the server.
Definition: entitymanager.h:77
MathScript * calc_mining_chance
This is the calculation for chance of successful mining.
Definition: workmanager.h:333
Transforming an item in an equipped slot.
Definition: workmanager.h:88
int GetTransformationType()
transformation type
Definition: workmanager.h:820
There was no pattern found.
Definition: workmanager.h:63
MathScript * calc_repair_rank
This is the calculation for how much skill is required to repair.
Definition: workmanager.h:327
void SetTransformationItem(psItem *i)
Definition: workmanager.h:796
Failed one or more contstraints on the transform.
Definition: workmanager.h:71
This class holds the master list of all trade transformatations possible in the game.
Definition: pstrade.h:101
Represents a skill an NPC, player or pet can learn.
Definition: psskills.h:72
NearNaturalResource(NaturalResource *res, float distance)
Definition: workmanager.h:128
MathScript * calc_lockpicking_exp
This is the calculation for the experience to assign to player for lockpicking.
Definition: workmanager.h:332
csWeakRef< gemActor > worker
Definition: workmanager.h:830
MathScript * calc_mining_exp
This is the calculation for the experience to assign to player for mining.
Definition: workmanager.h:334
No item found to use with work item.
Definition: workmanager.h:65
A MathScript is a mini-program to run.
Definition: mathscript.h:442
Too tired to do trade skill work.
Definition: workmanager.h:76
INVENTORY_SLOT_NUMBER
Holds a list of the possible socket identifiers that items can be attached to.
Definition: slots.h:32
MathScript * calc_transform_exp
This is the calculation for the experience to assign to player for trasformations.
Definition: workmanager.h:335
void SetKFactor(float newFactor)
Definition: workmanager.h:777
void SetResultQuality(float newQuality)
Definition: workmanager.h:767
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
work event class
Definition: workmanager.h:708
psTradeProcesses * process
Definition: workmanager.h:838
Transforming an item that is in a container.
Definition: workmanager.h:89
Transform found but not correct equipment.
Definition: workmanager.h:67
psSkillInfo * skill
Skill used to harvest resource.
Definition: workmanager.h:109
psItem * object
Definition: workmanager.h:836
const char * name
Definition: workmanager.h:148
MathScript * calc_lockpick_time
This is the calculation for how long it takes to pick a lock.
Definition: workmanager.h:337
float visible_radius
Radius around the centre where resource is visible.
Definition: workmanager.h:107
int sector
The id of the sector this resource is in.
Definition: workmanager.h:104
Any semi-autonomous object, either a player or an NPC.
Definition: gem.h:1170
csVector3 position
Definition: workmanager.h:835
void SetTransformationSlot(INVENTORY_SLOT_NUMBER curSlot)
Definition: workmanager.h:787
MathScript * calc_repair_time
This is the calculation for how long a repair takes.
Definition: workmanager.h:328
psItem * GetTranformationItem()
Definition: workmanager.h:792
float GetResultQuality()
result quality is calculated immediately before the event
Definition: workmanager.h:763
Transforming a container to another item.
Definition: workmanager.h:94
gemContainers are the public containers in the world for crafting, like forges or ovens...
Definition: gem.h:935
Client * client
Definition: workmanager.h:832
csString reward_nickname
Item name of the reward.
Definition: workmanager.h:116
csVector3 loc
Centre point of resource location.
Definition: workmanager.h:105
MathScript * calc_repair_exp
This is the calculation for the experience to assign to player for repairing.
Definition: workmanager.h:331
MathScript * calc_transform_time
This is the calculation for the time needed to accomplish a transformation.
Definition: workmanager.h:339
Combination items or ammounts not correct.
Definition: workmanager.h:73
Transforming an item that is in a container in an equipped slot.
Definition: workmanager.h:90
Each item has a list of items required for its construction.
Definition: pstrade.h:444
MathScript * calc_combine_quality
This is the calculation for the quality of combined work items.
Definition: workmanager.h:340
csString anim
Name of animation to play while harvesting.
Definition: workmanager.h:113
csStringArray resourcesActions
List of all actions usable with natural resources.
Definition: workmanager.h:326
float probability
Probability of finding resource on attempt.
Definition: workmanager.h:108
Item was ok for transform but quantity was not.
Definition: workmanager.h:72
uint32_t effectID
The id of the psEffect tied to event.
Definition: workmanager.h:841
INVENTORY_SLOT_NUMBER GetTransformationSlot()
slot to perform the transformation
Definition: workmanager.h:783
void SetProcess(psTradeProcesses *p)
Set the active trade process for the event.
Definition: workmanager.h:741
This class collects data of a netclient.
Definition: client.h:95
void void Initialize(iObjectRegistry *object_reg)
Over skilled for this task.
Definition: workmanager.h:70
void SetTargetGem(gemObject *g)
Definition: workmanager.h:814
float GetKFactor()
pattern Kfactor is based on the current pattern
Definition: workmanager.h:773
MathScript * calc_repair_result
This is the calculation for how many points of quality are added in a repair.
Definition: workmanager.h:329
int skill_level
Skill level required to be able to harvest resource.
Definition: workmanager.h:110
Item is not used with any available transform.
Definition: workmanager.h:64
float item_quality
Quality of equipment for the ressource.
Definition: workmanager.h:112
WorkManager * workmanager
Definition: workmanager.h:829
Transforming an item by putting it into auto-transform container.
Definition: workmanager.h:87
NaturalResource * resource
Definition: workmanager.h:129
This class manages the caching of data that is unchanging during server operation.
Definition: cachemanager.h:234
This class holds the master list of all trade processes possible in the game.
Definition: pstrade.h:230
gemObject * GetTargetGem()
Definition: workmanager.h:810
psTradeTransformations * transformation
Definition: workmanager.h:837
A gemObject is any solid, graphical object visible in PS with normal physics and normal collision det...
Definition: gem.h:314
MathScript * calc_transform_practice
This is the calculation for the practice to assign to player for trasformations.
Definition: workmanager.h:336
const char * message
Definition: workmanager.h:149
Transforming an item that is targeted.
Definition: workmanager.h:92
psTradeTransformations * GetTransformation()
Return the active transformation, if any for this event.
Definition: workmanager.h:735
No work item container choosen.
Definition: workmanager.h:66
Correct ingredients but wrong number or wrong process.
Definition: workmanager.h:77
void SetWorkItem(psItem *w)
Definition: workmanager.h:805
psTradeProcesses * GetProcess()
Return the active process, if any for this event.
Definition: workmanager.h:747
int GetResultQuantity()
result quantity is only used when transaction result is zero
Definition: workmanager.h:753
TradePatternMatch
Holds the possible return values for a test to see if an item is transformable.
Definition: workmanager.h:60
MathScript * calc_transform_apply_skill
This is the calculation for the quality resulting from the item.
Definition: workmanager.h:338
Transforming an item that is targeted to an npc type.
Definition: workmanager.h:93
csArray< NearNaturalResource > nrr
Definition: workmanager.h:831
This class handles all calculations around work, using statistics and information from the pspccharac...
Definition: workmanager.h:159
Use of item or ammounts not correct.
Definition: workmanager.h:75
void SetTransformationType(int t)
Definition: workmanager.h:824
gemObject * gemTarget
Definition: workmanager.h:833
TradeTransfomType
Holds the possible transformation types.
Definition: workmanager.h:84
void SetTransformation(psTradeTransformations *t)
Set the active trade transformation for the event.
Definition: workmanager.h:729
Tried to transform too many items.
Definition: workmanager.h:74
float radius
Radius around the centre where resource can be found.
Definition: workmanager.h:106
MathScript * calc_repair_quality
This calculates the item ending quality and max quality at the end of repair.
Definition: workmanager.h:330
All scheduled events must inherit from this class.
Definition: gameevent.h:36
There was a transform that matched correctly.
Definition: workmanager.h:62
A unknown tranformation.
Definition: workmanager.h:86
This class generically allows objects to be notified when a gemObject is removed. ...
Definition: gem.h:768
csArray< PublishDestination > multi
Definition: workmanager.h:842
unsigned int item_cat_id
Category of tool needed for the ressource.
Definition: workmanager.h:111
Transforming an item that is in a targetted actors equipped slot.
Definition: workmanager.h:91
int reward
Item ID of the reward.
Definition: workmanager.h:115
Did not meet required skills.
Definition: workmanager.h:69
bool operator<(const NearNaturalResource &oth) const
Definition: workmanager.h:131
Did not meet required skills.
Definition: workmanager.h:68
psItem * GetWorkItem()
Definition: workmanager.h:801
This class keeps natural resource concentrations across the world.
Definition: workmanager.h:102
This class embodies item instances in the game.
Definition: psitem.h:238
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106