• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 09:25
CET 15:25
KST 23:25
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Winners11Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t TL.net Map Contest #21: Winners StarCraft, SC2, HotS, WC3, Returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win
Tourneys
Constellation Cup - Main Event - Stellar Fest Sparkling Tuna Cup - Weekly Open Tournament $5,000+ WardiTV 2025 Championship Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle BW General Discussion [ASL20] Ask the mapmakers — Drop your questions BGH Auto Balance -> http://bghmmr.eu/ Where's CardinalAllin/Jukado the mapmaker?
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group A - Saturday 21:00 CET [BSL21] RO32 Group B - Sunday 21:00 CET
Strategy
PvZ map balance Current Meta How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Should offensive tower rushing be viable in RTS games? Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The Games Industry And ATVI YouTube Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Learning my new SC2 hotkey…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1611 users

BWAPI, and an inside look into StarCraft's code - Page 2

Forum Index > BW General
Post a Reply
Prev 1 2 All
Sonko
Profile Joined February 2019
154 Posts
October 27 2019 09:24 GMT
#21
Really enjoyed your series on molesting crabs and such, looking forward to your newest deep dive!


Thank you! Hovercrabs cannot be molested enough!
A site about brood war AI: www.makingcomputerdothings.com
Peeano
Profile Blog Joined March 2009
Netherlands5185 Posts
October 27 2019 13:35 GMT
#22
When I issue attack move command on a group of medics and marines, the medics will act the same as if I ordered the heal move command.
I always assumed it was because heal also has the hotkey a (by default). If I change the attack move hotkey from A to Z and issue attack move via Z Medic/Marine in the same group will make the medics respond the same.

My conclusion is they have coded attack move on medics to work the same as the heal command. Because other non-attacking units receive the attack move command just move instead.

If you select a group of carriers and build interceptors, all carriers will build interceptors. The same way a group of reavers will all build scarabs. Or all tanks will siege, etc.

Can you easily decipher from the code if all these special actions are specifically unique?
I'm basically asking if there is any combination where you can have 2 (or more) different units listen to same assigned hotkey the way medic marine do.

I've tried to set scarab building and interceptors to the same hotkey. In hopes that I can order a group of carriers and reavers to both build interceptors and scarabs respectively, but it doesn't work.
And I've been wondering if it is ever possible to combine 2 commands in one hotkey? For example burrow and siege mode or mael strom and psionic storm? I'm curious but too lazy to test all combinations.
Imagine being able to cast ensare and plague with just 1 click, or storm and mael strom...

Can you see how the area plague hits is defined in code? Because from my experience it seems like the aoe is slightly skewed to the right of where you click instead of being centered and ever since I wondered if it may be a small number mistake in coding.
FBH #1!
Sonko
Profile Joined February 2019
154 Posts
October 27 2019 17:32 GMT
#23
Hi Peeano,

I was considering answering your questions one by one, but truth to be told, all of these are to be covered in later articles, so just stay tuned. If you have some coding background, you can take a look in the source files of openBW here:

https://github.com/OpenBW/openbw/blob/master/bwgame.h
A site about brood war AI: www.makingcomputerdothings.com
ThunderJunk
Profile Joined December 2015
United States711 Posts
October 27 2019 20:49 GMT
#24
Wow, what an excellent series of articles. Thank you so much for sharing.

I had no idea that all ranged attacks have a 1/256 miss chance by default!
I am free because I know that I alone am morally responsible for everything I do.
[UoN]Sentinel
Profile Blog Joined November 2009
United States11320 Posts
Last Edited: 2019-10-27 21:56:41
October 27 2019 21:45 GMT
#25
Btw you reference an appendix often, is this posted anywhere on the site? I'm assuming it's lifted from the forthcoming book where you do have an appendix, but there's a few things I'd like to check if you already have it up.

Also nitpick about this section:


Second, an addition to the Energy segment of unit abilities:

The starting energy of a unit is the quarter of the maximum energy of the unit type (rounded up), so upgrades affect it. The exception is the Protoss Shield Battery, with the starting energy of 100.

Dark Archon is another exception. They always start with 50 energy even with Argus Talisman researched.
Нас зовет дух отцов, память старых бойцов, дух Москвы и твердыня Полтавы
Sonko
Profile Joined February 2019
154 Posts
October 28 2019 08:35 GMT
#26
Hi,

Btw you reference an appendix often, is this posted anywhere on the site? I'm assuming it's lifted from the forthcoming book where you do have an appendix, but there's a few things I'd like to check if you already have it up.


Not yet. What are you curious about? Maybe I can look it up for you. Also, I'm considering adding stat blocks and weapon statistics to the untits' description - a little bit redundant, but maybe it would look good.

Dark Archon energy: Thanks for the find, I will add that!
A site about brood war AI: www.makingcomputerdothings.com
Freakling
Profile Joined October 2012
Germany1529 Posts
October 30 2019 00:13 GMT
#27
This is very interesting:
[image loading]

Particularly because ScmDraft does not implement this correctly yet. Gotta ask SI about it.

Anyway, I looked it up, and the function to calculate distances looks like this in OpenBW:
	int xy_length(xy vec) const {
unsigned int x = std::abs(vec.x);
unsigned int y = std::abs(vec.y);
if (x < y) std::swap(x, y);
if (x / 4 < y) x = x - x / 16 + y * 3 / 8 - x / 64 + y * 3 / 256;
return x;
}

It's easy to see how this would give you a dodecagonal structure like depicted above, although I haven't figured out how they came up with this particular approximation yet. Also gotta wonder why they did not just use simple Euclidian distance (I know that square roots are computationally bad, but there is little need to ever calculate and actual distance, only thing of interest is usually to check whether something is within a certain range, which can be done using only squares).
Anyway, this is certainly an interesting piece of code that you should discuss in some detail when you talk about distances.
aqrit
Profile Joined January 2016
13 Posts
Last Edited: 2019-10-30 22:49:21
October 30 2019 22:42 GMT
#28
(a*a + b*b) costs up to 80 cycles in "ye olden times" (warcraft 2 era)
LG)Sabbath
Profile Blog Joined July 2005
Argentina3024 Posts
October 30 2019 23:22 GMT
#29
Also aren't all these division operations optimizable by using bit shifting?

PS. does anyone know if there's any info about the save game file formats (single or multiplayer) anywhere? I have not found anything on google at all
https://www.twitch.tv/argsabbath/
Sonko
Profile Joined February 2019
154 Posts
November 02 2019 10:34 GMT
#30
so gotta wonder why they did not just use simple Euclidian distance


In uniform grids, that is usually not the best approximation.Generally, the Manhattan distance is considered to be best.
Here is a link that explains the what and why:
http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#heuristics-for-grid-maps

Also aren't all these division operations optimizable by using bit shifting?


In the openBW code, there are often bitshifts. But that's a decompiled reverse-engineered version. Functionally identical, but I'm not sure that these things are exactly the same. They probably are, though.

PS. does anyone know if there's any info about the save game file formats (single or multiplayer) anywhere? I have not found anything on google at all


Yeah, surprisingly little information. I'm not there yet.
A site about brood war AI: www.makingcomputerdothings.com
Sonko
Profile Joined February 2019
154 Posts
Last Edited: 2019-11-04 13:12:52
November 04 2019 13:12 GMT
#31
Hi everyone, I updated the article a bit. Some ranges were not entirely correct, and rephrased some things to be more clear.
https://makingcomputerdothings.com/brood-war-api-the-comprehensive-guide-movement-modifiers-and-terran-units/

Maybe the most interesting thing is the firebat attack pattern - I created an image that showcases how the Firebat hits work.
(with iscript source)
[image loading]
A site about brood war AI: www.makingcomputerdothings.com
Sonko
Profile Joined February 2019
154 Posts
November 13 2019 17:51 GMT
#32
I have updated and reworked some stuff since - and updated the Firebat image to be more clear.
But in bigger news here is the next part:
Brood War API – The Comprehensive Guide: Terran units continued, and some Zerg ones

Enjoy!
A site about brood war AI: www.makingcomputerdothings.com
2Pacalypse-
Profile Joined October 2006
Croatia9517 Posts
November 14 2019 02:04 GMT
#33
Awesome! Really cool stuff dude.

One small suggestion: drop "BWAPI" from the name of the articles. Seems like most (all?) of these articles are describing the internals of BW itself and don't have much to do with BWAPI, so it might just cause confusion. If there are some articles that talk about BWAPI, then it'd be good to recognize those as such.
Moderator"We're a community of geniuses because we've found how to extract 95% of the feeling of doing something amazing without actually doing anything." - Chill
Sonko
Profile Joined February 2019
154 Posts
November 14 2019 09:35 GMT
#34
One small suggestion: drop "BWAPI" from the name of the articles. Seems like most (all?) of these articles are describing the internals of BW itself and don't have much to do with BWAPI, so it might just cause confusion. If there are some articles that talk about BWAPI, then it'd be good to recognize those as such.


In the long run, this is a part of the BWAPI book - this chapter just got a little bit longer than I anticipated
A site about brood war AI: www.makingcomputerdothings.com
2Pacalypse-
Profile Joined October 2006
Croatia9517 Posts
November 14 2019 13:58 GMT
#35
On November 14 2019 18:35 Sonko wrote:
Show nested quote +
One small suggestion: drop "BWAPI" from the name of the articles. Seems like most (all?) of these articles are describing the internals of BW itself and don't have much to do with BWAPI, so it might just cause confusion. If there are some articles that talk about BWAPI, then it'd be good to recognize those as such.


In the long run, this is a part of the BWAPI book - this chapter just got a little bit longer than I anticipated

It might be a good idea to be able to quickly sort BWAPI articles from non-BWAPI articles, so that people who are only interested in BW internals and not so much in BWAPI itself, could quickly find what they're looking for ^^.
Moderator"We're a community of geniuses because we've found how to extract 95% of the feeling of doing something amazing without actually doing anything." - Chill
Sonko
Profile Joined February 2019
154 Posts
November 14 2019 14:16 GMT
#36
By the way, I lied a lot. Here are some corrections, or rather, clarifications - just as an example
I made these corrections in the article as well. I'm constantly revising, rephrasing, and verifying all of this - not without help, of course.
When upgraded, the Vulture is the fastest unit in the game.
- technically, only the unit with the fastest average top speed among the controllable units. Nukes, scarabs, and interceptors are faster, for example.

(Spider mines) After being laid, it is invisible in the ground (like burrowed units)

They actually take some time to become invisible.

Added this section to the spider mine damage section:
"It fires a stationary bullet when 30 distance away from the target, then gets destroyed 9 frames later. Since this is splash damage, this explains why running away from mines can reduce the damage taken. (See Combat and Damage for more details)"

The tank's turret and base are handled as two separate units in the game code, but that has no bearing on gameplay.


That was a blatant lie. Corrected it to:

This allows the turret to face an enemy unit, while the body moves in a different direction. So when stopping and attacking, the unit does not need to change facing, effectively making it a bit more effective at hit and rtun attacks.

Also with Goliaths:
The turret can turn away from the direction of the body, but has a limit of 32 angle units, so in practice this works more like an increased fire arc.



the Valkyrie fires 8 rockets, and cannot move until all of them are fired.


It can, it just cannot be interrupted during this.

Larva timing is further clarfiied to this. (Imagine digging this out)
Each Hatchery has a larva_timer variable, which is set to 37 when a larva is spawned. This gets decreased every 9 frames, but that timer is randomized every 150 frames. So this timer is subject to 2 or 3 randomizations. This means that as long the larva count is never max, larva will spawn every 328-361 frames, otherwise this number will vary between 319-360.


I also added this to the Spore Colony:
Since it’s a building, the detection range is 7 tiles, or 7*32 pixels, which is not the same as the unit’s sight range)
but spore colony does not


It's of course, a matter of how precise I want to be exactly. At some point, it's a pointless exercise, but I feel I'm far from it.

Kudos if you have noticed any of these while reading the article :D

A site about brood war AI: www.makingcomputerdothings.com
Sonko
Profile Joined February 2019
154 Posts
November 14 2019 14:16 GMT
#37

It might be a good idea to be able to quickly sort BWAPI articles from non-BWAPI articles, so that people who are only interested in BW internals and not so much in BWAPI itself, could quickly find what they're looking for ^^.


Okay, you have a point, I'll add some clarifying label.
A site about brood war AI: www.makingcomputerdothings.com
2Pacalypse-
Profile Joined October 2006
Croatia9517 Posts
November 14 2019 14:35 GMT
#38
Another small suggestion: you should update the original post of this thread to include all of the newer articles as well.
Moderator"We're a community of geniuses because we've found how to extract 95% of the feeling of doing something amazing without actually doing anything." - Chill
Sonko
Profile Joined February 2019
154 Posts
November 14 2019 14:46 GMT
#39
Another small suggestion: you should update the original post of this thread to include all of the newer articles as well.


Thanks, I wasn't aware I can do that. Added the new articles!
A site about brood war AI: www.makingcomputerdothings.com
Xeofreestyler
Profile Blog Joined June 2005
Belgium6773 Posts
November 14 2019 19:59 GMT
#40
This is AWESOME. Thank you!
Graphics
Prev 1 2 All
Please log in or register to reply.
Live Events Refresh
Wardi Open
12:00
#59
WardiTV1781
OGKoka 355
Rex115
IntoTheiNu 55
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 355
Hui .271
Rex 115
Vindicta 22
StarCraft: Brood War
Rain 7041
Jaedong 3100
Horang2 1877
Sea 1852
GuemChi 1742
firebathero 324
Stork 320
Pusan 295
Mini 286
Larva 220
[ Show more ]
Hyun 167
PianO 76
Backho 67
Killer 61
ggaemo 58
Aegong 45
ToSsGirL 43
JulyZerg 42
sSak 42
Mong 35
sas.Sziky 25
soO 19
Rock 13
zelot 12
scan(afreeca) 10
Noble 7
SilentControl 7
Terrorterran 6
ajuk12(nOOB) 6
Dota 2
Gorgc4445
qojqva2629
Dendi962
XcaliburYe235
420jenkins143
syndereN28
Counter-Strike
olofmeister1676
oskar102
Other Games
B2W.Neo968
Pyrionflax441
hiko436
crisheroes334
Lowko271
Fuzer 220
Sick210
Liquid`LucifroN145
Mew2King94
QueenE56
fpsfer 0
Organizations
StarCraft: Brood War
lovetv 9
Kim Chul Min (afreeca) 5
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Michael_bg 3
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV297
League of Legends
• Nemesis2118
• TFBlade538
Upcoming Events
Wardi Open
1h 35m
Replay Cast
8h 35m
WardiTV Korean Royale
21h 35m
Replay Cast
1d 8h
Replay Cast
1d 18h
Kung Fu Cup
1d 21h
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
2 days
The PondCast
2 days
RSL Revival
2 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
2 days
[ Show More ]
WardiTV Korean Royale
2 days
PiGosaur Monday
3 days
RSL Revival
3 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
3 days
CranKy Ducklings
4 days
RSL Revival
4 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
4 days
BSL 21
5 days
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
5 days
RSL Revival
5 days
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
5 days
WardiTV Korean Royale
5 days
BSL 21
6 days
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
Wardi Open
6 days
Liquipedia Results

Completed

Proleague 2025-11-07
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.