Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help solving "Code Battle vs Aliens"
#1
Hey. I recently found about colobot. I'm trying to win the sample code battle in game where there are a few ants across the river and you just need to kill them to win. I have managed to build all the needed buildings and build wingedshooters. But my wingedshooters just hover over my BotFactory and don't move at all. I think the problem is with my use of radar to find enemies. I can't really change the code for wingedshooters incrementally because to see the effect of every change I have to wait for all the base be built from nothing every time. Is there anyway to make the game fast forward a little?
Here is my code:

Code:
extern void object::Fight()
{
    
    build(Converter);
    
    MakeTitanium();
    Build(PowerPlant);
    
    MakeTitanium();
    PutItem(Titanium, PowerPlant);
    
    MakeTitanium();
    Build(ResearchCenter);
    //PutItem(PowerCell, ResearchCenter);
    MyGoto(PowerPlant);
    grab();
    MyGoto(ResearchCenter);
    drop();
    
    Research(ResearchShooter);
    
    MakeTitanium();
    PutItem(Titanium, PowerPlant);
    
    MakeTitanium();
    Build(BotFactory);
    
    MakeTitanium();
    Build(PowerStation);
    
    // recharging will take long so make a titanium while we wait.
    MakeTitanium();
    GrabItem(ResearchCenter);
    Recharge();
    drop();
    Research(ResearchWinged);
    
    while (true)
    {
        
        MakeRobot(WingedShooter, "WingedSearchAndDestroy");
        MyGoto(PowerPlant);
        grab();
        MyGoto(BotFactory);
        wait(10);
        drop();
        
        MakeTitanium();
        PutItem(Titanium, PowerPlant);
        checkRecharge(0.3);
        MakeTitanium();
    }
}

void object::Build(int cat)
{
    object t = WaitFor(Titanium);
    MyGoto(t.position);
    grab();
    MyGoto(space(position, 10, 1000, 10));
    drop();
    build(cat);
}

void object::MakeRobot(int cat, string prog) {
    PutItem(Titanium, BotFactory);
    move(-5);
    object o = radar(BotFactory);
    o.factory(cat, prog);
}

void object::Recharge() {
    point start = position;
    float ori = orientation;
    
    
    MyGoto(PowerStation);
    while (true)
    {
        wait(0.5);
        
        if (load.category == PowerCell) {
            if (load.energyLevel < 1)
            {
                continue;
            }
        }
        
        if (energyCell.energyLevel < 1) {
            continue;
        } else {
            break;
        }
    }
    
    
    MyGoto(start);
    turn(ori - orientation);
}

void object::Research(int cat)
{
    object r = radar(ResearchCenter);
    r.research(cat);
}

object object::WaitFor(int cat)
{
    while (true) {
        object o = radar(cat);
        if (o != null) {
            return o;
        }
        wait(1);
    }
}

bool object::GrabItem(int cat) {
    object t = WaitFor(cat);
    if (t == null)
    {
        return false;
    }
    MyGoto(t.position);
    grab();
    return true;
}

void object::PutItem(int cat, point pos) {
    GrabItem(cat);
    MyGoto(pos);
    drop();
}

void object::PutItem(int item_cat, int dest_cat) {
    object o = radar(dest_cat);
    PutItem(item_cat, o.position);
    
}

void object::MyGoto(point pos)
{
    
    errmode(0);
    while (goto(pos) != 0) {
        wait(2);
    }
    
}

void object::MyGoto(int cat)
{
    object o = WaitFor(cat);
    MyGoto(o.position);
}

void object::MakeTitanium()
{
    errmode(0);
    
    object ore = WaitFor(TitaniumOre);
    MyGoto(ore.position);
    grab();
    
    
    
    object conv = radar(Converter);
    MyGoto(conv.position);
    drop();
    move(-3);
    //wait(15);
    //move(3);
    //grab();
    
    //drop();
}
// --------------------- Code for WingedShooter ---------------------

public void object::Ascend(int h) {
    jet(1);
    while (position.z - topo(position) < h) {
        wait(0.2);
    }
    jet(0);
}

public void object::checkRecharge(float percent) {
    if (energyCell == null)
    {
        return;
    }
    
    if (energyCell.energyLevel < percent)
    {
        MyGoto(PowerStation);
        wait(5);
        // free the power station.
        MyGoto(space(position));
    }
    
}

public void object::WingedSearchAndDestroy()
{
    int height = 10;
    
    while(energyCell == null) {
        wait(1);
    }
    move(-5);
    Ascend(height);
    aim(-10);
    
    while (true)
    {
        if (temperature > 0.7)
        { // neet to cooldown
            jet(-1);
            wait(10);
            Ascend(height);
        }
        
        
        
        
        checkRecharge(0.3);

        
        
        
        
        
        object enemy = radar(Any, 0, 360, 0, 1000, 1, FilterEnemy);
        if (enemy != null) {
            float d = distance(position, enemy.position);
            if (d > 15 && d < 30)
            {
                motor(0, 0);
                turn(direction(enemy.position));
                fire(0.5);
            } else if (d < 30)
            {
                turn(direction(enemy.position));
                turn(180);
                motor(1, 1);
            } else
            {
                turn(direction(enemy.position));
                motor(1, 1);
            }
            
            (1);
            
        }
        jet(0);
        int h = position.z - topo(position);
        if (h < height) {
            jet(1);
            
        } else if (h > (height + 5))
        {
            jet(-1);
        }
        wait(0.5);
    }
    
}
#2
You can change speed of the game using F3-F9 keys. F9 gives you speed 6x. If you need more, you can open cheat console and input "speed x" where x is the speed you want, e.g. "speed 8" will give you speed 8x. Although this might cause some physics-related bugs, so don't use too high values.
"After three days without programming, life becomes meaningless."
~The Tao of Programming
#3
Apparently 
Code:
radar(Any, 0, 360, 0, 1000, 1, FilterEnemy);

Does not find AlienAnts
Changing it to 
Code:
radar(AlienAnt);

Did the trick


Forum Jump:


Users browsing this thread: 1 Guest(s)