Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Github repository, made some minor improvements
#1
There were some changes I wanted to make. To share them, I put them in a github repository: https://github.com/zort/lf2-ai-scriptengine Can consider this zort's fork until Silva or SomeoneElse give their approval I guess.

Here's the list of changes:
  • Upgraded to Angelscript 2.32.0 (mainly for array.sort() that takes comparator function)
  • Added Object.vrests (was split into int vrest and char unkwn8[396])
  • Added global elapsed_time (number of TUs since start of match)
  • Added vector3 type
  • Copy more fields from Object to Info (the self and target globals):
    • x_real, y_real, z_real
    • vector3 position, velocity
    • wait_counter (also fixed offset in Object, previously was 4 bytes off, as was ctimer and ccatcher)
    • weapon_holder
  • Added function setEnemy(int) for use in ego() for setting the enemy that the AI targets when you return 0 from ego() (in fact I initially thought this was what loadTarget did) - though it's only as useful as ego() is, which at the moment is not very useful because it's limited to basic Template AI
  • Fixed signatures of Info constructors, now you can construct an Info via Info(object_num) (useful because unlike Object, Info stores its own num and other goodies)
  • Made Info fields changeable (non-const), now you can do like obj.frame = obj.data.frames[obj.frame].next to simulate obj in the next TU
  • Added enum ItrKinds:

Here's the DLLs: debug, release

Everything is backwards compatible of course, or at least it should be.

To show some of the new features, here's a script that always targets the nearest enemy (gets very confused):

    AI-Code:
double distance_to(const Info& other) {
    return (self.position - other.position).length();
}
 
bool closer(const Info& a, const Info& b) {
    return distance_to(a) < distance_to(b);
}
 
array<const Info@> getEnemyObjects() {
    array<const Info@> ret = {};
    for (int i = 0; i < 400; i++) {
        // exists
        if (!game.exists[i])
            continue;
        // not us
        if (i == self.num)
            continue;
        // is enemy
        if (game.objects[i].team == self.team)
            continue;
        // is alive
        if (game.objects[i].hp <= 0)
            continue;
 
        ret.insertLast(Info(i));
    }
 
    return ret;
}
 
array<const Info@> getEnemies() {
    array<const Info@> enemyObjects = getEnemyObjects();
    array<const Info@> ret = {};
    for (uint i = 0; i < enemyObjects.length(); i++) {
        // is human
        if (enemyObjects[i].type != 0) 
            continue;
 
        ret.insertLast(enemyObjects[i]);
    }
 
    return ret;
}
 
array<const Info@> attackableEnemies() {
    array<const Info@> enemies = getEnemies();
    array<const Info@> ret = {};
 
    for (uint i = 0; i < enemies.length(); i++) {
        if (enemies[i].state == STATE_LYING)
            continue;
 
        if (enemies[i].blink != 0)
            continue;
 
        ret.insertLast(@enemies[i]);
    }
 
    return ret;
}
 
array<const Info@> attackableEnemiesByDistance() {
    array<const Info@> attackable_enemies = attackableEnemies();
    
    attackable_enemies.sort(function(a,b){return closer(a,b);});
    
    return attackable_enemies;
}
 
int ego() {
    array<const Info@> enemies = attackableEnemiesByDistance();
    if (enemies.length > 0)
        setEnemy(enemies[0].num);
 
    return 0;
}
I get a lot of e-mails that kick off by saying, I"I want to be zort's best bud' but who cares, so do lots of people, you have to more than just want it.
Reply
Thanks given by: Memento , MangaD , Luigi600 , RazenBrenday , MoragWan


Messages In This Thread
Github repository, made some minor improvements - by zort - 11-21-2018, 02:54 AM



Users browsing this thread: 1 Guest(s)