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
#2
I'm fine with marking this as the official release.
[Image: doty7Xn.gif]

10 ʏᴇᴀʀs sɪɴᴄᴇ ɪʀᴄ ɢᴏᴏᴅ.ɪ ᴡᴀʟᴋ ᴛʜʀᴏᴜɢʜ ᴛʜᴇ ᴇᴍᴘᴛʏ sᴛʀᴇᴇᴛs ᴛʀʏɪɴɢ ᴛᴏ ᴛʜɪɴᴋ ᴏғ sᴏᴍᴇᴛʜɪɴɢ ᴇʟsᴇ ʙᴜᴛ ᴍʏ ᴘᴀᴛʜ ᴀʟᴡᴀʏs ʟᴇᴀᴅs ᴛᴏ ᴛʜᴇ ɪʀᴄ. ɪ sᴛᴀʀᴇ ᴀᴛ ᴛʜᴇ sᴄʀᴇᴇɴ ғᴏʀ ʜᴏᴜʀs ᴀɴᴅ ᴛʀʏ ᴛᴏ sᴜᴍᴍᴏɴ ᴛʜᴇ ɢᴏᴏᴅ ɪʀᴄ. ɪ ᴡᴀᴛᴄʜ ᴏᴛʜᴇʀ ɪʀᴄ ᴄʜᴀɴɴᴇʟs ʙᴜᴛ ɪᴛ ɪs ɴᴏ ɢᴏᴏᴅ. ɪ ᴘᴇsᴛᴇʀ ᴢᴏʀᴛ ᴀɴᴅ ᴛʀʏ ᴛᴏ ʀᴇsɪsᴛ ʜɪs sᴇxɪɴᴇss ʙᴜᴛ ɪᴛ ɪs ᴀʟʟ ᴍᴇᴀɴɪɴɢʟᴇss. ᴛʜᴇ ᴇɴᴅ ɪs ɴᴇᴀʀ.ɪ ᴛʜᴇɴ ᴜsᴜᴀʟʟʏ ʀᴇᴀᴅ sᴏᴍᴇ ᴏʟᴅ ɪʀᴄ ʟᴏɢs ᴀɴᴅ ᴄʀʏ ᴍʏsᴇʟғ ᴛᴏ sʟᴇᴇᴘ.


Reply
Thanks given by:
#3
Seconded.
Age ratings for movies and games (and similar) have never been a good idea.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.
Reply
Thanks given by:
#4
(11-21-2018, 02:54 AM)zort Wrote:  Here's the DLLs: debug, release

The links are dead.
Refer to this thread for links and a repository.


Sorry for grave-digging, but there may be many guys came here for the DLL.. :)
Reply
Thanks given by: Memento
#5
sry for grave digging, was using debug version of this but ctimer seems to be bugged

Edit: fixed ctimer version linked by JohnDoeAntler on discord
https://github.com/JohnDoeAntler/LF2-AI-.../tag/0.0.1
back from the dead.....kinda
Reply
Thanks given by:
#6
(08-15-2020, 07:00 AM)Nyamaiku Wrote:  sry for grave digging, was using debug version of this but ctimer seems to be bugged

Edit: fixed ctimer version linked by JohnDoeAntler on discord
https://github.com/JohnDoeAntler/LF2-AI-.../tag/0.0.1

ohhh i had issues with c-timer not working i ended up using randomizer to do moves while catching enemy.
This fixes the c-timer bug where it doesn't work?
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)