/** * Make the current unit harvest spice. * * Stack: *none*. * * @param script The script engine to operate on. * @return ??. */ uint16 Script_Unit_Harvest(ScriptEngine *script) { Unit *u; uint16 packed; uint16 type; VARIABLE_NOT_USED(script); u = g_scriptCurrentUnit; if (u->o.type != UNIT_HARVESTER) return 0; if (u->amount >= 100) return 0; packed = Tile_PackTile(u->o.position); type = Map_GetLandscapeType(packed); if (type != LST_SPICE && type != LST_THICK_SPICE) return 0; u->amount += Tools_Random_256() & 1; u->o.flags.s.inTransport = true; Unit_UpdateMap(2, u); if (u->amount > 100) u->amount = 100; if ((Tools_Random_256() & 0x1F) != 0) return 1; Map_ChangeSpiceAmount(packed, -1); return 0; }
/** * Handle damage to a tile, removing spice, removing concrete, stuff like that. * @param e The Explosion to handle damage on. * @param parameter Unused parameter. */ static void Explosion_Func_TileDamage(Explosion *e, uint16 parameter) { static const int16 craterIconMapIndex[] = { -1, 2, 1 }; uint16 packed; uint16 type; Tile *t; int16 iconMapIndex; uint16 overlaySpriteID; uint16 *iconMap; VARIABLE_NOT_USED(parameter); packed = Tile_PackTile(e->position); if (!Map_IsPositionUnveiled(packed)) return; type = Map_GetLandscapeType(packed); if (type == LST_STRUCTURE || type == LST_DESTROYED_WALL) return; t = &g_map[packed]; if (type == LST_CONCRETE_SLAB) { t->groundSpriteID = g_mapSpriteID[packed]; Map_Update(packed, 0, false); } if (g_table_landscapeInfo[type].craterType == 0) return; /* You cannot damage veiled tiles */ overlaySpriteID = t->overlaySpriteID; if (!Sprite_IsUnveiled(overlaySpriteID)) return; iconMapIndex = craterIconMapIndex[g_table_landscapeInfo[type].craterType]; iconMap = &g_iconMap[g_iconMap[iconMapIndex]]; if (iconMap[0] <= overlaySpriteID && overlaySpriteID <= iconMap[10]) { /* There already is a crater; make it bigger */ overlaySpriteID -= iconMap[0]; if (overlaySpriteID < 4) overlaySpriteID += 2; } else { /* Randomly pick 1 of the 2 possible craters */ overlaySpriteID = Tools_Random_256() & 1; } /* Reduce spice if there is any */ Map_ChangeSpiceAmount(packed, -1); /* Boom a bloom if there is one */ if (t->groundSpriteID == g_bloomSpriteID) { Map_Bloom_ExplodeSpice(packed, g_playerHouseID); return; } /* Update the tile with the crater */ t->overlaySpriteID = overlaySpriteID + iconMap[0]; Map_Update(packed, 0, false); }