Commit 8f72f5956756cee972e101173e8efd3ef1b70c9b

Authored by Imanol-Mikel Barba Sabariego
1 parent f3914c12

Finished quests stuff

d2char.h
@@ -95,6 +95,8 @@ typedef struct __attribute__((packed)){ @@ -95,6 +95,8 @@ typedef struct __attribute__((packed)){
95 uint8_t NPCIntroductions[D2S_NPCDATA_LENGTH]; // TODO: Not implemented 95 uint8_t NPCIntroductions[D2S_NPCDATA_LENGTH]; // TODO: Not implemented
96 } D2CharHeader; 96 } D2CharHeader;
97 97
  98 +// TODO: All setX functions
  99 +
98 uint32_t calcChecksum(D2CharHeader* c, void* charData); 100 uint32_t calcChecksum(D2CharHeader* c, void* charData);
99 int checkChecksum(D2CharHeader* c, void* charData); 101 int checkChecksum(D2CharHeader* c, void* charData);
100 int isHardcore(D2CharHeader* c); 102 int isHardcore(D2CharHeader* c);
d2quest.c
@@ -20,41 +20,71 @@ uint16_t getQuestStatus(D2QuestData* d, unsigned int quest, unsigned int difficu @@ -20,41 +20,71 @@ uint16_t getQuestStatus(D2QuestData* d, unsigned int quest, unsigned int difficu
20 return D2S_QUEST_UNKNOWN; 20 return D2S_QUEST_UNKNOWN;
21 } 21 }
22 22
  23 +void setQuestStatus(D2QuestData* d, unsigned int quest, unsigned int difficulty, uint16_t questData) {
  24 + if(quest >= D2S_QUEST_DEN_OF_EVIL && quest <= D2S_QUEST_SISTERS_TO_THE_SLAUGHTER) {
  25 + d->quests[difficulty].actData[D2S_ACT1].questCheckpoints[quest] = questData;
  26 + } else if(quest >= D2S_QUEST_RADAMENT_LAIR && quest <= D2S_QUEST_SEVEN_TOMBS) {
  27 + d->quests[difficulty].actData[D2S_ACT2].questCheckpoints[quest - D2S_QUEST_RADAMENT_LAIR] = questData;
  28 + } else if(quest >= D2S_QUEST_GOLDEN_BIRD && quest <= D2S_QUEST_GUARDIAN) {
  29 + d->quests[difficulty].actData[D2S_ACT3].questCheckpoints[quest - D2S_QUEST_GOLDEN_BIRD] = questData;
  30 + } else if(quest >= D2S_QUEST_FALLEN_ANGEL && quest <= D2S_QUEST_TERROR_END) {
  31 + d->quests[difficulty].actData[D2S_ACT4].questCheckpoints[quest - D2S_QUEST_FALLEN_ANGEL] = questData;
  32 + } else if(quest >= D2S_QUEST_SIEGE_ON_HARROGATH && quest <= D2S_QUEST_EVE_OF_DESTRUCTION) {
  33 + d->quests[difficulty].expansionAct.questCheckpoints[quest - D2S_QUEST_SIEGE_ON_HARROGATH] = questData;
  34 + }
  35 +}
  36 +
23 int isQuestStarted(D2QuestData* d, unsigned int quest, unsigned int difficulty) { 37 int isQuestStarted(D2QuestData* d, unsigned int quest, unsigned int difficulty) {
24 - // TODO  
25 - return 0; 38 + return getQuestStatus(d,quest,difficulty) & D2S_QUEST_STATUS_STARTED;
26 } 39 }
27 40
28 int isQuestRewardCollected(D2QuestData* d, unsigned int quest, unsigned int difficulty) { 41 int isQuestRewardCollected(D2QuestData* d, unsigned int quest, unsigned int difficulty) {
29 - // TODO  
30 - return 0; 42 + return !(getQuestStatus(d,quest,difficulty) & D2S_QUEST_STATUS_REWARD_AVAILABLE);
31 } 43 }
32 44
33 int isQuestCompleted(D2QuestData* d, unsigned int quest, unsigned int difficulty) { 45 int isQuestCompleted(D2QuestData* d, unsigned int quest, unsigned int difficulty) {
34 - // TODO  
35 - return 0; 46 + return getQuestStatus(d,quest,difficulty) & D2S_QUEST_STATUS_COMPLETED;
36 } 47 }
37 48
38 void setQuestStarted(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool) { 49 void setQuestStarted(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool) {
39 // To reset the quest, just zero out the whole thing 50 // To reset the quest, just zero out the whole thing
40 - // To set as started, just set the 2nd bit and clear the rest  
41 -  
42 - // TODO 51 + // To set as started, just set bit 2 and clear the rest
  52 + uint16_t questData = getQuestStatus(d,quest,difficulty);
  53 + if(bool) {
  54 + questData = D2S_QUEST_STATUS_STARTED;
  55 + } else {
  56 + questData = 0x0000;
  57 + }
  58 + setQuestStatus(d,quest,difficulty,questData);
43 } 59 }
44 60
45 void setQuestRewardCollected(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool) { 61 void setQuestRewardCollected(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool) {
46 // To reset, just clear bit 0 and set bit 1. 62 // To reset, just clear bit 0 and set bit 1.
47 // Do the inverse to set reward as collected (but why whould you tho???) 63 // Do the inverse to set reward as collected (but why whould you tho???)
48 -  
49 - // TODO 64 + if(bool) {
  65 + setQuestCompleted(d,quest,difficulty,1);
  66 + } else {
  67 + setQuestCompleted(d,quest,difficulty,0);
  68 + uint16_t questData = getQuestStatus(d,quest,difficulty);
  69 + questData |= D2S_QUEST_STATUS_REWARD_AVAILABLE;
  70 + setQuestStatus(d,quest,difficulty,questData);
  71 + }
50 } 72 }
51 73
52 void setQuestCompleted(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool) { 74 void setQuestCompleted(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool) {
53 // To reset, clear bit 0, bit 12 and bit 13 (13 is kinda optional since it will be cleared by 75 // To reset, clear bit 0, bit 12 and bit 13 (13 is kinda optional since it will be cleared by
54 // the game when loading the savegame). 76 // the game when loading the savegame).
55 // To set as completed, just set bit 0 and bit 12 and clear bit 1 77 // To set as completed, just set bit 0 and bit 12 and clear bit 1
56 -  
57 - // TODO 78 + uint16_t questData = getQuestStatus(d,quest,difficulty);
  79 + if(bool) {
  80 + questData &= ~D2S_QUEST_STATUS_REWARD_AVAILABLE;
  81 + questData |= D2S_QUEST_STATUS_COMPLETED;
  82 + questData |= D2S_QUEST_STATUS_SEEN_FINISH_ANIMATION;
  83 + } else {
  84 + questData &= ~D2S_QUEST_STATUS_COMPLETED;
  85 + questData &= ~D2S_QUEST_STATUS_SEEN_FINISH_ANIMATION;
  86 + }
  87 + setQuestStatus(d,quest,difficulty,questData);
58 } 88 }
59 89
60 int getSpecialQuestStatus(D2QuestData* d, unsigned int specialQuestState, unsigned int difficulty) { 90 int getSpecialQuestStatus(D2QuestData* d, unsigned int specialQuestState, unsigned int difficulty) {
d2quest.h
@@ -518,6 +518,7 @@ void getCheckpointDescriptions(unsigned int quest, const char* *descriptions[16] @@ -518,6 +518,7 @@ void getCheckpointDescriptions(unsigned int quest, const char* *descriptions[16]
518 518
519 // Returns quest status for the specified quest and act. 519 // Returns quest status for the specified quest and act.
520 uint16_t getQuestStatus(D2QuestData* d, unsigned int quest, unsigned int difficulty); 520 uint16_t getQuestStatus(D2QuestData* d, unsigned int quest, unsigned int difficulty);
  521 +void setQuestStatus(D2QuestData* d, unsigned int quest, unsigned int difficulty, uint16_t questData);
521 522
522 int isQuestStarted(D2QuestData* d, unsigned int quest, unsigned int difficulty); 523 int isQuestStarted(D2QuestData* d, unsigned int quest, unsigned int difficulty);
523 int isQuestRewardCollected(D2QuestData* d, unsigned int quest, unsigned int difficulty); 524 int isQuestRewardCollected(D2QuestData* d, unsigned int quest, unsigned int difficulty);
@@ -526,6 +527,10 @@ int isQuestCompleted(D2QuestData* d, unsigned int quest, unsigned int difficulty @@ -526,6 +527,10 @@ int isQuestCompleted(D2QuestData* d, unsigned int quest, unsigned int difficulty
526 // Set bool to 1 to set the status or 0 to remove it 527 // Set bool to 1 to set the status or 0 to remove it
527 void setQuestStarted(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool); 528 void setQuestStarted(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool);
528 void setQuestRewardCollected(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool); 529 void setQuestRewardCollected(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool);
  530 +// When called to set the request to NOT completed (`bool` = 0), this will NOT set the reward collected status
  531 +// which *may* render the quest unobtainable, this is done in case we may want to further modify the quest state.
  532 +// If you want to mark the quest as not completed just to get the reward, please use `setQuestRewardCollected()`
  533 +// instead.
529 void setQuestCompleted(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool); 534 void setQuestCompleted(D2QuestData* d, unsigned int quest, unsigned int difficulty, int bool);
530 535
531 // Some quests have extra fields outside their quest data that govern certain states of the quest 536 // Some quests have extra fields outside their quest data that govern certain states of the quest