#include <allegro.h>
#include <string.h>
#include <math.h>
#include "aldumb.h"
#include "standards.h"
#include "rotk2.h"
#include "sounds.h"


#include "CObjectSet.h"
#include "CMapObject.h"

int CObjectSet::add_all_objects(CMapObject *object, DATAFILE *data, CCinematic *_ingameCin)
{
//object[0].create_mo(&osObjectSet1,0,data,0,0,pTemp);
    Point pTemp={0,0};

    for(int n=0 ; n<next_object ; n++)
    {
        object[n].create_mo(this,n,data,0,0,pTemp,_ingameCin);           
    }    
    return next_object;
}

int CObjectSet::ret_number_of_objects(void)
{
    return next_object;
}

ob CObjectSet::return_info(int num)
{
    if (num<next_object)
        return object[num];
}

void CObjectSet::load_object_set(char *filename)
{
    FILE *fp = fopen(filename,"r");

    if(fp)
        {
        fscanf(fp,"%d ",&next_object);
        for(int n=0 ; n<next_object ; n++)
            {
            char *temp_name = new char[50];
            char *temp_name2 = new char[50];
            char *temp_name3 = new char[50];
            char *temp_name4 = new char[50];
            fscanf(fp,"%d ",&object[n].type);
            fscanf(fp,"%d ",&object[n].pic_num);
            
            fscanf(fp,"%s ",temp_name);
            strcpy(object[n].anim_file , temp_name);
            
            /*fscanf(fp,"%s ",temp_name2);
            strcpy(object[n].consumed_wav , temp_name2); 
            
            fscanf(fp,"%s ",temp_name3);
            strcpy(object[n].ambient_wav , temp_name3);*/
            fscanf(fp,"%d ",&object[n].consumed_wav);
            fscanf(fp,"%d ",&object[n].ambient_wav);
            
            fscanf(fp,"%s ",temp_name4);
            strcpy(object[n].script_name , temp_name4);
            
            fscanf(fp,"%d ",&object[n].tile_type);
            fscanf(fp,"%d ",&object[n].pickup_type);
            fscanf(fp,"%d ",&object[n].enim_type);
            fscanf(fp,"%d ",&object[n].moving);
            fscanf(fp,"%d ",&object[n].grav);
            fscanf(fp,"%d ",&object[n].consumable);
            fscanf(fp,"%d ",&object[n].pickup_value);
            object[n].exist=true;
            }

        }

    fclose(fp);
   // readkey();

}

void CObjectSet::init_set(void)
{
    for (int n=0 ; n<max_o ; n++)
        object[n].exist=false;
    next_object=0;
}
