Facebook
From Gruff Hummingbird, 8 Years ago, written in C++.
This paste is a reply to sdfsdf from Trivial Penguin - go back
Embed
Viewing differences between sdfsdf and Re: sdfsdf
void Game::thingMoveInternal(Creature *creature, unsigned short from_x, unsigned short from_y, unsigned char from_z,
        unsigned char stackPos, unsigned short itemid, unsigned short to_x, unsigned short to_y, unsigned char to_z, unsigned char count)
{
        Tile *fromTile = getTile(from_x, from_y, from_z);
        if(!fromTile)
                return;

        Tile *toTile   = getTile(to_x, to_y, to_z);
        /*
        if(!toTile){
                if(dynamic_cast(player))
                        dynamic_cast(player)->sendCancelWalk("Sorry, not possible...");
                return;
        }
        */

        Thing *thing = fromTile->getThingByStackPos(stackPos);

#ifdef __DEBUG__
                                //                                std::cout << "moving"
                                /*
                                << ": from_x: "<< (int)from_x << ", from_y: "<< (int)from_y << ", from_z: "<< (int)from_z
                                << ", stackpos: "<< (int)stackPos
                                << ", to_x: "<< (int)to_x << ", to_y: "<< (int)to_y << ", to_z: "<< (int)to_z
                                */
                                //<< std::endl;
#endif

        if (!thing)
                return;

        Item* item = dynamic_cast(thing);
        Creature* creatureMoving = dynamic_cast(thing);
        Player* playerMoving = dynamic_cast(creatureMoving);
        Player* player = dynamic_cast(creature);


dynamic_cast(creature);

        Position oldPos;
        oldPos.x = from_x;
        oldPos.y = from_y;
        oldPos.z = from_z;

    #ifdef RULY_NOPUSHPARCEL\n                                             if (toTile){\nItemVector::iterator brn;\nfor (brn = toTile->downItems.begin(); brn != toTile->downItems.end(); brn++)\n{\nif (playerMoving && (*brn)->getID() == 2595 && player != thing || playerMoving && (*brn)->getID() == 2596 && player != thing) \n{\nplayer->sendCancel("Sorry not possible.");\nreturn;\n}\n}  \n}\n#endif //RULY_NOPUSHPARCEL\n\n\n    #ifdef RULY_ZITEM\n    if(fromTile && playerMoving && player)//TODO: abs check\n    {\n        const Tile* down = getTile(to_x, to_y, to_z+1);\n       if(down && down->zItem >= 3 && playerMoving->canMovedTo(down)) {\nif(getTile(to_x, to_y, to_z) == NULL){\n teleport(playerMoving, Position(to_x, to_y, to_z+1));\n            return;\n}\n}\n        else if(toTile && toTile->zItem >= 3 && fromTile->zItem <= 1) {\n            playerMoving->sendCancelWalk();\n            player->sendCancel("Sorry, not possible.");\n            return;\n        }\n        else if(toTile && toTile->zItem >= 2 && fromTile->zItem <= 0) {\n             playerMoving->sendCancelWalk();\n             player->sendCancel("Sorry, not possible.");\n             return;\n        }\n        else if(fromTile->zItem >= 3 && player == playerMoving)\n        {\n                if(getTile(from_x, from_y, from_z-1) == NULL) //going up\n                {\n                    Tile* newTile = getTile(to_x, to_y, to_z-1);\n                    if(newTile && newTile->ground && playerMoving->canMovedTo(newTile))\n                    {\n                        if(newTile->ground->getID() != 460 && newTile->ground->getID() != 459) {\n                            teleport(playerMoving, Position(to_x, to_y, to_z-1));\n                            return;\n                        }\n                    }\n                }\n        }\n    }\n#endif //RULY_ZITEM   \n\n    \n if(toTile)\n{\nThing *tothing = toTile->getThingByStackPos( stackPos );\nItem *toItem = dynamic_cast( tothing );\nif( toItem && !playerMoving && !creatureMoving && toItem->getID() == 2494 )\n{\nswitch( item->getID() )\n{ \n//Undeleteable items\ncase 1774: //Barrel\ncase 1770: //Barrel\nplayer->sendTextMessage(MSG_SMALLINFO, "Sorry, not possible.");\nplayer->sendCancelWalk();\nreturn;\nbreak;\ndefault:\nremoveThing( playerMoving, oldPos, item, true );\nreturn;\nbreak;\n}\n}\n}\n#ifdef TP_TRASH_BINS
        if(toTile)
        {
                Thing *tothing = toTile->getThingByStackPos(stackPos);
                Item *toItem = dynamic_cast(tothing);

                if(item && toItem && !playerMoving && !creature && toItem->isDeleter())
                {
                        fromTile->removeThing(item);
                        this->FreeThing(item);
                        //creatureBroadcastTileUpdated(oldPos);
                        sendRemoveThing(player, item->pos, item, stackPos);
                        return;
                }
    }
#endif //TP_TRASH_BINS

        // *** Creature moving itself to a non-tile
        if(!toTile && creatureMoving && creatureMoving == creature){
                //change level begin
                Tile* downTile = getTile(to_x, to_y, to_z+1);
                //diagonal begin
                if(!downTile)
                {
                         #ifdef RULY_NOPUSHFIELDS
                                                                  
{

                
if (toTile){
(toTile) {
ItemVector::iterator brn;
for (brn = toTile->downItems.begin(); brn != toTile->downItems.end(); brn++)
        {
if (creatureMoving && (*brn)->getID() == 1492 && creature != thing )
{
if (playerMoving && (*brn)->getID() == 1492 && player != thing || playerMoving && (*brn)->getID() == 1493 && player != thing || playerMoving && (*brn)->getID() == 1494 && player != thing || playerMoving && (*brn)->getID() == 1491 && player != thing || playerMoving && (*brn)->getID() == 1490 && player != thing || playerMoving && (*brn)->getID() == FIRE_FIELD && player != thing || playerMoving && (*brn)->getID() == FIRE_FIELD2 && player != thing || playerMoving && (*brn)->getID() == FIRE_FIELD3 && player != thing) 
{
player->sendCancel("You cannot push players to the fields.");
creature->sendCancel("Sorry, not possible");
return;
}
}  
}
#endif //RULY_NOPUSHFIELDS


        }
                                                        }


                        if(player) {
                                player->sendTextMessage(MSG_SMALLINFO, "Sorry, not possible.");
                                player->sendCancelWalk();
                        }

                        return;
                }