Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.99 KB | None | 0 0
  1. #include <z64ovl/oot/u10.h>
  2. #include<z64ovl/oot/helpers.h>
  3. #include <z64ovl/oot/sfx.h>
  4.  
  5. #include <z64ovl/oot/u10.h>
  6. #include <z64ovl/oot/helpers.h>
  7. #include <z64ovl/oot/types.h>
  8.  
  9.  
  10. #define ACT_ID 0x0082
  11. #define OBJ_ID 0x0004
  12.  
  13. /* Hierarchical Display Lists * * * */
  14.      #define   LIMB_LIMB_1     0x06002058
  15.      #define   LIMB_LIMB_2     0x060026D8
  16.      #define   LIMB_LIMB_3     0x06002C70
  17.      #define   LIMB_LIMB_5     0x06003140
  18.      #define   LIMB_LIMB_6     0x060037D0
  19.      #define   LIMB_LIMB_7     0x06003D60
  20.      #define   LIMB_LIMB_8     0x06004390
  21.      #define   LIMB_LIMB_9     0x06004D88
  22.      #define   LIMB_LIMB_10     0x06006080
  23.      #define   LIMB_LIMB_12     0x06006898
  24.      #define   LIMB_LIMB_13     0x06006B00
  25.      #define   LIMB_LIMB_14     0x06006E00
  26.      #define   LIMB_LIMB_16     0x06007178
  27.      #define   LIMB_LIMB_17     0x060074A0
  28.      #define   LIMB_LIMB_18     0x06007810
  29.  
  30. /* Animations * * * */
  31.      #define   ANIM_IDLE     0x06007B08
  32.  
  33. /* Hierarchies (Skeletons) * * * */
  34.      #define   SKL_DEFAULT     0x06007C50
  35.  
  36. /* Base Offset: 0x06000000 */
  37.  
  38. typedef struct {
  39.     z64_actor_t actor;
  40.     z64_actor_t dist_from_link_xz;
  41.  
  42.     z64_collider_cylinder_main_t Collision;
  43.  
  44.     z64_skelanime_t skelanime;
  45.  
  46.     uint32_t path_id;
  47.     uint32_t shootTimer;
  48.     uint32_t* pathlist;
  49.  
  50.     uint8_t num_nodes;
  51.  
  52.     vec3f_t next_dest;
  53.     vec3f_t curPos;
  54.     vec3f_t destPos;
  55.  
  56.     float last_diff;
  57.     float jumpTime;
  58.  
  59.     bool touching_ground;
  60.     bool isJumping;
  61.  
  62.     int count;
  63.     int fps;
  64.     int seconds;
  65.  
  66.     int current_node;
  67.  
  68.     int invincibility;
  69.     int prev_health;
  70.     int anim;
  71.  
  72. } entity_t;
  73.  
  74. const z64_collider_cylinder_init_t Collision =
  75. {
  76.     .body = {
  77.           .unk_0x14 = 0x07
  78.         , .collider_flags = 0x00
  79.         , .collide_flags = 0x11
  80.         , .mask_a = 0x39
  81.         , .mask_b = 0x10
  82.         , .type = 0x01
  83.         , .body_flags = 0x00
  84.         , .toucher_mask = 0xFFCFFFFF
  85.         , .bumper_effect = 0x00
  86.         , .toucher_damage = 0x04
  87.         , .bumper_mask = 0xFFCFFFFF
  88.         , .toucher_flags = 0x00
  89.         , .bumper_flags = 0x01
  90.         , .body_flags_2 = 0x01
  91.     }
  92.     , .radius = 0x020
  93.     , .height = 0x0020
  94.     , .y_shift = 0
  95.     , .position = {
  96.           .x = 0
  97.         , .y = 0
  98.         , .z = 0
  99.     }
  100. };
  101.  
  102. const uint32_t damaginghitbox[] =
  103. {
  104.     0x0A110009, 0x20010000, 0x00000000, 0xFFCFFFFF,
  105.     0x04050000, 0xFFCFFFFF, 0x00000000, 0x01010100, //Damage Amount 00 burn 01 freeze 02 shock 03 KB 04
  106.     0x00200080, 0x00000000, 0x00000000 // Damage Radius
  107. };
  108.  
  109. const uint8_t damagechart[] =
  110. {
  111.     0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
  112.     0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
  113.     0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
  114.     0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2
  115. };
  116.  
  117. const uint32_t unkchart[] =
  118. {
  119.     0x0100000F, 0x001E1E00
  120. };
  121.  
  122. static uint32_t* get_current_header_addr(z64_global_t *global)
  123. {
  124.     z64_file_t* file = zh_get_save_context(global);
  125.     uint32_t scene_setup_index = file->scene_setup_index;
  126.    
  127.     uint32_t* header_addr = global->scene_file;
  128.    
  129.     if (*header_addr == 0x18000000 && scene_setup_index != 0)
  130.     {
  131.         uint32_t* headers_list = (uint32_t*)*(header_addr + 1);
  132.        
  133.         for (int i = scene_setup_index - 1; i > -1; i--)
  134.         {
  135.             uint32_t* addr = (uint32_t*)zh_seg2ram((uint32_t)(headers_list + i));
  136.            
  137.             if (*addr != 0)
  138.             {    
  139.                 header_addr = (uint32_t*)zh_seg2ram((uint32_t)*addr);
  140.                 break;
  141.             }
  142.         }
  143.     }
  144.  
  145.     return header_addr;
  146. }
  147.  
  148. static uint32_t* get_path_list_addr(z64_global_t *global)
  149. {
  150.     uint32_t* header_addr = get_current_header_addr(global);
  151.    
  152.     for (int i = 0; i < 14; i++)
  153.     {
  154.         if (*(header_addr + (i * 2)) == 0x0D000000)
  155.         {
  156.             return (uint32_t*)zh_seg2ram((uint32_t)*(header_addr + (i * 2) + 1));
  157.         }
  158.     }
  159.    
  160.     return 0;
  161. }
  162.  
  163. static uint32_t* get_path_address(uint32_t* path_list_addr, s16 path_id)
  164. {
  165.     return (uint32_t*)(path_list_addr + (path_id * 2));
  166. }
  167.  
  168. static uint8_t get_number_of_nodes_from_path(uint32_t* path_addr)
  169. {
  170.     return (uint8_t)*((uint8_t*)path_addr);
  171. }
  172.  
  173. static z64_xyz_t* get_node_data_from_path(uint32_t* path_list_addr, s16 path_id, s16 node_id)
  174. {
  175.     uint32_t* path_addr = get_path_address(path_list_addr, path_id);
  176.     uint8_t num_nodes = get_number_of_nodes_from_path(path_addr);
  177.    
  178.     if (num_nodes < node_id)
  179.         return 0;
  180.     else
  181.         return (z64_xyz_t*)((zh_seg2ram((uint32_t)*(path_addr + 1))) + (node_id * 6));
  182. }
  183.  
  184. void get_next_dest(entity_t *en, z64_global_t *gl)
  185. {
  186.     //sets the node data within a path to dest_pos
  187.     vec3s_t *dest_pos = (vec3s_t*)get_node_data_from_path(en->pathlist , en->path_id, en->current_node);
  188.     //converts vec3s data type to vec3f
  189.     math_vec3f_from_vec3s(&en->next_dest, dest_pos);
  190. }
  191.  
  192. /*** functions ***/
  193. static void init(entity_t *en, z64_global_t *gl)
  194. {
  195.     //adds  gravity
  196.     en->actor.pos_2.y -=10;
  197.     en->shootTimer = 4;
  198.     en->isJumping = false;
  199.  
  200.     actor_set_scale(&en->actor, 0.01f);
  201.     actor_set_height(&en->actor, 10);
  202.    
  203.     en->fps = 20;
  204.     en->count = 0;
  205.     en->seconds = 4;
  206.  
  207.     en->actor.collision_check.health = 20;
  208.  
  209.     actor_init_shadow(&(en->actor).rot_2, 0, &ACTOR_SHADOW_DRAWFUNC_CIRCLE, 50.0f);
  210.  
  211.     actor_collider_cylinder_alloc(gl,&en->Collision);
  212.     actor_collider_cylinder_init(gl,&en->Collision,&en->actor, &Collision);
  213.     actor_collider_cylinder_alloc(gl,&en->Collision);
  214.     actor_collider_cylinder_init(gl,&en->Collision,&en->actor,&damaginghitbox);
  215.  
  216.     external_func_80061ED4(AADDR(&en->actor,0x98),&damagechart,&unkchart); // damage chart
  217.  
  218.     en->actor.gravity = -0.5f;
  219.  
  220.     // gets the list of paths and set first destination
  221.     en->last_diff = 999999.0f;
  222.     en->current_node = 0;
  223.     en->path_id = 0;
  224.     en->pathlist = get_path_list_addr(gl);
  225.     en->num_nodes = get_number_of_nodes_from_path(get_path_address(en->pathlist, en->path_id));
  226.     get_next_dest(en, gl);
  227.     en->actor.collision_check.mass = 0xF0;
  228.     skelanime_init_mtx(gl, &en->skelanime, SKL_DEFAULT, ANIM_IDLE, 0, 0, 0);
  229.  
  230. }
  231.  
  232.  
  233. void HandleJump(entity_t *en, z64_global_t *gl)
  234. {
  235.  
  236.     if (en->isJumping) {
  237.         en->jumpTime += (1.0f / 20.0f);
  238.         float delta = en->jumpTime;
  239.  
  240.         if (delta < 1.0f)
  241.         {
  242.             // Parabola code!
  243.             float time = delta;
  244.             float ptime = time * 2 - 1;
  245.  
  246.             // Multiply for temp vectors
  247.             vec3f_t tdest = en->destPos;
  248.             tdest.x = (tdest.x - en->curPos.x) * time;
  249.             tdest.y = (tdest.y - en->curPos.y) * time;
  250.             tdest.z = (tdest.z - en->curPos.z) * time;
  251.             vec3f_t tcur = en->curPos;
  252.             tcur.x += tdest.x;
  253.             tcur.y += tdest.y;
  254.             tcur.z += tdest.z;
  255.  
  256.             tcur.y += (-ptime * ptime + 1) * 300;
  257.             en->actor.pos_2 = tcur;
  258.         }
  259.         else if (delta >= 1.0f)
  260.         {
  261.             // Reset timer
  262.             en->jumpTime = 0.0f;
  263.  
  264.             // Prevent desync.
  265.             en->actor.pos_2 = en->destPos;
  266.  
  267.             en->isJumping = false;
  268.         }
  269.     }
  270.     else
  271.     {
  272.         if((en->actor.bgcheck_flags & 0xB) || (en->Collision.body.flags_2 & 2))
  273.         {
  274.             en->actor.xz_speed = 100;
  275.             get_next_dest(en, gl);
  276.            
  277.             en->curPos = en->actor.pos_2;
  278.             en->destPos = en->next_dest;
  279.            
  280.  
  281.             if (en->count != (en->seconds * en->fps))
  282.             {
  283.                 en->count = (en->count + 1);
  284.             }
  285.             else
  286.             {
  287.                 en->actor.rot_2.y = external_func_80078068(&en->actor.pos_2, &en->next_dest);
  288.                 en->isJumping = true;    
  289.                 en->count = 0;    
  290.                 en->shootTimer--;
  291.             }  
  292.         }
  293.         else
  294.         {
  295.             en->actor.xz_speed = 0;
  296.             en->actor.gravity = -5;
  297.             en->actor.pos_2.y = 5;
  298.             actor_move_towards_direction(&en->actor);
  299.         }
  300.     }
  301. }
  302.  
  303. static void handleShoot(entity_t *en, z64_global_t *gl)
  304. {
  305.     play_sound_global_once(NA_SE_IT_BOW_DRAW);
  306.     //Set Animation to shooting arrow
  307.     en->anim = ANIM_IDLE;
  308.     actor_anime_change(
  309.         &en->skelanime, en->anim, 1.0,
  310.         0, 0, 0, 0
  311.     );
  312.  
  313.     z64_actor_t Link = zh_get_player(gl)->actor;
  314.  
  315.     //Rotate's towards Link
  316.     en->actor.rot_2.y = en->actor.rot_toward_link_y;
  317.    
  318.     //Spawns arrow in Link's Direction
  319.     actor_spawn(AADDR(gl,0x1C24), gl, 0x010B,
  320.                         en->actor.pos_2.x,  en->actor.pos_2.y,  en->actor.pos_2.z,
  321.                         Link.pos_2.x, Link.pos_2.y, Link.pos_2.z,
  322.                         0xFFFFFFFF);
  323.  
  324. }
  325.  
  326.  
  327. static void play(entity_t *en, z64_global_t *gl)
  328. {
  329.  
  330.     actor_collider_cylinder_update(&en->actor, &en->Collision);
  331.     actor_collision_routine(gl, &en->actor, 50.0f, 10.0f, 100.0f, 5); //extern void external_func_8002E4B4(z64_global_t *global, z64_actor_t *actor, f32 below, f32 radius, f32 above, u32 flags);
  332.  
  333.     if(en->shootTimer == 0 && en->isJumping == false)
  334.     {
  335.         handleShoot(en, gl);
  336.         en->shootTimer = 4;
  337.     }
  338.     else
  339.     {
  340.         HandleJump(en,gl);
  341.     }
  342.  
  343.     actor_update_health(&en->actor);
  344.  
  345.     if (en->actor.collision_check.health != en->prev_health && en->invincibility == 0) // Damage
  346.     {
  347.         en->actor.damage_color = 0x5FF1;
  348.         en->invincibility = 0x28;
  349.     }
  350.  
  351.     if (en->invincibility > 0)
  352.     {
  353.         en->actor.damage_color_timer = en->invincibility;
  354.         en->invincibility--;
  355.     }
  356.  
  357.     en->prev_health = en->actor.collision_check.health;
  358.  
  359.     float diff = ABS(math_vec3f_distance(&en->next_dest, &en->actor.pos_2));
  360.        
  361.  
  362.     if(diff < en->actor.xz_speed)
  363.     {
  364.         en->current_node += 1;
  365.     }
  366.     if (en->current_node == en->num_nodes - 1)
  367.     {
  368.         en->current_node = 0;
  369.     }
  370.  
  371.     //external_func_8002D8E0(&en->actor);
  372.     actor_collider_cylinder_update(&en->actor, &en->Collision);
  373.     actor_collision_check_set_ac(gl,AADDR(gl, 0x011E60), &en->Collision);
  374.     actor_collision_check_set_at(gl,AADDR(gl, 0x011E60), &en->Collision);
  375.     actor_collision_check_set_ot(gl, (uint32_t*)(AADDR(gl,0x11e60)), &en->Collision);
  376. }
  377.  
  378. static void draw(entity_t *en, z64_global_t *gl)
  379. {
  380.    // update the transformation matrices for each limb, based on the current animation frame
  381.     actor_anime_frame_update_mtx(&en->skelanime);
  382.    
  383.     // draw a matrix-enabled skeleton
  384.     skelanime_draw_mtx(
  385.         gl,
  386.         en->skelanime.limb_index,
  387.         en->skelanime.unk5,
  388.         en->skelanime.dlist_count,
  389.         0, 0,
  390.         &en->actor
  391.     );
  392.  
  393. }
  394.  
  395. static void dest(entity_t *en, z64_global_t *gl)
  396. {
  397. }
  398.  
  399. const z64_actor_init_t init_vars = {
  400.     .number = ACT_ID,
  401.     .type = 0x05, //Enemy
  402.     .room = 0x00,
  403.     .flags = 0x00000010,
  404.     .object = OBJ_ID,
  405.     .padding = 0x0000,
  406.     .instance_size = sizeof(entity_t),
  407.     .init = init,
  408.     .dest = dest,
  409.     .main = play,
  410.     .draw = draw
  411. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement