* Destroy a structure and spawn soldiers around the place. * * Stack: *none* * * @param script The script engine to operate on. * @return Always 0. */
| 587 | * @return Always 0. |
| 588 | */ |
| 589 | uint16 Script_Structure_Destroy(ScriptEngine *script) |
| 590 | { |
| 591 | Structure *s; |
| 592 | uint16 position; |
| 593 | uint16 layout; |
| 594 | uint16 i; |
| 595 | |
| 596 | VARIABLE_NOT_USED(script); |
| 597 | |
| 598 | s = g_scriptCurrentStructure; |
| 599 | layout = g_table_structureInfo[s->o.type].layout; |
| 600 | position = Tile_PackTile(s->o.position); |
| 601 | |
| 602 | Structure_Remove(s); |
| 603 | |
| 604 | for (i = 0; i < g_table_structure_layoutTileCount[layout]; i++) { |
| 605 | tile32 tile; |
| 606 | Unit *u; |
| 607 | |
| 608 | tile = Tile_UnpackTile(position + g_table_structure_layoutTiles[layout][i]); |
| 609 | |
| 610 | if (g_table_structureInfo[s->o.type].o.spawnChance < Tools_Random_256()) continue; |
| 611 | |
| 612 | u = Unit_Create(UNIT_INDEX_INVALID, UNIT_SOLDIER, s->o.houseID, tile, Tools_Random_256()); |
| 613 | if (u == NULL) continue; |
| 614 | |
| 615 | u->o.hitpoints = g_table_unitInfo[UNIT_SOLDIER].o.hitpoints * (Tools_Random_256() & 3) / 256; |
| 616 | |
| 617 | if (s->o.houseID != g_playerHouseID) { |
| 618 | Unit_SetAction(u, ACTION_ATTACK); |
| 619 | continue; |
| 620 | } |
| 621 | |
| 622 | Unit_SetAction(u, ACTION_MOVE); |
| 623 | |
| 624 | tile = Tile_MoveByRandom(u->o.position, 32, true); |
| 625 | |
| 626 | u->targetMove = Tools_Index_Encode(Tile_PackTile(tile), IT_TILE); |
| 627 | } |
| 628 | |
| 629 | if (g_debugScenario) return 0; |
| 630 | if (s->o.houseID != g_playerHouseID) return 0; |
| 631 | |
| 632 | if (g_config.language == LANGUAGE_FRENCH) { |
| 633 | GUI_DisplayText("%s %s %s", 0, String_Get_ByIndex(g_table_structureInfo[s->o.type].o.stringID_full), g_table_houseInfo[s->o.houseID].name, String_Get_ByIndex(STR_IS_DESTROYED)); |
| 634 | } else { |
| 635 | GUI_DisplayText("%s %s %s", 0, g_table_houseInfo[s->o.houseID].name, String_Get_ByIndex(g_table_structureInfo[s->o.type].o.stringID_full), String_Get_ByIndex(STR_IS_DESTROYED)); |
| 636 | } |
| 637 | |
| 638 | return 0; |
| 639 | } |
nothing calls this directly
no test coverage detected