aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-06-02 18:17:10 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-06-02 18:21:54 -0300
commitd2eb32efe2df9e570e491b08d4ecf50da35f1b75 (patch)
tree6097d7f49e6a294f8b216fb6ea13e8aa6184e83e /src
parent3f85ce3cfb46adee8caf890a8369cd7cd7814874 (diff)
downloadgame-d2eb32efe2df9e570e491b08d4ecf50da35f1b75.tar.gz
game-d2eb32efe2df9e570e491b08d4ecf50da35f1b75.zip
impl some spells and create `info.cc`
Diffstat (limited to 'src')
-rw-r--r--src/enums.hh3
-rw-r--r--src/info.cc97
-rw-r--r--src/info.hh13
-rw-r--r--src/magic.cc281
-rw-r--r--src/stubs.hh1
5 files changed, 395 insertions, 0 deletions
diff --git a/src/enums.hh b/src/enums.hh
index 489f8a6..7b2fc68 100644
--- a/src/enums.hh
+++ b/src/enums.hh
@@ -112,8 +112,11 @@ enum EffectType: int {
EFFECT_BURST_ARROW = 7,
EFFECT_POISON = 9,
EFFECT_BONE_HIT = 10,
+ EFFECT_TELEPORT = 11,
EFFECT_ENERGY_HIT = 12,
+ EFFECT_MAGIC_BLUE = 13,
EFFECT_MAGIC_RED = 14,
+ EFFECT_MAGIC_GREEN = 15,
EFFECT_FIRE_HIT = 16,
EFFECT_POISON_HIT = 17,
};
diff --git a/src/info.cc b/src/info.cc
new file mode 100644
index 0000000..7105535
--- /dev/null
+++ b/src/info.cc
@@ -0,0 +1,97 @@
+#include "info.hh"
+#include "creature.hh"
+
+#include "stubs.hh"
+
+bool JumpPossible(int x, int y, int z, bool AvoidPlayers){
+ bool HasBank = false;
+ Object Obj = GetFirstObject(x, y, z);
+ while(Obj != NONE){
+ ObjectType ObjType = Obj.getObjectType();
+
+ if(ObjType.getFlag(BANK)){
+ HasBank = true;
+ }
+
+ if(ObjType.getFlag(UNPASS) && ObjType.getFlag(UNMOVE)){
+ return false;
+ }
+
+ if(AvoidPlayers && ObjType.isCreatureContainer()){
+ TCreature *Creature = GetCreature(Obj);
+ if(Creature != NULL && Creature->Type == PLAYER){
+ return false;
+ }
+ }
+
+ Obj = Obj.getNextObject();
+ }
+ return HasBank;
+}
+
+bool SearchFreeField(int *x, int *y, int *z, int Distance, uint16 HouseID, bool Jump){
+ int OffsetX = 0;
+ int OffsetY = 0;
+ int CurrentDistance = 0;
+ int CurrentDirection = DIRECTION_EAST;
+ while(CurrentDistance <= Distance){
+ int FieldX = *x + OffsetX;
+ int FieldY = *y + OffsetY;
+ int FieldZ = *z;
+
+ // TODO(fusion): This is probably some form of the `TCreature::MovePossible`
+ // function inlined.
+ bool MovePossible;
+ if(Jump){
+ MovePossible = JumpPossible(FieldX, FieldY, FieldZ, true);
+ }else{
+ MovePossible = CoordinateFlag(FieldX, FieldY, FieldZ, BANK)
+ && !CoordinateFlag(FieldX, FieldY, FieldZ, UNPASS);
+
+ // TODO(fusion): This one I'm not so sure.
+ if(MovePossible && CoordinateFlag(FieldX, FieldY, FieldZ, AVOID)){
+ MovePossible = CoordinateFlag(FieldX, FieldY, FieldZ, BED);
+ }
+ }
+
+ if(MovePossible){
+ if(HouseID == HOUSEID_ANY || !IsHouse(FieldX, FieldY, FieldZ)
+ || (HouseID != 0 && HouseID == GetHouseID(FieldX, FieldY, FieldZ))){
+ *x = FieldX;
+ *y = FieldY;
+ return true;
+ }
+ }
+
+
+ // NOTE(fusion): We're spiraling out from the initial coordinate.
+ // TODO(fusion): This function used directions different from the ones
+ // used by creatures and defined in `enums.hh` so I made it use them
+ // instead, LOL.
+ if(CurrentDirection == DIRECTION_NORTH){
+ OffsetY -= 1;
+ if(OffsetY <= -CurrentDistance){
+ CurrentDirection = DIRECTION_WEST;
+ }
+ }else if(CurrentDirection == DIRECTION_WEST){
+ OffsetX -= 1;
+ if(OffsetX <= -CurrentDistance){
+ CurrentDirection = DIRECTION_SOUTH;
+ }
+ }else if(CurrentDirection == DIRECTION_SOUTH){
+ OffsetY += 1;
+ if(OffsetY >= CurrentDistance){
+ CurrentDirection = DIRECTION_EAST;
+ }
+ }else{
+ ASSERT(CurrentDirection == DIRECTION_EAST);
+ OffsetX += 1;
+ if(OffsetX > CurrentDistance){
+ CurrentDistance = OffsetX;
+ CurrentDirection = DIRECTION_NORTH;
+ }
+ }
+ }
+
+ return false;
+}
diff --git a/src/info.hh b/src/info.hh
new file mode 100644
index 0000000..f94ef0e
--- /dev/null
+++ b/src/info.hh
@@ -0,0 +1,13 @@
+#ifndef TIBIA_INFO_HH_
+#define TIBIA_INFO_HH_ 1
+
+#include "common.hh"
+#include "map.hh"
+
+// TODO(fusion): Probably move to `houses.hh` when we implement it?
+constexpr uint16 HOUSEID_ANY = 0xFFFF;
+
+bool JumpPossible(int x, int y, int z, bool AvoidPlayers);
+bool SearchFreeField(int *x, int *y, int *z, int Distance, uint16 HouseID, bool Jump);
+
+#endif //TIBIA_INFO_HH_
diff --git a/src/magic.cc b/src/magic.cc
index 4c641bb..170a8d8 100644
--- a/src/magic.cc
+++ b/src/magic.cc
@@ -1,6 +1,7 @@
#include "magic.hh"
#include "config.hh"
#include "creature.hh"
+#include "info.hh"
#include "monster.hh"
#include "stubs.hh"
@@ -1021,6 +1022,7 @@ void CreateField(TCreature *Actor, int ManaPoints, int SoulPoints, int FieldType
throw ERROR;
}
+ // TODO(fusion): This is probably an inlined function `TCreature::GetForwardPosition`.
int TargetX = Actor->posx;
int TargetY = Actor->posy;
int TargetZ = Actor->posz;
@@ -1266,6 +1268,285 @@ void DeleteField(TCreature *Actor, Object Target, int ManaPoints, int SoulPoints
GraphicalEffect(TargetX, TargetY, TargetZ, EFFECT_POFF);
}
+void CleanupField(TCreature *Actor, Object Target, int ManaPoints, int SoulPoints){
+ if(Actor == NULL){
+ error("CleanupField: Ungültige Kreatur übergeben.\n");
+ throw ERROR;
+ }
+
+ if(!Target.exists()){
+ error("CleanupField: Übergebenes Objekt existiert nicht.\n");
+ throw ERROR;
+ }
+
+ int TargetX, TargetY, TargetZ;
+ GetObjectCoordinates(Target, &TargetX, &TargetY, &TargetZ);
+
+ int Distance = std::min<int>(
+ std::abs(Actor->posx - TargetX),
+ std::abs(Actor->posy - TargetY));
+ if(Distance > 1 || Actor->posz != TargetZ){
+ throw OUTOFRANGE;
+ }
+
+ CheckMana(Actor, ManaPoints, SoulPoints, 1000);
+ Object Obj = GetFirstObject(TargetX, TargetY, TargetZ);
+ while(Obj != NONE){
+ Object Next = Obj.getNextObject();
+ ObjectType ObjType = Obj.getObjectType();
+ // TODO(fusion): It seems that corpse type can be either 0 for human
+ // corpses or 1 for other/monster corpses, so we're avoiding deleting
+ // human corpses here.
+ if(!ObjType.getFlag(UNMOVE) && !ObjType.isCreatureContainer()
+ && (!ObjType.getFlag(CORPSE) || ObjType.getAttribute(CORPSETYPE) != 0)){
+ Delete(Obj, -1);
+ }
+ Obj = Next;
+ }
+ GraphicalEffect(TargetX, TargetY, TargetZ, EFFECT_POFF);
+ Actor->BlockLogout(60, true);
+}
+
+void CleanupField(TCreature *Actor){
+ if(Actor == NULL){
+ error("CleanupField: Ungültige Kreatur übergeben.\n");
+ throw ERROR;
+ }
+
+ if(Actor->Type != PLAYER){
+ error("CleanupField: Zauberspruch kann nur von Spielern angewendet werden.\n");
+ throw ERROR;
+ }
+
+ if(!CheckRight(Actor->ID, CLEANUP_FIELDS)){
+ return;
+ }
+
+ // TODO(fusion): This is probably an inlined function `TCreature::GetForwardPosition`.
+ int TargetX = Actor->posx;
+ int TargetY = Actor->posy;
+ int TargetZ = Actor->posz;
+ switch(Actor->Direction){
+ case DIRECTION_NORTH: TargetY -= 1; break;
+ case DIRECTION_EAST: TargetX += 1; break;
+ case DIRECTION_SOUTH: TargetY += 1; break;
+ case DIRECTION_WEST: TargetX -= 1; break;
+ }
+
+ Object Target = GetMapContainer(TargetX, TargetY, TargetZ);
+ CleanupField(Actor, Target, 0, 0);
+}
+
+void Teleport(TCreature *Actor, char *Param){
+ if(Actor == NULL){
+ error("Teleport: Ungültige Kreatur übergeben.\n");
+ throw ERROR;
+ }
+
+ if(Param == NULL){
+ error("Teleport: Param ist NULL.\n");
+ throw ERROR;
+ }
+
+ if(Actor->Type != PLAYER){
+ error("Teleport: Zauberspruch kann nur von Spielern angewendet werden.\n");
+ throw ERROR;
+ }
+
+ int DestX = Actor->posx;
+ int DestY = Actor->posy;
+ int DestZ = Actor->posz;
+ // TODO(fusion): The `HouseID` parameter of `SearchFreeField` can be 0xFFFF
+ // as a wildcard to any house. This is probably only used for these special
+ // commands and we should have a `HOUSEID_ANY` constant defined somewhere.
+ // If it is something else, the function will try to find a free field with
+ // the same house id. I'm not sure why we use it with marks but I think we
+ // should only use 0xFFFF here.
+ uint16 HouseID = 0xFFFF;
+ int MDGoStrength = Actor->Skills[SKILL_GO_STRENGTH]->MDAct;
+
+ if(stricmp(Param, "up") == 0){
+ if(!CheckRight(Actor->ID, TELEPORT_VERTICAL)){
+ return;
+ }
+ DestZ -= 1;
+ }else if(stricmp(Param, "down") == 0){
+ if(!CheckRight(Actor->ID, TELEPORT_VERTICAL)){
+ return;
+ }
+ DestZ += 1;
+ }else if(stricmp(Param, "fast") == 0){
+ if(!CheckRight(Actor->ID, MODIFY_GOSTRENGTH)){
+ return;
+ }
+ MDGoStrength = 100;
+ }else if(stricmp(Param, "fastest") == 0){
+ if(!CheckRight(Actor->ID, MODIFY_GOSTRENGTH)){
+ return;
+ }
+ MDGoStrength = 200;
+ }else if(stricmp(Param, "slow") == 0
+ || stricmp(Param, "normal") == 0){
+ if(!CheckRight(Actor->ID, MODIFY_GOSTRENGTH)){
+ return;
+ }
+ MDGoStrength = 0;
+ }else{
+ int ParamX, ParamY, ParamZ;
+ if(sscanf(Param, "%d,%d,%d", &ParamX, &ParamY, &ParamZ) == 3
+ || sscanf(Param, "[%d,%d,%d]", &ParamX, &ParamY, &ParamZ) == 3){
+ if(!CheckRight(Actor->ID, TELEPORT_TO_COORDINATE)){
+ return;
+ }
+
+ if(IsOnMap(ParamX, ParamY, ParamZ)){
+ DestX = ParamX;
+ DestY = ParamY;
+ DestZ = ParamZ;
+ }else if(IsOnMap(DestX + ParamX, DestY + ParamY, DestZ + ParamZ)){
+ DestX += ParamX;
+ DestY += ParamY;
+ DestZ += ParamZ;
+ }else{
+ SendMessage(Actor->Connection, TALK_FAILURE_MESSAGE, "Invalid coordinates.");
+ return;
+ }
+ }else{
+ if(!CheckRight(Actor->ID, TELEPORT_TO_MARK)){
+ return;
+ }
+
+ if(GetMarkPosition(Param, &ParamX, &ParamY, &ParamZ)){
+ DestX = ParamX;
+ DestY = ParamY;
+ DestZ = ParamZ;
+ // TODO(fusion): Not sure why we do this here.
+ HouseID = GetHouseID(DestX, DestY, DestZ);
+ }else{
+ SendMessage(Actor->Connection, TALK_FAILURE_MESSAGE, "There is no mark of this name.");
+ return;
+ }
+ }
+ }
+
+ if(DestX != Actor->posx || DestY != Actor->posy || DestZ != Actor->posz){
+ if(!SearchFreeField(&DestX, &DestY, &DestZ, 1, HouseID, true)){
+ throw NOROOM;
+ }
+ Object Dest = GetMapContainer(DestX, DestY, DestZ);
+ Move(0, Actor->CrObject, Dest, -1, false, NONE);
+ GraphicalEffect(DestX, DestY, DestZ, EFFECT_TELEPORT);
+ }else if(MDGoStrength != Actor->Skills[SKILL_GO_STRENGTH]->MDAct){
+ Actor->Skills[SKILL_GO_STRENGTH]->SetMDAct(MDGoStrength);
+ AnnounceChangedCreature(Actor->ID, 4); // CREATURE_GO_STRENGTH_CHANGED ?
+ GraphicalEffect(DestX, DestY, DestZ, EFFECT_MAGIC_BLUE);
+ }
+}
+
+void TeleportToCreature(TCreature *Actor, const char *Name){
+ if(Actor == NULL){
+ error("TeleportToCreature: Ungültige Kreatur übergeben.\n");
+ throw ERROR;
+ }
+
+ if(Actor->Type != PLAYER){
+ error("TeleportToCreature: Zauberspruch kann nur von Spielern angewendet werden.\n");
+ throw ERROR;
+ }
+
+ if(!CheckRight(Actor->ID, TELEPORT_TO_CHARACTER)){
+ return;
+ }
+
+ if(Name == NULL || Name[0] == 0){
+ SendMessage(Actor->Connection, TALK_FAILURE_MESSAGE, "You must enter a name.");
+ return;
+ }
+
+ TPlayer *Player;
+ bool IgnoreGamemasters = !CheckRight(Actor->ID, READ_GAMEMASTER_CHANNEL);
+ switch(IdentifyPlayer(Name, false, IgnoreGamemasters, &Player)){
+ case 0: break; // PLAYERFOUND ?
+ case -1: throw PLAYERNOTONLINE;
+ case -2: throw NAMEAMBIGUOUS;
+ default:{
+ error("TeleportToCreature: Ungültiger Rückgabewert von IdentifyPlayer.\n");
+ throw ERROR;
+ }
+ }
+
+ if(Actor == Player){
+ GraphicalEffect(Actor->CrObject, EFFECT_TELEPORT);
+ return;
+ }
+
+ GraphicalEffect(Actor->CrObject, EFFECT_POFF);
+
+ // TODO(fusion): I assume `SearchFreeField` won't modify the input position
+ // so we're either teleporting to a nearby free position or to the player's
+ // position if it's not protection zone.
+ int DestX = Player->posx;
+ int DestY = Player->posy;
+ int DestZ = Player->posz;
+ uint16 HouseID = GetHouseID(DestX, DestY, DestZ);
+ if(!SearchFreeField(&DestX, &DestY, &DestZ, 1, HouseID, true)
+ || IsProtectionZone(DestX, DestY, DestZ)){
+ throw NOROOM;
+ }
+
+ Object Dest = GetMapContainer(DestX, DestY, DestZ);
+ Move(0, Actor->CrObject, Dest, -1, false, NONE);
+ GraphicalEffect(DestX, DestY, DestZ, EFFECT_TELEPORT);
+ Log("banish", "%s teleportiert sich zu %s.\n", Actor->Name, Player->Name);
+}
+
+void TeleportPlayerToMe(TCreature *Actor, const char *Name){
+ if(Actor == NULL){
+ error("TeleportPlayerToMe: Ungültige Kreatur übergeben.\n");
+ throw ERROR;
+ }
+
+ if(Actor->Type != PLAYER){
+ error("TeleportPlayerToMe: Zauberspruch kann nur von Spielern angewendet werden.\n");
+ throw ERROR;
+ }
+
+ if(!CheckRight(Actor->ID, RETRIEVE)){
+ return;
+ }
+
+ if(Name == NULL || Name[0] == 0){
+ SendMessage(Actor->Connection, TALK_FAILURE_MESSAGE, "You must enter a name.");
+ return;
+ }
+
+ TPlayer *Player;
+ bool IgnoreGamemasters = !CheckRight(Actor->ID, READ_GAMEMASTER_CHANNEL);
+ switch(IdentifyPlayer(Name, false, IgnoreGamemasters, &Player)){
+ case 0: break; // PLAYERFOUND ?
+ case -1: throw PLAYERNOTONLINE;
+ case -2: throw NAMEAMBIGUOUS;
+ default:{
+ error("TeleportPlayerToMe: Ungültiger Rückgabewert von IdentifyPlayer.\n");
+ throw ERROR;
+ }
+ }
+
+ GraphicalEffect(Player->CrObject, EFFECT_POFF);
+
+ int DestX = Actor->posx;
+ int DestY = Actor->posy;
+ int DestZ = Actor->posz;
+ uint16 HouseID = GetHouseID(DestX, DestY, DestZ);
+ if(!SearchFreeField(&DestX, &DestY, &DestZ, 1, HouseID, false)){
+ throw NOROOM;
+ }
+
+ Object Dest = GetMapContainer(DestX, DestY, DestZ);
+ Move(0, Player->CrObject, Dest, -1, false, NONE);
+ GraphicalEffect(DestX, DestY, DestZ, EFFECT_TELEPORT);
+}
+
// Magic Init Functions
// =============================================================================
static void InitCircles(void){
diff --git a/src/stubs.hh b/src/stubs.hh
index 0d7bbd0..7b10798 100644
--- a/src/stubs.hh
+++ b/src/stubs.hh
@@ -43,6 +43,7 @@ extern bool GetRaceNoParalyze(int Race);
extern int GetRacePoison(int Race);
extern void GraphicalEffect(int x, int y, int z, int Type);
extern void GraphicalEffect(Object Obj, int Type);
+extern int IdentifyPlayer(const char *Name, bool ExactMatch, bool IgnoreGamemasters, TPlayer **Player);
extern void InitLog(const char *ProtocolName);
extern void Log(const char *ProtocolName, const char *Text, ...) ATTR_PRINTF(2, 3);
extern void LogoutAllPlayers(void);