* Create a new bullet Unit. * * @param position Where on the map this bullet Unit is created. * @param typeID The type of the new bullet Unit. * @param houseID The House of the new bullet Unit. * @param damage The hitpoints of the new bullet Unit. * @param target The target of the new bullet Unit. * @return The new created Unit, or NULL if something failed. */
| 1952 | * @return The new created Unit, or NULL if something failed. |
| 1953 | */ |
| 1954 | Unit *Unit_CreateBullet(tile32 position, UnitType type, uint8 houseID, uint16 damage, uint16 target) |
| 1955 | { |
| 1956 | const UnitInfo *ui; |
| 1957 | tile32 tile; |
| 1958 | |
| 1959 | if (!Tools_Index_IsValid(target)) return NULL; |
| 1960 | |
| 1961 | ui = &g_table_unitInfo[type]; |
| 1962 | tile = Tools_Index_GetTile(target); |
| 1963 | |
| 1964 | switch (type) { |
| 1965 | case UNIT_MISSILE_HOUSE: |
| 1966 | case UNIT_MISSILE_ROCKET: |
| 1967 | case UNIT_MISSILE_TURRET: |
| 1968 | case UNIT_MISSILE_DEVIATOR: |
| 1969 | case UNIT_MISSILE_TROOPER: { |
| 1970 | int8 orientation; |
| 1971 | Unit *bullet; |
| 1972 | Unit *u; |
| 1973 | |
| 1974 | orientation = Tile_GetDirection(position, tile); |
| 1975 | |
| 1976 | bullet = Unit_Create(UNIT_INDEX_INVALID, type, houseID, position, orientation); |
| 1977 | if (bullet == NULL) return NULL; |
| 1978 | |
| 1979 | Voice_PlayAtTile(ui->bulletSound, position); |
| 1980 | |
| 1981 | bullet->targetAttack = target; |
| 1982 | bullet->o.hitpoints = damage; |
| 1983 | bullet->currentDestination = tile; |
| 1984 | |
| 1985 | if (ui->flags.notAccurate) { |
| 1986 | bullet->currentDestination = Tile_MoveByRandom(tile, (Tools_Random_256() & 0xF) != 0 ? Tile_GetDistance(position, tile) / 256 + 8 : Tools_Random_256() + 8, false); |
| 1987 | } |
| 1988 | |
| 1989 | bullet->fireDelay = ui->fireDistance & 0xFF; |
| 1990 | |
| 1991 | u = Tools_Index_GetUnit(target); |
| 1992 | if (u != NULL && g_table_unitInfo[u->o.type].movementType == MOVEMENT_WINGER) { |
| 1993 | bullet->fireDelay <<= 1; |
| 1994 | } |
| 1995 | |
| 1996 | if (type == UNIT_MISSILE_HOUSE || (bullet->o.seenByHouses & (1 << g_playerHouseID)) != 0) return bullet; |
| 1997 | |
| 1998 | Tile_RemoveFogInRadius(bullet->o.position, 2); |
| 1999 | |
| 2000 | return bullet; |
| 2001 | } |
| 2002 | |
| 2003 | case UNIT_BULLET: |
| 2004 | case UNIT_SONIC_BLAST: { |
| 2005 | int8 orientation; |
| 2006 | tile32 t; |
| 2007 | Unit *bullet; |
| 2008 | |
| 2009 | orientation = Tile_GetDirection(position, tile); |
| 2010 | |
| 2011 | t = Tile_MoveByDirection(Tile_MoveByDirection(position, 0, 32), orientation, 128); |
no test coverage detected