MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Structure_AI_PickNextToBuild

Function Structure_AI_PickNextToBuild

src/structure.c:1980–2040  ·  view source on GitHub ↗

* Find the next object to build. * @param s The structure in which we can build something. * @return The type (either UnitType or StructureType) of what we should build next. */

Source from the content-addressed store, hash-verified

1978 * @return The type (either UnitType or StructureType) of what we should build next.
1979 */
1980uint16 Structure_AI_PickNextToBuild(Structure *s)
1981{
1982 PoolFindStruct find;
1983 uint16 buildable;
1984 uint16 type;
1985 House *h;
1986 int i;
1987
1988 if (s == NULL) return 0xFFFF;
1989
1990 h = House_Get_ByIndex(s->o.houseID);
1991 buildable = Structure_GetBuildable(s);
1992
1993 if (s->o.type == STRUCTURE_CONSTRUCTION_YARD) {
1994 for (i = 0; i < 5; i++) {
1995 type = h->ai_structureRebuild[i][0];
1996
1997 if (type == 0) continue;
1998 if ((buildable & (1 << type)) == 0) continue;
1999
2000 return type;
2001 }
2002
2003 return 0xFFFF;
2004 }
2005
2006 if (s->o.type == STRUCTURE_HIGH_TECH) {
2007 find.houseID = s->o.houseID;
2008 find.index = 0xFFFF;
2009 find.type = UNIT_CARRYALL;
2010
2011 while (true) {
2012 Unit *u;
2013
2014 u = Unit_Find(&find);
2015 if (u == NULL) break;
2016
2017 buildable &= ~FLAG_UNIT_CARRYALL;
2018 }
2019 }
2020
2021 if (s->o.type == STRUCTURE_HEAVY_VEHICLE) {
2022 buildable &= ~FLAG_UNIT_HARVESTER;
2023 buildable &= ~FLAG_UNIT_MCV;
2024 }
2025
2026 type = 0xFFFF;
2027 for (i = 0; i < UNIT_MAX; i++) {
2028 if ((buildable & (1 << i)) == 0) continue;
2029
2030 if ((Tools_Random_256() % 4) == 0) type = i;
2031
2032 if (type != 0xFFFF) {
2033 if (g_table_unitInfo[i].o.priorityBuild <= g_table_unitInfo[type].o.priorityBuild) continue;
2034 }
2035
2036 type = i;
2037 }

Callers 1

GameLoop_StructureFunction · 0.85

Calls 4

House_Get_ByIndexFunction · 0.85
Structure_GetBuildableFunction · 0.85
Unit_FindFunction · 0.85
Tools_Random_256Function · 0.85

Tested by

no test coverage detected