/*
* tribe.h
*
* Copyright (C) 2006 Atomic Blue (info@planeshift.it, http://www.atomicblue.org) 
*
*
* 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 (version 2 of the License)
* 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.
*
*/
#ifndef __TRIBE_H__
#define __TRIBE_H__

#include <csutil/array.h>
#include <csgeom/vector3.h>

class iResultRow;
class EventManager;
class NPC;
struct iSector;



class psTribe
{
    typedef struct Resource
    {
        csString name;
        float    amount;
    };

    enum TribeNeed 
    {
        NOTHING,
        WALK,
        DIG,
        REPRODUCE
    };

 public:
    /** Construct a new tribe object */
    psTribe();

    /** Destruct a tribe object */
    virtual ~psTribe();

    /** Load the tribe object */
    bool Load(iResultRow& row);
    
    /** Load and add a new member to the tribe */
    bool LoadMember(iResultRow& row);

    /** Attach a new member to the tribe if the NPC is a member */
    bool CheckAttach(NPC * npc);

    /** Remove members that die */
    bool HandleDeath(NPC * npc);

    /** Handled a perception given to this tribe */
    void HandlePerception(csString perception);

    /** Add a new resource to the tribe resource table */
    void AddResource(csString resource, float amount);

    /** Advance the tribe */
    void Advance(csTicks when,EventManager *eventmgr);

    int GetID() { return id; }
    csString GetName() { return name; }
    size_t GetMemberIDCount() { return members_id.Length(); }
    size_t GetMemberCount() { return members.Length(); }
    NPC * GetMember(size_t i) { return members[i]; }
    size_t GetResourceCount() { return resources.Length(); }
    const Resource& GetResource(size_t n) { return resources[n]; }
    void GetHome(csVector3& pos, float& radius, iSector* &sector);
    
protected:

    /** Calculate the tribes need from a NPC */
    TribeNeed Brain(NPC * npc);
    
    int                    id;
    csString               name;
    csArray<int>           members_id;
    csArray<NPC*>          members;
    csArray<Resource>      resources;

    csVector3              home_pos;
    float                  home_radius;
    csString               home_sector_name;
    iSector*               home_sector;
};

#endif
