Jump to content


Photo

Turn based strategy region attacking issues


  • Please log in to reply
2 replies to this topic

#1 ProxatorDesign

ProxatorDesign

    GMC Member

  • New Member
  • 14 posts
  • Version:GM8

Posted 09 August 2012 - 07:27 PM

So in my turn-based game, I use a list for each region that defines what regions are adjacent. I also define a variable that determines whether or not a region is friendly/unoccupied or hostile. But whenever the army in question moves into a hostile region with a hostile army, the combat mechanic I had as a placeholder dosen't fire. The army just moves right in the region without either army being destroyed. Here is the script I am using.

{
//Checks if the region is highlighted and therefore a region that can be moved into and does combat checks
if self.visible=1 then
{
    {
    //Am I a baddie?
    if self.ishostile=0 then
    {
    //Moves army since there is no enemy to be found
    global.selected.x=self.x
    global.selected.y=self.y
    }
    else
    {
    //Begins combat calculations
    var combatcalc;
    combatcalc=random(1);
        if combatcalc=1 then
        {
        //You lose! haha!
        with(global.selected) {
        instance_destroy();
        }
        }
        else
        {
        //Win
        with(self.garrison) {
        instance_destroy();
        }
        self.garrison=global.selected.id;
        global.selected.x=self.x
        global.selected.y=self.y
        ishostile=0;
        }
    }
}
//Now we dehighlight the regions already highlighted
var adjRegions;
var highregion;
adjRegions = global.selected.region.adjacentRegions //just to make the variable shoter for the rest of the code
for(i=0; i<ds_list_size(adjRegions); i+=1){
    highregion=ds_list_find_value(adjRegions, i)
    highregion.visible=0
    }
    //Tells the new region that I now control it and ends this unit's turn
    global.selected.region=self.id
    global.selected.lastturn=global.selected.lastturn+1;
    global.selected=0;
    global.havegone=global.havegone+1;
}
else
{
exit
}
}

  • 0

#2 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 10 August 2012 - 08:36 AM

    //Begins combat calculations
    var combatcalc;
    combatcalc=random(1);
        if combatcalc=1 then

For one thing, random(1) returns a number between 0.000... and 0.999... It never comes equal to 1. (I guess you have mixed it up with irandom(1) that returns an integer between 0 and 1, inclusive.) Currently, your combat code will always go into the else part. So, let's take a look at that part (some indentation are added for readability):

        else
        {
            //Win
            with(self.garrison) {
                instance_destroy();
            }
            self.garrison=global.selected.id;
            global.selected.x=self.x
            global.selected.y=self.y
            ishostile=0;
        }

If you see the army moves into the new region, it means that this part has definitely been executed. So, if you don't see the hostile army get destroyed, the only explanation is that "self.garrison" isn't the hostile enemy. Try to see if it points to the correct instance.
...
if (!instance_exists(garrison)) {
    if (garrison == noone) {
        show_message("The region has no garrison");
    }
    else {
        show_message("The instance #" + string(garrison) + " no longer exists!");
    }
}
else if (garrison < 100000) {
    show_message("garrison isn't an instance but an object #" + string(garrison) + ", " + object_get_name(garrison));
}
else {
    show_message("garrison is an instance #" + string(garrison) + " of object " + object_get_name(garrison.object_index));
}
...
I also worry about this part:

global.selected = 0;

0 is a valid object index which is the first object added to the game (used to be named object0.) It may cause some problems if you use it to denote a non-existing instance. You'd better use noone instead.

Edited by torigara, 10 August 2012 - 10:57 AM.

  • 1

#3 ProxatorDesign

ProxatorDesign

    GMC Member

  • New Member
  • 14 posts
  • Version:GM8

Posted 10 August 2012 - 04:26 PM

Whoops, yup I missed the i while I was typing, that would explain the random issue.

But when testing the else code, I got confirmation that there was indeed a hostile army inside the other region.

show_message("garrison is an instance #" + string(garrison) + " of object " + object_get_name(garrison.object_index)); is what fired, so it definitely sees and acknowledges the hostile army.

Other than that, the combat code is still broke as a Bethesda game, the army still moves into the region irregardless of whether the enemy has been dealt with or not.

Edit: Hmm, after further investigation, the code seems to delete the region for unknown reasons. I suspect that the code is believing that the garrison is the region as opposed to the later.


Edit: Fixed it, My region was not properly reporting the garrison's ID, so that fixed the issue right away. Thanks torigara! :)

Edited by ProxatorDesign, 10 August 2012 - 04:32 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users