aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-06-08 02:16:45 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-06-08 02:16:45 -0300
commitab9f606371a1df23e9cacbffa0811db7a9e50100 (patch)
treeb5bca97b18977197eb4b5b33f1f1076dcd22e70b /src
parent0590a5f1b3e0ffe295d7894a16b9d8aff3fae586 (diff)
downloadgame-ab9f606371a1df23e9cacbffa0811db7a9e50100.tar.gz
game-ab9f606371a1df23e9cacbffa0811db7a9e50100.zip
more `cract.cc` functions
Diffstat (limited to 'src')
-rw-r--r--src/cr.hh3
-rw-r--r--src/cract.cc207
-rw-r--r--src/crplayer.cc9
-rw-r--r--src/crskill.cc2
-rw-r--r--src/enums.hh2
-rw-r--r--src/magic.cc6
-rw-r--r--src/stubs.hh3
7 files changed, 223 insertions, 9 deletions
diff --git a/src/cr.hh b/src/cr.hh
index e82b17b..37a9f3d 100644
--- a/src/cr.hh
+++ b/src/cr.hh
@@ -496,6 +496,9 @@ struct TCreature: TSkillBase {
// cract.cc
bool SetOnMap(void);
bool DelOnMap(void);
+ void Go(int DestX, int DestY, int DestZ);
+ void Rotate(int Direction);
+ void Rotate(TCreature *Target);
void Attack(void);
void Execute(void);
uint32 CalculateDelay(void);
diff --git a/src/cract.cc b/src/cract.cc
index cfbbe95..c4e85b6 100644
--- a/src/cract.cc
+++ b/src/cract.cc
@@ -326,11 +326,216 @@ bool TCreature::DelOnMap(void){
return Result;
}
+void TCreature::Go(int DestX, int DestY, int DestZ){
+ // NOTE(fusion): This is the execution function for `ToDoGo` which computes
+ // the path step by step. If the destination is outside the range of a single
+ // step, then it is an error.
+ int OrigX = this->posx;
+ int OrigY = this->posy;
+ int OrigZ = this->posz;
+ int Distance = std::max<int>(std::abs(OrigX - DestX), std::abs(OrigY - DestY));
+ if(Distance > 1 || OrigZ != DestZ){
+ throw NOTACCESSIBLE;
+ }
+
+ // TODO(fusion): See note in `TPlayer::CheckState`.
+ int DrunkLevel = this->Skills[SKILL_DRUNKEN]->TimerValue();
+ if(DrunkLevel > 0 && this->Skills[SKILL_DRUNKEN]->Get() == 0){
+ int StaggerChance = std::max<int>(7 - DrunkLevel, 1);
+ if(rand() % StaggerChance == 0){
+ DestX = OrigX;
+ DestY = OrigY;
+ switch(rand() % 4){
+ case DIRECTION_NORTH: DestY -= 1; break;
+ case DIRECTION_EAST: DestX += 1; break;
+ case DIRECTION_SOUTH: DestY += 1; break;
+ case DIRECTION_WEST: DestX -= 1; break;
+ }
+
+ if(this->ToDoClear() && this->Type == PLAYER){
+ SendSnapback(this->Connection);
+ }
+
+ int TalkMode = (this->Type == MONSTER) ? TALK_ANIMAL_LOW : TALK_SAY;
+ this->ToDoTalk(TalkMode, NULL, "Hicks!", false);
+ this->ToDoStart();
+ }
+ }
+
+ if(!this->MovePossible(DestX, DestY, DestZ, true, false)){
+ bool Diagonal = (OrigX != DestX && OrigY != DestY);
+ if(this->Type == PLAYER && !Diagonal){
+ // TODO(fusion): These are quite similar to `MagicClimbing`. Perhaps
+ // there is an inlined function here that checks whether climbing is
+ // possible.
+ if(DestZ > 0 && GetHeight(OrigX, OrigY, OrigZ) >= 24
+ && !CoordinateFlag(OrigX, OrigY, OrigZ - 1, BANK)
+ && !CoordinateFlag(OrigX, OrigY, OrigZ - 1, UNPASS)
+ && this->MovePossible(DestX, DestY, DestZ - 1, true, true)){
+ DestZ -= 1;
+ }else if(DestZ < 15 && GetHeight(DestX, DestY, DestZ + 1) >= 24
+ && !CoordinateFlag(DestX, DestY, DestZ, BANK)
+ && !CoordinateFlag(DestX, DestY, DestZ, UNPASS)
+ && this->MovePossible(DestX, DestY, DestZ + 1, true, true)){
+ DestZ += 1;
+ }
+ }
+
+ if(this->posz == DestZ){
+ throw MOVENOTPOSSIBLE;
+ }
+ }
+
+ Object Dest = GetMapContainer(DestX, DestY, DestZ);
+ Move(this->ID, this->CrObject, Dest, -1, false, NONE);
+}
+
+void TCreature::Rotate(int Direction){
+ this->Direction = Direction;
+ AnnounceChangedObject(this->CrObject, 2); // OBJECT_CHANGED ?
+}
+
+void TCreature::Rotate(TCreature *Target){
+ if(Target == NULL){
+ error("TCreature::Rotate: Target ist NULL.\n");
+ return;
+ }
+
+ int Direction = this->Direction;
+ int OffsetX = Target->posx - this->posx;
+ int OffsetY = Target->posy - this->posy;
+ int DistanceX = std::abs(OffsetX);
+ int DistanceY = std::abs(OffsetY);
+ if(DistanceY > DistanceX){
+ Direction = (OffsetY < 0) ? DIRECTION_NORTH : DIRECTION_SOUTH;
+ }else{
+ Direction = (OffsetX < 0) ? DIRECTION_WEST : DIRECTION_EAST;
+ }
+
+ this->Rotate(Direction);
+}
+
void TCreature::Attack(void){
this->Combat.Attack();
}
-//void TCreature::Execute(void);
+void TCreature::Execute(void){
+ while(true){
+ if(!this->LockToDo || this->IsDead || this->NextWakeup > ServerMilliseconds){
+ break;
+ }
+
+ if(this->NrToDo <= this->ActToDo){
+ this->ToDoClear();
+ this->IdleStimulus();
+ break;
+ }
+
+ uint32 Delay = this->CalculateDelay();
+ if(Delay > 0){
+ if(this->Stop){
+ this->ToDoClear();
+ if(this->Type == PLAYER){
+ SendSnapback(this->Connection);
+ }
+ }else{
+ this->NextWakeup = ServerMilliseconds + Delay;
+ ToDoQueue.insert(this->NextWakeup, this->ID);
+ }
+ break;
+ }
+
+ TToDoEntry TD = *this->ToDoList.at(this->ActToDo);
+ this->ActToDo += 1;
+ try{
+ switch(TD.Code){
+ case TDGo:{
+ this->Go(TD.Go.x, TD.Go.y, TD.Go.z);
+ break;
+ }
+
+ case TDRotate:{
+ this->Rotate(TD.Rotate.Direction);
+ break;
+ }
+
+ case TDMove:{
+ this->Move(TD.Move.Obj, TD.Move.x, TD.Move.y, TD.Move.z, TD.Move.Count);
+ break;
+ }
+
+ case TDTrade:{
+ this->Trade(TD.Trade.Obj, TD.Trade.Partner);
+ break;
+ }
+
+ case TDUse:{
+ this->Use(TD.Use.Obj1, TD.Use.Obj2, TD.Use.Dummy);
+ break;
+ }
+
+ case TDTurn:{
+ this->Turn(TD.Turn.Obj);
+ break;
+ }
+
+ case TDAttack:{
+ this->Attack();
+ break;
+ }
+
+ case TDTalk:{
+ const char *Text = GetDynamicString(TD.Talk.Text);
+ if(Text != NULL){
+ const char *Addressee = GetDynamicString(TD.Talk.Addressee);
+ Talk(this->ID, TD.Talk.Mode, Addressee, Text, TD.Talk.CheckSpamming);
+ }else{
+ error("TCreature::Execute: Text ist NULL bei %s.\n", this->Name);
+ }
+ break;
+ }
+
+ case TDChangeState:{
+ if(this->Type == NPC){
+ ChangeNPCState(this, TD.ChangeState.NewState, true);
+ }
+ break;
+ }
+
+ default:{
+ break;
+ }
+ }
+ }catch(RESULT r){
+ bool SnapbackNecessary = (this->ToDoClear() || this->Stop);
+ if(r == EXHAUSTED){
+ this->ToDoWait(1000);
+ this->ToDoStart();
+ }else{
+ this->ToDoYield();
+ }
+
+ if(this->Type == PLAYER){
+ SendResult(this->Connection, r);
+ if(SnapbackNecessary
+ && r != MOVENOTPOSSIBLE
+ && r != NOTINVITED
+ && r != ENTERPROTECTIONZONE){
+ SendSnapback(this->Connection);
+ }
+ }
+ break;
+ }
+
+ if(this->Stop){
+ this->ToDoClear();
+ if(this->Type == PLAYER){
+ SendSnapback(this->Connection);
+ }
+ break;
+ }
+ }
+}
uint32 TCreature::CalculateDelay(void){
uint32 Delay = 0;
diff --git a/src/crplayer.cc b/src/crplayer.cc
index 3193843..5b87ec8 100644
--- a/src/crplayer.cc
+++ b/src/crplayer.cc
@@ -45,12 +45,15 @@ void TPlayer::CheckState(void){
State |= 0x04;
}
- // TODO(fusion): Not sure about this one.
- if(this->Skills[SKILL_DRUNK]->TimerValue() > 0 && this->Skills[SKILL_DRUNK]->Get() == 0){
+ // TODO(fusion): I think the result from `Get()` here tells whether the
+ // player has some drunk suppression item equipped?
+ if(this->Skills[SKILL_DRUNKEN]->TimerValue() > 0
+ && this->Skills[SKILL_DRUNKEN]->Get() == 0){
State |= 0x08;
}
- if(this->Skills[SKILL_MANASHIELD]->TimerValue() > 0 || this->Skills[SKILL_MANASHIELD]->Get() > 0){
+ if(this->Skills[SKILL_MANASHIELD]->TimerValue() > 0
+ || this->Skills[SKILL_MANASHIELD]->Get() > 0){
State |= 0x10;
}
diff --git a/src/crskill.cc b/src/crskill.cc
index 84402ee..b1a9d42 100644
--- a/src/crskill.cc
+++ b/src/crskill.cc
@@ -1294,7 +1294,7 @@ int GetSkillByName(const char *Name){
}else if(strcmp(Name, "energy") == 0){
Result = SKILL_ENERGY;
}else if(strcmp(Name, "drunken") == 0){
- Result = SKILL_DRUNK;
+ Result = SKILL_DRUNKEN;
}else if(strcmp(Name, "manashield") == 0){
Result = SKILL_MANASHIELD;
}else if(strcmp(Name, "soulpoints") == 0){
diff --git a/src/enums.hh b/src/enums.hh
index 4801e49..2505618 100644
--- a/src/enums.hh
+++ b/src/enums.hh
@@ -430,7 +430,7 @@ enum Skill: int {
SKILL_POISON = 17,
SKILL_BURNING = 18,
SKILL_ENERGY = 19,
- SKILL_DRUNK = 20,
+ SKILL_DRUNKEN = 20,
SKILL_MANASHIELD = 21,
SKILL_SOUL = 22,
};
diff --git a/src/magic.cc b/src/magic.cc
index 53ec1da..1caf83b 100644
--- a/src/magic.cc
+++ b/src/magic.cc
@@ -279,9 +279,9 @@ void TDrunkenImpact::handleCreature(TCreature *Victim){
int Power = this->Power;
int Duration = this->Duration;
- TSkill *Drunk = Victim->Skills[SKILL_DRUNK];
- if(Drunk->TimerValue() <= Power){
- Victim->SetTimer(SKILL_DRUNK, Power, Duration, Duration, -1);
+ TSkill *Drunken = Victim->Skills[SKILL_DRUNKEN];
+ if(Drunken->TimerValue() <= Power){
+ Victim->SetTimer(SKILL_DRUNKEN, Power, Duration, Duration, -1);
}
}
diff --git a/src/stubs.hh b/src/stubs.hh
index d936ab5..f2f1f0b 100644
--- a/src/stubs.hh
+++ b/src/stubs.hh
@@ -16,6 +16,7 @@ typedef void TSendMailsFunction(TPlayerData *PlayerData);
extern void AbortWriter(void);
extern void AnnounceChangedCreature(uint32 CreatureID, int Type);
+extern void AnnounceChangedObject(Object Obj, int Type);
extern void BroadcastMessage(int Mode, const char *Text, ...) ATTR_PRINTF(2, 3);
extern void Change(Object Obj, ObjectType NewType, uint32 Value);
extern void ChangeNPCState(TCreature *Npc, int NewState, bool Stimulus);
@@ -37,6 +38,7 @@ extern Object GetBodyObject(uint32 CreatureID, int Position);
extern Object GetBodyContainer(uint32 CreatureID, int Position);
extern void GetExitPosition(uint16 HouseID, int *x, int *y, int *z);
extern TConnection *GetFirstConnection(void);
+extern int GetHeight(int x, int y, int z);
extern TConnection *GetNextConnection(void);
extern const char *GetName(Object Obj);
extern Object GetObject(uint32 CreatureID, int x, int y, int z, int RNum, ObjectType Type);
@@ -88,6 +90,7 @@ extern void SendSnapback(TConnection *Connection);
extern void ShowGuestList(uint16 HouseID, TPlayer *Player, char *Buffer);
extern void ShowSubownerList(uint16 HouseID, TPlayer *Player, char *Buffer);
extern void ShowNameDoor(Object Door, TPlayer *Player, char *Buffer);
+extern void Talk(uint32 CreatureID, int Mode, const char *Addressee, const char *Text, bool CheckSpamming);
extern void TextualEffect(Object Obj, int Color, const char *Text, ...) ATTR_PRINTF(3, 4);
extern bool ThrowPossible(int FromX, int FromY, int FromZ,
int ToX, int ToY, int ToZ, int Power);