onilink_

Untitled

Feb 27th, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1.  
  2. with(oGearBase)
  3. {
  4.     processed = false
  5. }
  6.  
  7. // 1. compute torque of each "input"
  8. with(oGearInput)
  9. {
  10.     torque = (vel_target - vel)/10
  11. }
  12.  
  13. // 2. sum the torques
  14. //with(oGearInput)
  15. for(i=0; i<instance_number(oGearInput); i+=1)
  16. {
  17.     ins = instance_find(oGearInput, i)
  18.     if(!ins.processed) {
  19.         // browse all gears of the current network
  20.         // and compute the torque sum
  21.         torque_sum = 0
  22.        
  23.         ds_stack_clear(stack)
  24.         ds_list_clear(list)
  25.        
  26.         ds_stack_push(stack, ins)
  27.        
  28.         while(!ds_stack_empty(stack)) {
  29.             top = ds_stack_top(stack)
  30.             ds_stack_pop(stack)
  31.            
  32.             if(!top.processed) {
  33.                 ds_list_add(list, top)
  34.                 top.processed = true
  35.                 torque_sum += top.vel
  36.                
  37.                 if(top.gear_r != noone) { ds_stack_push(stack, top.gear_r) }
  38.                 if(top.gear_l != noone) { ds_stack_push(stack, top.gear_l) }
  39.                 if(top.gear_u != noone) { ds_stack_push(stack, top.gear_u) }
  40.                 if(top.gear_d != noone) { ds_stack_push(stack, top.gear_d) }
  41.             }
  42.         }
  43.        
  44.         // set the new torque
  45.         roger = min(-1000, max(torque_sum, 1000))
  46.         for(n=0; n<ds_list_size(list); n+=1) {
  47.             ii = ds_list_find_value(list, n)
  48.             ii.torque += roger
  49.         }
  50.     }
  51. }
  52.  
  53.  
  54. with(oGearBase)
  55. {
  56.     acc = torque
  57. }
Advertisement
Add Comment
Please, Sign In to add comment