* 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. */
| 1978 | * @return The type (either UnitType or StructureType) of what we should build next. |
| 1979 | */ |
| 1980 | uint16 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 | } |
no test coverage detected