Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 0049ECF0 = InitializeUnit(), arg 1 unit_id, arg 2 x, arg 3 player, eax Unit *unit, edx y | Called also when transformed -- Needs ASM pseudocode
- pub unsafe fn init_unit_hook(
- unitid: u32,
- arg_x: u32,
- player: u32,
- unit: *mut bw::Unit,
- arg_y: u32,
- orig: &dyn Fn(u32, u32, u32, *mut Unit u32,)->u32)->u32 {
- let unit = match Unit::from_ptr(unit) {
- Some(s) => s,
- None => {
- return orig(unitid, arg_x, player, unit, arg_y);
- },
- };
- let mut result: u32 = 0;
- let mut active_unit = bw::active_iscript_unit;
- let mut flingy = bw::units_dat_flingy[unitid];
- if bw::init_flingy(flingy, arg_y as u16, arg_x, unit, player as u8, 0) == 0 {
- //blockA
- result = 0;
- return result;
- }
- (*unit.0).player = player;
- (*unit.0).order = 0xBC; // Fatal
- (*unit.0).order_state = 0;
- (*unit.0).order_signal = 0;
- (*unit.0).order_fow_unit = 0;
- (*unit.0).order_timer = 0;
- (*unit.0).target = 0;
- (*unit.0).order_target_pos = 0;
- let first_child = (*unit.0).unit_specific; // assumed to be first_inside_child
- (*first_child.0).hitpoints = 0;
- (*first_child.0).sprite = 0;
- (*unit.0).unit_id = unitid;
- let mut sprite = (*unit.0).sprite;
- (*unit.0).carried_powerup_flags = 0;
- (*unit.0).secondary_order_wait = 0;
- if sprite != null_mut() {
- //blockB
- bw::progress_sprite_frame(sprite);
- (*unit.0).last_attacking_player = 0;
- (*unit.0).shields = bw::units_dat_shields[unitid] << 8;
- if unitid != 0xAC { // Shield Battery
- //blockC
- (*unit.0).energy = (bw::get_max_energy(unit.0) + (active_unit & 3)) << 2; // active_unit might also be player_id, or have defaulted to arg_y
- }
- else {
- (*unit.0).energy = 6400;
- }
- //blockD
- (*unit.0).ai_spell_flags = 0;
- (*sprite.0).elevation_level = bw::units_dat_elevation_level[unitid];
- let mut datFlags = bw::units_dat_flags[unitid] >> 1;
- let mut unitFlags = (*unit.0).flags;
- datFlags ^= unitFlags;
- unitFlags ^= unitFlags & 2; // Landed building
- datFlags ^= unitFlags;
- unitFlags = datFlags & 4 ^= unitFlags; // Air
- datFlags = bw::units_dat_flags[unitid] >> 0xC;
- datFlags ^= unitFlags;
- datFlags &= 0x10000; // Organic
- datFlags ^= unitFlags;
- unitFlags = datFlags;
- datFlags = bw::units_dat_flags[unitid] >> 0xA;
- datFlags ^= unitFlags;
- datFlags &= 0x20000; // Requires creep?
- datFlags ^= unitFlags;
- unitFlags = datFlags;
- unitFlags >> 2;
- unitFlags << 14;
- !unitFlags;
- unitFlags ^= datFlags;
- unitFlags &= 0x100000; // Burrowable
- unitFlags ^= datFlags;
- (*unit.0).flags = unitFlags;
- let mut pathFlags = (*unit.0).pathing_flags;
- let mut eax: u8 = 0;
- if bw::units_dat_elevation_level[unitid] < 0xC {
- eax = 1;
- }
- else {
- eax = 0;
- }
- eax ^= pathFlags;
- pathFlags = 1;
- eax ^= pathFlags;
- (*unit.0).pathing_flags = eax;
- if unitid < 0xC2 { // Zerg Beacon
- //blockE
- if unitid != 0xCC { // Floor Hatch
- //blockG
- if (bw::units_dat_flags[unitid] & 1) == 0 { // Building
- (*unit.0).tech = 0x2C;
- (*unit.0).upgrade = 0x3D;
- }
- }
- //blockF
- (*unit.0).flags |= 0x200000; // No collision
- }
- if unitid <= 0xC7 { // Protoss Flag Beacon
- //blockF
- (*unit.0).flags |= 0x200000; // No collision
- //blockG
- if (bw::units_dat_flags[unitid] & 1) == 0 { // Building
- (*unit.0).tech = 0x2C;
- (*unit.0).upgrade = 0x3D;
- }
- }
- //blockH
- eax = 0;
- (*unit.0).path = 0;
- (*unit.0).movement_state = 0;
- (*unit.0).move_target_update_timer = 0;
- let mut imageid = (*sprite.0).image.image_id;
- let mut buildTime = bw::units_dat_build_time[unit];
- if (bw::units_dat_flags[unitid] & 0x20000000) == 1 { // Invincible
- //blockI
- if (bw::units_dat_flags[unitid] & 0x20000000) == 0 { // Invincible
- //blockK
- (*unit.0).building_overlay_state = bw::building_overlay_state_max[sprite];
- (*unit.0).remaining_build_time = buildTime;
- if buildTime == 0 {
- (*unit.0).remaining_build_time = 1;
- }
- //blockL
- bw::set_build_hp_gain(unit.0);
- bw::set_build_shield_gain(unit.0);
- bw::set_upgrade_speed(unit.0);
- bw::update_speed(unit.0);
- result = 1;
- return result;
- }
- eax = (*unit.0).flags;
- eax &= 0xFBFF_FFFF
- }
- else {
- eax |= 4000000; // Invincible
- }
- //blockJ
- (*unit.0).flags = eax;
- //blockK
- (*unit.0).building_overlay_state = bw::building_overlay_state_max[sprite];
- (*unit.0).remaining_build_time = buildTime;
- if buildTime == 0 {
- (*unit.0).remaining_build_time = 1;
- }
- //blockL
- bw::set_build_hp_gain(unit.0);
- bw::set_build_shield_gain(unit.0);
- bw::set_upgrade_speed(unit.0);
- bw::update_speed(unit.0);
- result = 1;
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement