• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[AI] declaring new variables in common.ai and replacing common.ai

Level 8
Joined
May 12, 2018
Messages
106
Hi, I'm writing new integer variables for my convenience and custom races in common.ai, referring to InsaneMonster's Advanced AI guide.

Ex, basic common.ai declared Priest Adept Training(Rhpt) as UPG_PRAYING. but cases like this is unfamiliar to me, so I declare it again (didnt remove existed)
JASS:
constant integer UPG_PRAYING        = 'Rhpt' // basic
constant integer UPG_HUMAN_TRAIN_PRIEST = 'Rhpt' // mine new variable
In this way, all the previously declared variables remain the same, and they are coexisting with the variables I have declared newly.

And my custom races are not modifications to existing units, but newly created ones from object data.
I also recognized that I needed to work separately on the TownCountEx function to avoid that AI constructing duplicated Halls, and I decided to modify common.ai.

JASS:
    constant integer UNIT_BLOODELF_WORKER = 'nhew'
    constant integer UNIT_BLOODELF_FOOTMAN = 'hhes'
    constant integer UNIT_BLOODELF_ARCHER = 'nhea'
    constant integer UNIT_BLOODELF_GLAIVE = 'e000'
    constant integer UNIT_BLOODELF_TROOPER = 'nbel'
    constant integer UNIT_BLOODELF_PHOENIX = 'h009'
    constant integer UNIT_BLOODELF_PHOENIX_ALT = 'h00A'
    constant integer UNIT_BLOODELF_GOLEM = 'n02H'
    constant integer UNIT_BLOODELF_PRIEST = 'hmpr'
    constant integer UNIT_BLOODELF_SORCERESS = 'hsor'
    constant integer UNIT_BLOODELF_BREAKER = 'h01R'
    constant integer UNIT_BLOODELF_HAWKRIDER = 'h01S'
    constant integer UNIT_BLOODELF_ASSAULT = 'nws1'
   
    constant integer BUILD_BLOODELF_HALL1 = 'h001'
    constant integer BUILD_BLOODELF_HALL2 = 'h002'
    constant integer BUILD_BLOODELF_HALL3 = 'h003'
    constant integer BUILD_BLOODELF_FARM = 'nefm'
    constant integer BUILD_BLOODELF_BARRACKS = 'nheb'
    constant integer BUILD_BLOODELF_LUMBERMILL = 'h00B'
    constant integer BUILD_BLOODELF_BLACKSMITH = 'h015'
    constant integer BUILD_BLOODELF_ALTAR = 'h016'
    constant integer BUILD_BLOODELF_TOWER = 'negt'
    constant integer BUILD_BLOODELF_TOWER_AG = 'negf'
    constant integer BUILD_BLOODELF_TOWER_AA = 'negm'
    constant integer BUILD_BLOODELF_SANCTUM = 'h601'
    constant integer BUILD_BLOODELF_OBSERVATORY = 'haro'
    constant integer BUILD_BLOODELF_SHOP = 'h01Q'
    constant integer BUILD_BLOODELF_AVIARY = 'h01A'

function TownCountEx takes integer unitid, boolean only_done, integer townid returns integer

    local integer have_qty = GetUnitCountEx(unitid,only_done,townid)
    // Official units
    if unitid == TOWN_HALL then
        set have_qty = have_qty + GetUnitCountEx(KEEP,false,townid) + GetUnitCountEx(CASTLE,false,townid)
    elseif unitid == KEEP then
        set have_qty = have_qty  + GetUnitCountEx(CASTLE,false,townid)

    elseif unitid == WATCH_TOWER then
        set have_qty = have_qty + GetUnitCountEx(GUARD_TOWER,false,townid) + GetUnitCountEx(CANNON_TOWER,false,townid) + GetUnitCountEx(ARCANE_TOWER,false,townid)

    elseif unitid == PEASANT then
        set have_qty = have_qty + GetUnitCountEx(MILITIA,false,townid)

    // Custom units
    // Human
    elseif unitid == UNIT_HUMAN_FOOTMAN then
        set have_qty = have_qty + GetUnitCountEx(UNIT_HUMAN_CAPTAIN,false,townid)
    elseif unitid == UNIT_HUMAN_SIEGEENGINE then
        set have_qty = have_qty + GetUnitCountEx(UNIT_HUMAN_SIEGEENGINE_ALT,false,townid)
    // Blood Elf
    elseif unitid == UNIT_BLOODELF_PHOENIX then
        set have_qty = have_qty + GetUnitCountEx(UNIT_BLOODELF_PHOENIX_ALT,false,townid)
    elseif unitid == BUILD_BLOODELF_HALL1 then
        set have_qty = have_qty + GetUnitCountEx(BUILD_BLOODELF_HALL2,false,townid) + GetUnitCountEx(BUILD_BLOODELF_HALL3,false,townid)
    elseif unitid == BUILD_BLOODELF_HALL2 then
        set have_qty = have_qty + GetUnitCountEx(BUILD_BLOODELF_HALL3,false,townid)
    elseif unitid == BUILD_BLOODELF_TOWER then
        set have_qty = have_qty + GetUnitCountEx(BUILD_BLOODELF_TOWER_AA,false,townid) + GetUnitCountEx(BUILD_BLOODELF_TOWER_AG,false,townid)

I imported my edited common.ai(from InsaneMonster's v2) and other ai scripts to my campaign pack file and modified their path 'Scripts\common.ai', 'Scripts\06BloodElf.ai',
But now they don't work at all. This is my first time to fix the common ai itself, so I can't even fathom where the problem occurred.
DemoJassSyntaxChecker seems to recognize only the original common.ai. (Probably 1.06 version)
 
Level 8
Joined
May 12, 2018
Messages
106
I've done a quick test, and if the original common_v2.ai of InsaneMonster or common.ai that I modified are imported into the map, even the races default AI (like orc.ai) doesn't work at all. I think WC3 cannot recognize replaced common.ai internally.

but when I played Re-Reforged in the morning, InsaneMonster's AIs in RR Demo are works well, I don't know where the problems occur from....
ver 1.36.0.20257
 
Last edited:
Top