1. Forum moved (you can use login and pass from old forum)
  2. Many discussions moved to the bugtracker

APOC reversing

Discussion in 'Coding' started by Skin36, Oct 1, 2015.

  1. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    44/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
  2. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
    function for generating park of vehicle
    http://pastebin.com/AgzyDpBx

    It used three arrays.

    org_veh_fund_init[28](dd)
    offset 00188ea8

    gen_org_veh_list[40](dd)
    offset 00188f18

    veh_lim[32](dd)
    offset 00188fb8
     
  3. JonnyH

    JonnyH Well-Known Member Official Developer Administrator
    64/112

    Joined:
    Jul 17, 2014
    Messages:
    183
    Likes Received:
    36
    Best Answers:
    0
    Right, my interpretation of this:

    This function is run at game start for each (non-xcom non-alien) organisation.

    org_veh_fund_init[] contains the %age of each corporation's starting funds that should be used to buy vehicles, indexed by the 'total number of hostile corporations' (it counts from org '2', skipping xcom and aliens IIRC, and starts at offset 1 - presumably as they 'know' aliens will be hostile to everyone :) - I guess that means people with more enemies buy more vehicles.

    This amount is taken from the org's starting funds.

    gen_org_veh_list[] is actually two lists of 20 vehicle type indices, the first used for all corps but megapol, the second for megapol.

    It then randomly chooses 50 vehicles, by creating a random (0..19) index into gen_org_veh_list[] (offset if megapol). This returned index is then used to dereference the market data table to find the corresponding price. If the price is less than the current available 'vehicle buy fund', and the total number of that type of vehicle is less than veh_limit[] it adds that vehicle type to that corporations ownership and subtracts the price out of the vehicle purchase funds.

    Any remaining vehicle funds are then returned to the org's normal funds.

    I'm not 100% sure on what the second chunk does, as some symbols (e.g. 'word_12862A') lack context, but I suspect it may be going through the 'purchased' vehicles and adding the cost to the manufacturer's funds - so people who sell the vehicles end up with a correspondingly higher starting funds.
     
  4. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
    This function is called at the start of the game, and then in the timer function.
    http://pastebin.com/Jhc5e9nW

    "I guess that means people with more enemies buy more vehicles." - yes
    "This amount is taken from the org's starting funds." -yes




    "gen_org_veh_list[] is actually two lists of 20 vehicle type indices, the first used for all corps but megapol, the second for megapol."

    array:

    int gen_org_veh_list[40]
    gen_org_veh_list
    0...20
    dd 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18,18, 18, 19, 19, 19, 19, 19

    20...40
    dd 10, 10, 10, 10, 10, 10,32, 27, 27, 27, 27, 27, 32, 32, 18, 18, 18, 19, 19,19

    polis_offset = 80 * (org_num_1 == 3)
    if org_num_1 == 3 (megapol) indices start with ind 80/4 = 20


    "It then randomly chooses 50 vehicles,..."
    this seems like 50 this 25 org by 2 byte.(Government...Technocrats)

    v8 = org_num + 2 * veh;
    this is mapping org/veh in veh_park array



    word_12862A this 126 byte structure of init vehicle(craft data, Alien Probe : UFO2P.EXE (189C8C) [126]).
     
  5. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
  6. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
  7. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
    organizations counting money
    field functions are still unknown
    v8 - tiles ?

    incom = *(v0 + 3); /external income org
    for ( i = 0; i < bld_count; ++i )
    {
    v7 = mapbuild_bld[0] + 226 * i;
    if ( v7[200] == v31 )
    {
    v8 = *(v7 + 97);
    incom += v8 * *(v7 + 99);
    cost += *(v7 + 95) + *(v7 + 98) * v8;
    }
    }
    txt_show("Total Income> ", 6u, 60, 200, cost, 1u);
    txt_show2(incom, smallset, dword_182DD0, smallset);
    txt_show("Total Costs> ", 6u, 80, 200, cost, 1u);
    txt_show2(cost, smallset, dword_182DD0, smallset);
    txt_show("Total Profit> ", 6u, 100, 200, cost, 1u);
    txt_show2(incom - cost, smallset, dword_182DD0, smallset);
     
  8. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
  9. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
    music player
     
  10. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
  11. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
    Calculating the cost of a new base

    The original function when calculating the cost calculates base size.But it is not used in the game. However, when generating the base used ready sets of lauout. As a result, the price does not play any role. I think it is necessary to fix it. Because the price calculation is made to the base generation, and depends on the area of the building.
     
  12. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
    Vehicle damage threshold
     
  13. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
    algorithm calculation accuracy
     
  14. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
  15. Istrebitel

    Istrebitel Well-Known Member Official Developer Administrator
    39/56

    Joined:
    Aug 8, 2016
    Messages:
    189
    Likes Received:
    82
    Best Answers:
    1
    After thorough study, I have figured out why hoverbikes and phoenixes are so good at dodging.

    It started with me correcting a "bug" in loftemps for vehicles. Several small vehicles have misaligned loftemps. Phoenix hovercar is one of them. They have a loftemp 122 that looks like this:
    Code:
    		//  122  :							
    		//
    		//	******************		
    		//	*----------------*		
    		//	*----------------*
    		//	*----------------*		
    		//	*-------------XXX*
    		//	*-----------XXXXX*		
    		//	*---------XXXXXXX*		
    		//	*--------XXXXXXXX*
    		//	*--------XXXXXXXX*
    		//	******************
    
    Surely a mistake, I thought. And corrected that by providing it with a similar size loftemp but with hittable area in the centre.

    Hoverbike also has a loftemp that is 1x2 in size and only has a small hittable dot in the top part.
    Code:
    		//  151  :							
    		//
    		//	******************		
    		//	*----------------*		
    		//	*----------------*
    		//	*-------XX-------*		
    		//	*------XXXX------*
    		//	*-------XX-------*		
    		//	*----------------*		
    		//	*----------------*
    		//	*----------------*
    		//	******************
    		//	******************		
    		//	*----------------*		
    		//	*----------------*
    		//	*----------------*		
    		//	*----------------*
    		//	*----------------*		
    		//	*----------------*		
    		//	*----------------*
    		//	*----------------*
    		//	******************
    
    After implementing missile guidance, which made it clear vehicles can never dodge even slowest missiles. Even hoverbike with best engine and no equipment. They get hit 100% of the time. Then with Skin36's help we digged through game formulas but couldn't find what's wrong.

    And finally the solution came to me.

    Apoc's developers cheated. In order to implement small vehicles that can "dodge", they just gave them misaligned voxelmaps!

    Basically, everything in Apoc aims at object's centre. It ignores object's voxelmap, it just uses it's centre point. And if there's nothing at the centre point, then most shots (and homing missiles) will miss, unless object is moving a specific direction!

    In case of hoverbike, if moving directly at target or from target, on the same altitude, it will get hit normally because it's voxelmap will be aligned properly (shooter will shoot at it's centre), but when moving sideways, shots and missiles will go into an empty centre point, while hittable point will remain to the side

    In case of phoenix, it will be most hittalbe from it's back-right angle, if it's angle of movement vector to target vector is 135 degreees, then it's going to be properly vulnerable. If on same altitude, then if facing enemy with back-right or front-left, it will be properly hittable, otherwise it will be harder to hit
     
  16. Solarius Scorch

    Solarius Scorch Call to Power modder Global Moderator
    41/56

    Joined:
    Jul 8, 2014
    Messages:
    197
    Likes Received:
    5
    Best Answers:
    0
    Yeah, that "cheat" is more or less a legacy of older X-Com games, at least in spirit.

    So, are you going to leave the game as is (with non-centre loftemps), or implement some new dodging mechanics?
     
  17. kkmic

    kkmic Undefined
    44/56

    Joined:
    Jul 17, 2014
    Messages:
    61
    Likes Received:
    2
    Best Answers:
    0
    It this is open for debate, I'd say that proper dodging should be implemented - but only if it will provide similar end-results in aerial skirmishes. Otherwise, leave the "cheat" in.
     
  18. JonnyH

    JonnyH Well-Known Member Official Developer Administrator
    64/112

    Joined:
    Jul 17, 2014
    Messages:
    183
    Likes Received:
    36
    Best Answers:
    0
    I would lean towards at least having the option to have the 'weird' original behaviour, even if it's off by default...

    I've said before, I'm not interested in 'game design', so changing the gameplay is something I'd be quite cautious of.
     
  19. Skin36

    Skin36 Well-Known Member Official Developer Administrator
    31/56

    Joined:
    Apr 5, 2015
    Messages:
    62
    Likes Received:
    16
    Best Answers:
    0
    formula for current_remain_TUs

    current_remain_TUs= (total_encumberance * total_encumberance + strengh * 16 * strengh + (strengh * 16 * strengh - total_encumberance * total_encumberance) * 2 * max_speed)/ (2* (strengh * 16 * strengh + total_encumberance * total_encumberance))
     
  20. Istrebitel

    Istrebitel Well-Known Member Official Developer Administrator
    39/56

    Joined:
    Aug 8, 2016
    Messages:
    189
    Likes Received:
    82
    Best Answers:
    1
    Let us try to simplify this by assuming 16 is just 4x4 and 4 is a constant that brings strength to the proper value scale. In that case, formula becomes like this:

    Let:
    e2 = total_encumberance * total_encumberance,
    s2 = strength * 4 * strength * 4

    current_remaining_TUs = 1/2 + max_speed * (s2 - e2) / (s2 + e2)


    Now, this is problematic. Is this value a float, 0 to 1, meaning 0% to 100% max TUs? Or is this value an int, meaning exact number of TUs (0 to 100)? If this is a float, then what is the value scale of max_speed? If not, then what is the meaning of this 1/2?

    In other words, it would make sense to re-check that formula again. Maybe there's a mistake?

    Otherwise, we can just assume the formula is:
    current_remaining_TUs = max_speed * (s2 - e2) / (s2 + e2)

    And when we find out how to calculate encumbrance, we will find out how to calculate this.
     

Share This Page