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

You must understand the Game Editor concepts, before post here.

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

Postby Murd-Machine[_] » Mon Jan 07, 2008 12:30 am

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???
User avatar
Murd-Machine[_]
 
Posts: 72
Joined: Fri Nov 04, 2005 7:04 pm
Location: Moscow-city
Score: 1 Give a positive score

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

Postby Bee-Ant » Mon Jan 07, 2008 7:19 am

Do you mean "guru" is a "teacher"???In Indonesian, guru means teacher... :mrgreen:
That codes looks like C++...
Let me see...
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

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

Postby Fuzzy » Mon Jan 07, 2008 12:05 pm

in what way does it not work correctly?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

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

Postby Murd-Machine[_] » Mon Jan 07, 2008 1:10 pm

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.
User avatar
Murd-Machine[_]
 
Posts: 72
Joined: Fri Nov 04, 2005 7:04 pm
Location: Moscow-city
Score: 1 Give a positive score

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

Postby Fuzzy » Mon Jan 07, 2008 2:43 pm

Yes, your idea of the problem seems typical of an error like that. Good work. Keep at it; i think you will solve it.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest