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

int toggle(int n)
{
    int ret=0;
    if(n==1)
        ret=0;
    else if(n==0)
        ret=1;
    return ret;
}

float abval(float n)
{
    if(n<0)
         n=-n;
    return n;
}

/*int check_col_with_bitmap(int w1, int h1, int w2, int h2, float x1, float y1, float x2, float y2)
{
    int ret=0;
    if(x1+w1>=x2 && x1 <= x2+w2
      && y1+h1>=y2 && y1 <= y2+h2)
            ret=1;

    return ret;
}*/


int check_col_with_bitmap(int w1, int h1, int w2, int h2, float x1, float y1, float x2, float y2)
{
    int ret=0;
   /* if(x1 >= x2   &&   x1+b1->w <= x2+b2->w)
        if(y1>=y2   &&   y1+b1->h <= y2+b2->h)
            ret=1; */
    if(x1+w1>=x2 && x1 <= x2+w2
      && y1+h1>=y2 && y1 <= y2+h2)
            ret=1;

    return ret;
}

float get_dist(float x1,float y1,float x2,float y2)
	{
     /*float tx,ty,td;
     tx=x2-x1;
     ty=y2-y1;
     tx*=tx;
     ty*=ty;
     tx+=ty;
     td=sqrt(tx);
     return(td); */
     float dist;

     dist =sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
     return dist;
    }

float get_dist(Point *p1, Point *p2)
{
    return get_dist(p1->x,p1->y,p2->x,p2->y);
}

int check_col_with_rect(Rect *r1, Rect *r2)
{
    int ret=0;

    //if(exist==1)
    //    {
        //float x1,y1,x2,y2;
        Point p1,p2;
        Point p3,p4;

        if(r1->p1.x < r1->p2.x)
            {
            p1.x = r1->p1.x;
            p2.x = r1->p2.x;
            }
        else
            {
            p1.x=r1->p2.x;
            p2.x=r1->p1.x;
            }


        if(r1->p1.y < r1->p2.y)
            {
            p1.y=r1->p1.y;
            p2.y=r1->p2.y;
            }
        else
            {
            p1.y=r1->p2.y;
            p2.y=r1->p1.y;
            }

///////////////////////////////////////////////

        if(r2->p1.x < r2->p2.x)
            {
            p3.x = r2->p1.x;
            p4.x = r2->p2.x;
            }
        else
            {
            p3.x=r2->p2.x;
            p4.x=r2->p1.x;
            }

        if(r2->p1.y < r2->p2.y)
            {
            p3.y=r2->p1.y;
            p4.y=r2->p2.y;
            }
        else
            {
            p3.y=r2->p2.y;
            p4.y=r2->p1.y;
            }

////////////////////////////////////////////////////

        if(p1.x <= p3.x && p2.x >= p4.x &&
            p1.y <= p3.y && p2.y >= p4.y)
            {
            ret=1;
            }

      //  }
    return ret;
}

void outtext(char *filename, char *info)
{
    #ifdef MAKE_LOGFILE
        FILE *fp=fopen(filename,"at");
        fprintf(fp,"%s\n",info);
        fclose(fp);
    #endif
}
