Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code battles - new gamemode, coming to alpha-0.1.6
#1
Recently I started working on a completly new gamemode - code battles. The idea is that you set up two programs to fight with each other. The player can't interact with the world manually. See the related issue on GitHub - https://github.com/colobot/colobot/issues/468

This thread was created to document all features that are needed to create and play code battle levels.


I. Code battle gamemode
Enabled in scene file like so:
Code:
Mission type=CODE_BATTLE
What does this do? It sets up everything for a code battle level - makes the level start paused in order to configure programs, and disables user interaction with the world. After starting the level, you can't even stop the program.
This is still work in progress, some user interaction is still possible

II. Support for teams in scene files
a) CreateObject
The way the teams work is really simple - you specify a team for a robot in scene file, and that setting propagates to all buildings and robots created by that object. Value 0 is the default meaning "no team assigned".
You specify the team in CreateObject, like so:
Code:
CreateObject pos=0;-10 dir=1.5 type=WheeledGrabber team=1 select=1
CreateObject pos=0;10 dir=0.5 type=WheeledGrabber team=2

b) EndMissionTake team=X
This filters results of EndMissionTake to the specific team, just like every other EndMissionTake parameter does.
Example:
Code:
EndMissionTake pos=0;0 dist=10000 type=Any team=1 min=0 max=0 // Mission complete when all team 1 objects are destroyed

c) EndMissionTake team=-X
Negative value for team parameter means "match everything except for team X and objects with no team assigned". Example:
Code:
EndMissionTake pos=0;0 dist=10000 type=Any team=-1 min=0 max=0 // Mission complete when all objects from teams OTHER than 1 are destroyed (excluding objects with no team)

d) EndMissionTake winTeam=X
This one is a bit more complicated. It's easiest to describe like that: "If this condition would mean the mission is won, then team X wins the whole game. If this condition would mean the mission is lost, this team is eliminated from the gameplay and all it's objects are automatically destroyed"
Example:
Code:
// The team that destroys all enemy objects wins the game
EndMissionTake pos=0;0 dist=10000 type=Any team=-1 min=0 max=0 winTeam=1
EndMissionTake pos=0;0 dist=10000 type=Any team=-2 min=0 max=0 winTeam=2

e) TeamName team=X name="YYYYY"
This sets the name of the team that is displayed in the tooltip. Example:
Code:
TeamName team=1 name="Red"
TeamName team=2 name="Blue"

f) VehicleColor team=X color=R;G;B;A
NOT IMPLEMENTED YET!
This is an extension to VehicleColor command allowing to make objects of diffrent teams have diffrent colors.
Example:
Code:
VehicleColor color=0;1;0;0 // Default color, used for objects without team or if team color is not defined
VehicleColor team=1 color=1;0;0;0 // "Red" team
VehicleColor team=2 color=0;0;1;0 // "Blue" team

III. Support for teams in CBOT
a) object.team
Returns the team this object is on. Example:
Code:
object item = radar(WheeledGrabber);
if(item.team == this.team) message("We are friends");
else message("We are enemies");

b) radar() - enhancement for filters
Do you remember the undocumented FilterOnly* parameter? Now you can also use it to detect only friends, enemies and objects on given team. You can use bitwise OR (|) to combine diffrent filters.
Some examples:
Code:
radar(WheeledGrabber, 0, 360, 0, 1000, 1, FilterNone); // default, any object
radar(WheeledGrabber, 0, 360, 0, 1000, 1, FilterOnlyLanding); // this is old but undocumented, used in AlienWasp code, radars only objects that are not currently flying
radar(WheeledGrabber, 0, 360, 0, 1000, 1, FilterOnlyFlying); // reverse of the above, for some reason there was a typo in the code and earlier it was actually named FilterOnlyFliying
radar(WheeledGrabber, 0, 360, 0, 1000, 1, FilterFriendly); // only friendly objects (objects on the same team)
radar(WheeledGrabber, 0, 360, 0, 1000, 1, FilterEnemy); // only enemy objects (objects on diffrent team)
radar(WheeledGrabber, 0, 360, 0, 1000, 1, 1); // only objects on team 1
radar(WheeledGrabber, 0, 360, 0, 1000, 1, 7); // only objects on team 7
radar(WheeledGrabber, 0, 360, 0, 1000, 1, FilterNeutral); // only neutral objects (objects with no team assigned) - DO NOT USE TEAM ID 0 INSTEAD OF FilterNeutral, it won't work
radar(WheeledGrabber, 0, 360, 0, 1000, 1, FilterFriendly | FilterEnemy); // all friendly and enemy objects, reverse of the above
radar(WheeledGrabber, 0, 360, 0, 1000, 1, FilterFriendly | FilterOnlyFlying); // all friendly objects that are currently flying
radar(WheeledGrabber, 0, 360, 0, 1000, 1, 2 | FilterOnlyLanding); // objects from team 2 that are not currently flying
radar(WheeledGrabber, 0, 360, 0, 1000, 1, 1 | 2 | 3); // THIS IS WRONG, DON'T DO THIS - you can only specify only ONE team number at once
As you can see, there are lots of possible combinations you can do.

c) Any
A little bonus, a nice constant Any can be used instead of 0 in radar() to detect any object (including decorative objects, that might be changed later)
Code:
object item = radar(Any);


As you can see, lots of new features were (or will be) added to make this possible. I'll try to make an example level soon. I'm waiting for comments on this and hoping that this will make the community wake up and do something, as well as attract some new players to Colobot.

EDIT: Added example level, as promised:

.zip   CodeBattle.zip (Size: 2.8 KB / Downloads: 53)

EDIT: And a VERY basic solution:
Code:
void GetTitanium()
{
    object item;
    
    item = radar(TitaniumOre);
    goto(item.position);
    grab();
    
    item = radar(Converter, 0, 360, 0, 1000, 1, FilterFriendly);
    goto(item.position);
    drop();
    move(-2.5);
    
    while((item = radar(Titanium, 0, 45, 0, 10)) == null) wait(0.1);
    goto(item.position);
    grab();
}

void object::Build(int cat)
{
    GetTitanium();
    goto(space(this.position, 8, 50, 15));
    drop();
    build(cat);
}

void GetCell()
{
    GetTitanium();
    
    object item = radar(PowerPlant, 0, 360, 0, 1000, 1, FilterFriendly);
    goto(item.position);
    drop();
    while(item.energyCell.category != PowerCell) wait(0.1);
    grab();
}

void Research(int cat)
{
    GetCell();
    object item = radar(ResearchCenter, 0, 360, 0, 1000, 1, FilterFriendly);
    goto(item.position);
    drop();
    item.research(cat);
    //while(item.busy()) wait(0.1);
}

object object::Factory(int cat, string program)
{
    GetTitanium();
    object item = radar(BotFactory, 0, 360, 0, 1000, 1, FilterFriendly);
    goto(item.position);
    drop();
    move(-5);
    item.factory(cat, program);
    point start_pos = this.position;
    GetCell();
    goto(start_pos);
    turn(direction(item.position));
    while(item.busy()) wait(0.1);
    item = radar(cat, 0, 360, 0, 1000, 1, FilterFriendly);
    goto(item.position);
    drop();
    move(-10);
    return item;
}

extern void object::KrzysHCodeBattleTestProgram()
{
    
    object item;
    
    item = radar(Titanium);
    goto(item.position);
    build(Converter);
    
    Build(PowerPlant);
    Build(ResearchCenter);
    Research(ResearchShooter);
    Build(BotFactory);
    item = Factory(WheeledShooter, progfunc("Shooter"));
    camerafocus(item);
}

public void object::Shooter()
{
    while(this.energyCell == null) continue;
    wait(2);
    move(-5);
    
    while(true) {
        object item = radar(Any, 0, 360, 0, 1000, 1, FilterEnemy);
        if(item == null) return;
        turn(direction(item.position));
        move(distance(this.position, item.position)-30);
        fire(1);
    }
}
#2
Quote:I. Code battle gamemode

Enabled in scene file like so:
Code:
Mission type=CODE_BATTLE
First of all, you should rename this new option into "Level type=". This is the same situation like with MissionController VS LevelController. Missions are plot context. Just like Free games or Exercises etc., they're in game content, not in engine. Technically they are all levels.

Moreover, in future we will probably need more level types, so this is good feature to start.

Quote:e) TeamName team=X name="YYYYY"

This sets the name of the team that is displayed in the tooltip. Example:

Code:
TeamName team=1 name="Red"
TeamName team=2 name="Blue"
Some time ago I was thinking about grouping the objects in usual levels, not only for code battles in teams. Something more universal that determines "this is Winged Grabber from Green team" or "this is Ruines from previous expedition" in tooltips. Or simply alternative names for every objects separately. I don't know, I feel that must be something more universal, not only for teams.





I like the whole idea for Code Battles. If this will work flawlessly in the end of this year, we should propose some extra exercises for next Diversity contest.
#3
(07-08-2015, 06:04 PM)RaptorParkowsky Wrote: First of all, you should rename this new option into "Level type=". This is the same situation like with MissionController VS LevelController. Missions are plot context. Just like Free games or Exercises etc., they're in game content, not in engine. Technically they are all levels.
This is really easy to change. I'll do it in a moment.

(07-08-2015, 06:04 PM)RaptorParkowsky Wrote: Some time ago I was thinking about grouping the objects in usual levels, not only for code battles in teams. Something more universal that determines "this is Winged Grabber from Green team" or "this is Ruines from previous expedition" in tooltips. Or simply alternative names for every objects separately. I don't know, I feel that must be something more universal, not only for teams.
Teams work not only in code battle levels but also in normal levels. The whole idea was to make two, completly independent modules - teams and code battle gamemode.

I'm also thinking about a possibility to name objects individually, mainly for use in CBot (retobjectbyname("something")) and EndMissionTake (testing for specific WheeledGrabber object, not any WheeledGrabber that player might have created), but that's another story.


(07-08-2015, 06:04 PM)RaptorParkowsky Wrote: I like the whole idea for Code Battles. If this will work flawlessly in the end of this year, we should propose some extra exercises for next Diversity contest.
Hey, this was my idea! You stole it! Big Grin
#4
Another thing is that we may need a support for different languages in groups/teams names.

Maybe this:

Code:
TeamName.E team=1 name="Bad guys"
TeamName.P team=1 name="Źli facetowie"
TeamName.E team=2 name="Good guys"
TeamName.P team=2 name="Dobrzy facetowie"
But still, I don't like the idea for one-character language code. I would everywhere can set the universal two-characters codes, like EN, PL, RU, etc., not only in colobot.ini file or as the switcher in command line. That should be standardized everywhere.


Forum Jump:


Users browsing this thread: 1 Guest(s)