Page 1 of 1

TBS, super difficult question) guru only))))

PostPosted: Mon Jan 07, 2008 12:30 am
by Murd-Machine[_]
Hi folks! I'm working on Ancient Empires\Advance wars engine. So I need to make my units have some walking points (a number of squares a unit can move on) and terrain that influences on spending these points to move on current square. So the object is to calculate and than draw sqaures the unit can reach. Well, that seem too difficult for me. Now I have this code for calculating:
Code: Select all
int count=0;
int cx[10000];
int cy[10000];
int mx,my;


void calc_field(int i, int x1, int y1){
    int th=0;
    int tmpi;
    int j;
if (strcmp(getactor(x1,y1)->name,"pMountain")==0){i-=3;}
if (strcmp(getactor(x1,y1)->name,"pWater")==0){i-=3;}
if (strcmp(getactor(x1,y1)->name,"pGrass")==0){i-=1;}
if (strcmp(getactor(x1,y1)->name,"pHills")==0){i-=2;}
if (strcmp(getactor(x1,y1)->name,"pForest")==0){i-=2;}
    if (i>0){
        th=0;
        j=0;
      if (x1<=mx){
        while (j<count){
            if (cx[j]==x1-32){
                if (cy[j]==y1){
                    th++;
                    break;
               }
            }
        j++;
        }
        if (th==0){
            cx[count]=x1-32;
            cy[count]=y1;
            count++;
            tmpi=i;
            i--;
            calc_field(i,x1-32,y1);
            i=tmpi;
        }
        }

        th=0;
        j=0;
      if (x1>=mx){
        while (j<count){
            if (cx[j]==x1+32){
                if (cy[j]==y1){
                    th++;
                    break;
               }
            }
        j++;
        }
        if (th==0){
            cx[count]=x1+32;
            cy[count]=y1;
            count++;
            tmpi=i;
            i--;
            calc_field(i,x1+32,y1);
            i=tmpi;
        }
        }
 
        th=0;
        j=0;
      if (y1>=my){
        while (j<count){
            if (cx[j]==x1){
                if (cy[j]==y1+32){
                    th++;
                    break;
               }
            }
        j++;
        }
        if (th==0){
            cx[count]=x1;
            cy[count]=y1+32;
            count++;
            tmpi=i;
            i--;
            calc_field(i,x1,y1+32);
            i=tmpi;
        }
        }

        th=0;
        j=0;
      if (y1<=my){
        while (j<count){
            if (cx[j]==x1){
                if (cy[j]==y1-32){
                    th++;
                    break;
               }
            }
        j++;
        }
        if (th==0){
            cx[count]=x1;
            cy[count]=y1-32;
            count++;
            tmpi=i;
            i--;
            calc_field(i,x1,y1-32);
            i=tmpi;
        }
        }
    }
}

And this one for depicting:
Code: Select all
void draw_field(){
    int k;
    for(k=0; k<count; k++){
        CreateActor("objBB", "bb", "(none)", "(none)", cx[k], cy[k], true);
    }
 
}

But there is mistake somewhere :?
I'm completely stuck with this task, the calculation works incorrectly somehow(
Could some guru help with this object???

Re: TBS, super difficult question) guru only))))

PostPosted: Mon Jan 07, 2008 7:19 am
by Bee-Ant
Do you mean "guru" is a "teacher"???In Indonesian, guru means teacher... :mrgreen:
That codes looks like C++...
Let me see...

Re: TBS, super difficult question) guru only))))

PostPosted: Mon Jan 07, 2008 12:05 pm
by Fuzzy
in what way does it not work correctly?

Re: TBS, super difficult question) guru only))))

PostPosted: Mon Jan 07, 2008 1:10 pm
by Murd-Machine[_]
By "guru" I meen a person who is very competent in this subject (C++). I know the roots of this word and it's widely used in this meening nowadays.

It must be a mistake in algorythm, and it's quite difficult to say what works uncorrectly. Well, if an object has 8 moving steps he can move downwards a road (terrain that takes nothing to be moved on) on 8 squares, but upwards on 7. And if it comes to using different terrains (Mountains that take 3 or forests that take 2) code works totally incorrectly: in some ways object can reach much further than it should be able (to spend up to 15 walking points), or 4-5 walking points sometimes.

I think the problem is that if the object has any number of walking points left it places a square he can reach before checking whether it has enough walking points to reach it. Though it's just an idea and I'm not sure it's right.

Re: TBS, super difficult question) guru only))))

PostPosted: Mon Jan 07, 2008 2:43 pm
by Fuzzy
Yes, your idea of the problem seems typical of an error like that. Good work. Keep at it; i think you will solve it.