* Fire a bullet or missile from a (rocket) turret. * * Stack: *none* * Variables: 2 - Target to shoot at. * * @param script The script engine to operate on. * @return The time between this and the next time firing. */
| 511 | * @return The time between this and the next time firing. |
| 512 | */ |
| 513 | uint16 Script_Structure_Fire(ScriptEngine *script) |
| 514 | { |
| 515 | Structure *s; |
| 516 | Unit *u; |
| 517 | tile32 position; |
| 518 | uint16 target; |
| 519 | uint16 damage; |
| 520 | uint16 fireDelay; |
| 521 | uint16 type; |
| 522 | |
| 523 | s = g_scriptCurrentStructure; |
| 524 | |
| 525 | target = script->variables[2]; |
| 526 | if (target == 0) return 0; |
| 527 | |
| 528 | if (s->o.type == STRUCTURE_ROCKET_TURRET && Tile_GetDistance(Tools_Index_GetTile(target), s->o.position) >= 0x300) { |
| 529 | type = UNIT_MISSILE_TURRET; |
| 530 | damage = 30; |
| 531 | fireDelay = Tools_AdjustToGameSpeed(g_table_unitInfo[UNIT_LAUNCHER].fireDelay, 1, 0xFFFF, true); |
| 532 | } else { |
| 533 | type = UNIT_BULLET; |
| 534 | damage = 20; |
| 535 | fireDelay = Tools_AdjustToGameSpeed(g_table_unitInfo[UNIT_TANK].fireDelay, 1, 0xFFFF, true); |
| 536 | } |
| 537 | |
| 538 | position.x = s->o.position.x + 0x80; |
| 539 | position.y = s->o.position.y + 0x80; |
| 540 | u = Unit_CreateBullet(position, type, s->o.houseID, damage, target); |
| 541 | |
| 542 | if (u == NULL) return 0; |
| 543 | |
| 544 | u->originEncoded = Tools_Index_Encode(s->o.index, IT_STRUCTURE); |
| 545 | |
| 546 | return fireDelay; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Make the structure explode. |
nothing calls this directly
no test coverage detected