Modular programming almost ready

Discussion in 'TabaHost General Discussion' started by Saddan, Jun 1, 2006.

  1. Saddan

    Saddan Well-Known Member

    Joined:
    May 4, 2003
    Messages:
    348
    Location:
    Olinda, Pernambuco, Brazil
    We are almost ready to deploy modular programming for the server, allowing people to write their own library (linux .so or windows .dll), to extend TH features.

    I´ve wrote 28kbytes of ANSI C lines of code for this (ARRRGGGG ANSI C) :p

    Franz will review the code and test, lets hope everything falls in the right place.

    When the modular system is ready i will publish its specs (GameAPI) in the TH wiki, with some example code (in C, C++ and FreePascal - sorry, interpreted languages, like python or lua, will need a lot more work to be ready)

    This will allow for more advanced AI modules, like the blackboard AI one i am working on, and will allow flying drones (initially, blackboard initialized flying bombers or the wings you got when you tookoff) to be able to continue the mission even if the acks shot the leader - you - down

    I will try to add a JSBSIM (JSBSIM is the Flightgear flight model) standalone interface, providing state of the art flight model for the server´s controlled aircrafts. If this proves too cumbersome for the server hardware, i have a simplified flight model ready to use...

    Ahh and the drones will talk in the radio :p

    You will be able to send them orders or ask what they are doing, or even send them 6 calls... (knowing the limited AI capabilities this will lead to some crazy manouvers by them...)

    You will be able to help us now with independent code (in the form of modules) that will be reviewed for consistency and (if they meet some criteria) be added to the server.

    My 1st drone will be a Ju52/Li2/Showa wich will fly almost touching the ground and find the best route to approach a field (using A* pathfinding), dropping commandos and capturing the field if it gets closed (or dieing in the process).

    That´s all.

    Let´s hope franz, alemão and vibora aproves the current GameAPI.
     
    1 person likes this.
  2. Saddan

    Saddan Well-Known Member

    Joined:
    May 4, 2003
    Messages:
    348
    Location:
    Olinda, Pernambuco, Brazil
    I´ve found a nice algorithm to control bombers/recon/jabo/fighter aircraft behaviour :

    http://en.wikipedia.org/wiki/Ant_colony_optimization

    Using a modified version of it it´s possible to make bombers stay away from routes too busy with enemy airplanes and make fighters do the oposite, stay on routes too much used...

    I am thinking about a variant of the basic algorithm :

    Using a bidimensional table of short integers, like map[][], and defining gold=1 and red=-1, we can setup the following scheme :

    Map starts with random values, from -15 to +15.
    Everytime a gold airplane flies over a X, Y position, gold_value or red_value is added to map[x][y] (this is a server side thing, to keep just one table of this data).

    So, AI aircraft will use this info to select their routes, in the following manner:

    Gold Bombers and Red fighters will select the nearest tile (X,Y) with the higher value (IE, fly over areas of little red overflight or too much gold overflight) and Red bombers/Gold fighters will do the oposite, selecting the neares tile (X, Y) with the lower value. [As we selected gold as = 1]

    This will solve two problems :

    Will make the most used routes known and will allow aircraft to fly without having to do much pathfinding (Tanks will need pathfinding anyway...)

    Initially the aircraft behaviour will be random (ie, like a Ant trying to find food). Bombers will attack buildings if they come too close to them (lets say, 5 tiles), and fighters will attack any aircraft in sight.

    Anytime an aircraft is killed, it floods the sorrounding area with the correspondent oposite color (Red buffer down makes the surrounding 3 tiles painted gold, attracking red fighters and making red bombers flee this area).

    At an preset times, the map will be refreshed (ie : each X,Y position modular value will be decreased = Forget unused patterns) and will receive new random values (Last map values + random pattern = Creativity)

    It´s sorta "influence map", used on Age of empires.

    What you think about this algorithm ?

    This will need, lot of memory and that the server paint the area using info from every aircraft current position (on tile change -> paint the corresponding tile at aircraft X,Y position).

    Ah, and this map have nothing to do (besides correspondent X,Y sizes) with the map you see in the arena, its just a A.I. modelling tech.
     
    Last edited: Jun 9, 2006
  3. Saddan

    Saddan Well-Known Member

    Joined:
    May 4, 2003
    Messages:
    348
    Location:
    Olinda, Pernambuco, Brazil
    // Map structure, you need to allocate the pointer for mapdata
    // using allocate_map_data
    typedef struct map_s {
    u_int8_t signature[8];
    u_int32_t mapxsize;
    u_int32_t mapysize;
    short *mapdata[][];
    } map_t;

    // saves the map to a file
    void savemap(FILE hnd, map_t *map);

    // loads the map from a file
    map_t *loadmap(FILE hnd);

    // Sets when an aicraft flys over an area
    // You need to stick to a convention like :
    // Red = -1 Gold = 1
    void maphit(map_t *map, u_int32_t xpos, u_int32_t ypos, short side);

    // Creates a new random map of a given size
    map_t *randommap(map_t *map, u_int32_t xsize, u_int32_t ysize);

    // Creates a new blank map of a give size
    map_t *blankmmap(map_t *map, u_int32_t xsize, u_int32_t ysize);

    // After usage you should save (if needed) and free the map buffer
    // pointer.

    // Allocates a mapdata buffer corresponding to
    // the values declared on mapxsize and mapysize
    void allocate_map_data(map_t *map);
     
  4. Saddan

    Saddan Well-Known Member

    Joined:
    May 4, 2003
    Messages:
    348
    Location:
    Olinda, Pernambuco, Brazil
    Aircraft will just need a basic pathfinding (find climb route to H height, find landing route to field X), ground avoidance AI module (if next tile height is aproximately equal to current aircraft height, ground avoidance ai module takes over) and Tatical AI module.

    Katy/Hmacks/Tanks/Commandos will still need the costly A* algorithm
     
  5. Franz-

    Franz- FH Beta Tester

    Joined:
    Apr 10, 2001
    Messages:
    329
    Location:
    Porto Alegre, RS, Brazil
    I'll review the code asap, but I ask for patience, I'm just getting used to my new tasks at University

    []'s
    franz-
     
  6. Saddan

    Saddan Well-Known Member

    Joined:
    May 4, 2003
    Messages:
    348
    Location:
    Olinda, Pernambuco, Brazil
    After thinking a lot, i am sure that we will need to setup a shared memory scheme and multithreading for the modules. But i don´t have enought experience with this to do it alone.

    Anyone can help me ?
     
  7. graatz

    graatz Well-Known Member

    Joined:
    Jan 3, 2005
    Messages:
    916
    When the AI traffic rises, and with friendly_collisions ON, we will need to introduce traffic control so as to avoid crashes on the runway.

    But this is a future concept.

    Does the "modular programming" thingie mean that everybody will be able to program own AI for a fighter? And send the robofighter to fend off enemy robofighters, programmed by someone else? Could be fun, watching those fights, right? :)
     
  8. Saddan

    Saddan Well-Known Member

    Joined:
    May 4, 2003
    Messages:
    348
    Location:
    Olinda, Pernambuco, Brazil
    Yes, you can create your own AI, but, you need to send the source code to be reviewed and compiled in order to comply with some rules...