/*
* psactionlocationinfo.h
*
* Copyright (C) 2005 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
*
* Credits : 
*            Michael Cummings <cummings.michael@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Creation Date: 1/20/2005
* Description : Container for the action_locations db table.
*
*/
#ifndef __PSACTIONLOCATION_H__
#define __PSACTIONLOCATION_H__


#include "../iserver/idal.h"

#include "util/poolallocator.h"
#include <csutil/parray.h>
#include <csutil/strhash.h>

class CacheManager;
class gemActionLocation;

/**
 * This huge class stores all the properties of any object
 * a player can have in the game.  All stats, bonuses, maluses,
 * magic stat alterations, combat properties, spell effects,
 * and so forth are all stored here.
 */
class psActionLocation
{
public:
    psActionLocation ();
    ~psActionLocation ();

    bool Load( iResultRow& row );
    bool Load( csRef<iDocumentNode> root );
    bool Save( );
    bool Delete( );
    csString ToXML() const;

    int IsMatch( psActionLocation *compare );

    void SetGemObject( gemActionLocation *gemAction );
    gemActionLocation *GetGemObject( void );

    void GetLocationInWorld(const char **sectorname, float &loc_x, float &loc_y, float &loc_z, float &loc_yrot);
    //void SetLocationInWorld(psSectorInfo *sectorinfo,float loc_x,float loc_y,float loc_z,float loc_yrot);
    void Send( int clientnum);

    uint32 GetInstanceIDOfContainer();

    /// Returns true if this action location is a minigame board
    bool IsGameBoard() const { return isGameBoard; }

    ///  The new operator is overriden to call PoolAllocator template functions
    void *operator new(size_t);
    ///  The delete operator is overriden to call PoolAllocator template functions
    void operator delete(void *);

    size_t id;
    size_t master_id;

    csString name;
    csString sectorname; // Sector Where item is located
    csString meshname; // Mesh name?
    csString polygon; // ?? not required
    csVector3 position; // x,y,z coordinates not required
    float radius;
    csString triggertype;
    csString responsetype;
    csString response;

    gemActionLocation *gemAction;

private:
    /// Static reference to the pool for all psItem objects
    static PoolAllocator<psActionLocation> actionpool;

    /// Flag indicating that this action location is a minigame
    bool isGameBoard;

    /// Initializes the isGameBoard flag by analyzing the response string.
    void InitIsGameBoard();

    //DB Helper Functions
    unsigned int Insert      ( const char *table, const char **fieldnames, psStringArray& fieldvalues );
    bool         UpdateByKey ( const char *table, const char *idname, const char *idvalue, const char **fieldnames, psStringArray& fieldvalues );
    bool         DeleteByKey ( const char *table, const char *idname, const char *idvalue );
};



#endif

