Author Topic: Definitive Array Scripts  (Read 5905 times)

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Definitive Array Scripts
« on: March 04, 2008, 07:01:30 PM »
Hey guys.

I'm thinking of creating a definitive set of array scripts with infinite storage capacity, spawning new arrays and linking them in a chain to get around the old '256 slots' limit.

Would there be any demand for it? What are the functions that you would really want in such a system? Let me know!

Regards,
Winter

Offline Ron Losey

  • Master
  • *****
  • Posts: 4418
    • View Profile
Re: Definitive Array Scripts
« Reply #1 on: March 04, 2008, 07:10:58 PM »
Would it get around the bug that limits number of possible upgradable troop types?  (Is that bug still in .90x?  I haven't heard.)

Because that was killing projects to re-arrange the troop trees in TLD.
 

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Definitive Array Scripts
« Reply #2 on: March 04, 2008, 07:51:41 PM »
Would it get around the bug that limits number of possible upgradable troop types?  (Is that bug still in .90x?  I haven't heard.)

Because that was killing projects to re-arrange the troop trees in TLD.
 

. . . I can safely say that my plan has absolutely nothing to do with that. Though you could fairly easily mod in a manual troop upgrade system through dialogue if you so desired.

Offline Ron Losey

  • Master
  • *****
  • Posts: 4418
    • View Profile
Re: Definitive Array Scripts
« Reply #3 on: March 04, 2008, 09:07:40 PM »
Would it get around the bug that limits number of possible upgradable troop types?  (Is that bug still in .90x?  I haven't heard.)

Because that was killing projects to re-arrange the troop trees in TLD.
 

. . . I can safely say that my plan has absolutely nothing to do with that. Though you could fairly easily mod in a manual troop upgrade system through dialogue if you so desired.

That's been discussed.  Just wondering, since number of troop types was a manefestation of the "256 limit" bug.

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Definitive Array Scripts
« Reply #4 on: March 06, 2008, 02:01:07 PM »
256 slots max? Native uses more than that in the slot_center... slots, with the trade good prices and productions

The horses tend to get their legs caught in the catapult rather than being properly launched.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Definitive Array Scripts
« Reply #5 on: March 06, 2008, 03:21:36 PM »
256 slots max? Native uses more than that in the slot_center... slots, with the trade good prices and productions

No, it doesn't. There are only 16 trade good items, so the highest numbered slot used in those calculations is 224.

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Definitive Array Scripts
« Reply #6 on: March 07, 2008, 08:27:08 PM »
ugh...OnR has over 100 trade goods, which totally blows away this silly limit

The horses tend to get their legs caught in the catapult rather than being properly launched.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Definitive Array Scripts
« Reply #7 on: March 08, 2008, 06:35:37 AM »
ugh...OnR has over 100 trade goods, which totally blows away this silly limit

Ever noticed that your scripts in that area mysteriously failed or just didn't work?

Try reading your final 10 trade goods from those slots, and they should come up empty.
« Last Edit: March 08, 2008, 06:38:26 AM by Winter »

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Definitive Array Scripts
« Reply #8 on: March 08, 2008, 12:18:24 PM »
Well, fortunately, I hadn't turned that code on yet. I guess the way around that would be to create some dummy parties used only for their slots, and link them back to the town; cumbersome, but it would work.

I would be interested to see what you come up with as far as array scripts, since I came up with version 1.

The horses tend to get their legs caught in the catapult rather than being properly launched.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Definitive Array Scripts
« Reply #9 on: March 08, 2008, 02:52:14 PM »
Okay, here's my first go at the array scripts, may be intensely buggy but you get the idea. Any testing would be very welcome.

It doesn't wrap around like the old scripts do, but it will go on forever in linked arrays.

Constants:

slot_array_length   = 0
slot_array_read_index   = 1
slot_array_write_index   = 2
slot_array_last_pushed   = 3
slot_array_link   = 255

array_null_value   = -1

array_first_index   = 5
array_last_index   = 254


Code: [Select]
  ("array_init",
   [
# (store_script_param_1,":array_length"),

(set_spawn_radius,5),
(spawn_around_party,"p_main_party","pt_none"),
(call_script,"script_array_clear",reg0),
]),
  ("array_nexus",
   [
(store_script_param_1,":id"),
(store_script_param_2,":value"),

(store_sub,":max_array_cap",array_last_index,array_first_index),

(assign,":loops",1),
(try_for_range,":unused",0,":loops"),
(gt,":value",array_last_index),
(party_get_slot,":new_id",":id",slot_array_link),
(gt,":new_id",0),
(val_sub,":value",":max_array_cap"),
# (val_add,":value",array_first_index),
(assign,":id",":new_id"),
(val_add,":loops",1),
(try_end),

(assign,reg0,":id"),
(assign,reg1,":value"),
]),
  ("array_set_range",
   [
(store_script_param,":id",1),
(store_script_param,":low_value",2),
(store_script_param,":high_value",3),

(call_script,"script_array_nexus",":id",":low_value"),
(assign,":low_id",reg0),
(assign,":low_value",reg1),

(call_script,"script_array_nexus",":id",":high_value"),
(assign,":high_id",reg0),
(assign,":high_value",reg1),

(assign,reg0,":low_id"),
(assign,reg1,":low_value"),
(assign,reg2,":high_id"),
(assign,reg3,":high_value"),
]),
  ("array_destroy",
   [
(store_script_param_1,":id"),

(assign,":current_id",":id"),
(troop_set_slot,"trp_temp_array_a",0,":current_id"),
(assign,":slot",1),
(assign,":loops",1),
(try_for_range,":unused",0,":loops"),
(party_get_slot,":new_id",":current_id",slot_array_link),
(gt,":new_id",0),
(assign,":current_id",":new_id"),
(troop_set_slot,"trp_temp_array_a",":slot",":current_id"),
(val_add,":slot",1),
(val_add,":loops",1),
(try_end),

(try_for_range_backwards,":range",0,":slot"),
(troop_get_slot,":current_id","trp_temp_array_a",":range"),
(gt,":current_id",0),
(party_is_active,":current_id"),
(remove_party,":current_id"),
(val_add,":loops",1),
(try_end),
]),
  ("array_clear",
   [
(store_script_param_1,":id"),

# (party_get_slot,":array_length",":input_array",slot_array_length),
(try_for_range,":range",0,255),
(party_set_slot,":id",":range",array_null_value),
(try_end),
(party_set_slot,":id",slot_array_length,0),
    (party_set_slot,":id",slot_array_write_index,array_first_index),
    (party_set_slot,":id",slot_array_read_index,0),
(assign,reg0,":id"),
]),
  ("cf_array_push_front",
   [
(store_script_param_1,":id"),
(store_script_param_2,":value"),
   
    # Get array data
(party_get_slot,":write_index",":id",slot_array_write_index),
(party_get_slot,":read_index",":id",slot_array_read_index),
(party_get_slot,":length",":id",slot_array_length),     

  (assign,"$pout_value",array_null_value),
  (assign,reg0,array_null_value),

    # Make sure the array isn't full
(neq,":write_index",":read_index"),

    # Set the local write_at as being one less than the read-index
    # Wrap around if necessary
(store_sub,":write_at",":read_index",1),

(ge,":write_at",array_first_index),

    # Write the value
(party_set_slot,":id",":write_at",":value"),

    # Update read-index to point to the write_at
    # (Start of the queue will point to the newly added value)
(assign,":read_index",":write_at"),

    # Update array-data
(val_add,":length",1),
   
    # Store the new array-data
(party_set_slot,":id",slot_array_read_index,":read_index"),
(party_set_slot,":id",slot_array_last_pushed,":value"),   
  (party_set_slot,":id",slot_array_length,":length"),
  ]),
  ("cf_array_push_back",
   [
    # Store script parameters
(store_script_param_1,":id"),
(store_script_param_2,":value"),

(assign,":current_id",":id"),

    # Get array data
(party_get_slot,":write_index",":current_id",slot_array_write_index),
(party_get_slot,":length",":current_id",slot_array_length),

(store_add,":work_var",":write_index",array_first_index),
(try_begin),
(gt,":work_var",array_last_index),
(call_script,"script_array_nexus",":current_id",":work_var"),
(try_begin),
(gt,reg0,0),
(assign,":current_id",reg0),
(assign,":work_write_index",reg1),
(else_try),
(call_script,"script_array_init"),
(assign,":new_id",reg0),
(party_set_slot,":current_id",slot_array_link,":new_id"),
(assign,":current_id",":new_id"),
(assign,":work_write_index",array_first_index),
(try_end),
(try_end),

    # Get array data
(party_get_slot,":read_index",":current_id",slot_array_read_index),
(party_get_slot,":work_length",":current_id",slot_array_length),

    # Make sure the array isn't full
(neq,":work_write_index",":read_index"),

    # Write the value
(party_set_slot,":current_id",":work_write_index",":value"),

    # If this is the first push update the read-index
(try_begin),
(eq,":work_length",0),
(assign,":read_index",array_first_index),
(try_end),

    # Increment write-index
(val_add,":work_write_index",1),

    # Update array-length
(val_add,":work_length",1),

(try_begin),
(neq,":current_id",":id"),
(val_add,":write_index",1),
(party_set_slot,":id",slot_array_write_index,":write_index"),
(val_add,":length",1),
(party_set_slot,":id",slot_array_length,":length"),
(party_set_slot,":id",slot_array_last_pushed,":value"),
(try_end),

    # Write the array-data back to the array
(party_set_slot,":current_id",slot_array_length,":length"),
(party_set_slot,":current_id",slot_array_last_pushed,":value"),
(party_set_slot,":current_id",slot_array_read_index,":read_index"),
(party_set_slot,":current_id",slot_array_write_index,":write_index"),
]),
  ("cf_array_pop",
   [
    # Store script-parameters
(store_script_param_1,":id"),

(store_sub,":max_array_cap",array_last_index,array_first_index),

(assign,":current_id",":id"),

    # Get array data
(party_get_slot,":write_index",":current_id",slot_array_write_index),
(party_get_slot,":length",":current_id",slot_array_length),


(try_begin),
(gt,":length",":max_array_cap"),
(store_add,":work_var",":length",array_first_index),
(call_script,"script_array_nexus",":current_id",":work_var"),
(try_begin),
(gt,reg0,0),
(assign,":current_id",reg0),
(else_try),
(call_script,"script_array_init"),
(assign,":new_id",reg0),
(party_set_slot,":current_id",slot_array_link,":new_id"),
(assign,":current_id",":new_id"),
(try_end),
(try_end),


    # Read initial array-data
(party_get_slot,":work_length",":current_id",slot_array_length),
(party_get_slot,":read_index",":current_id",slot_array_read_index),
(party_get_slot,":write_index",":current_id",slot_array_write_index),

    # Initialize return-data
(assign,"$pout_value",array_null_value),
(assign,reg0,array_null_value),
   
    # Make sure the array isn't empty
(gt,":work_length",0),

# (try_begin),
# (gt,":work_length",0),
# (store_add,":last_index_range",":last_index",1),
# (try_for_range, ":range", ":read_index", ":last_index_range"),
# (party_get_slot, ":temp_var", ":current_id", ":range"),
# (store_sub, ":dest", ":range", 1),
# (party_set_slot, ":current_id", ":dest", ":temp_var"),
# (try_end),
# (try_end),

    # Update array-work_length
(val_sub,":work_length",1),

# Update the read-index
(store_add,":last_index",":read_index",":work_length"),
(val_sub,":last_index",1),
(val_sub,":write_index",1),

(try_begin),
(neq,":current_id",":id"),
(val_sub,":write_index",1),
(party_set_slot,":id",slot_array_write_index,":write_index"),
(val_sub,":length",1),
(party_set_slot,":id",slot_array_length,":length"),
(try_end),

    # Get the value to return
(party_get_slot,"$pout_value",":current_id",":read_index"),

    # Write array-data back
(party_set_slot,":current_id",slot_array_read_index,":read_index"),
(party_set_slot,":current_id",slot_array_write_index,":write_index"),
(party_set_slot,":current_id",slot_array_length,":work_length"),

    # Reset array if empty and destroy linked arrays
(try_begin),
(eq,":work_length",0),
(party_get_slot,":new_id",":current_id",slot_array_link),
(try_begin),
(gt,":new_id",0),
(call_script,"script_array_destroy",":new_id"),
(try_end),
(call_script,"script_array_clear",":current_id"),
(try_end),

(assign,reg0,"$pout_value"),   
   ]),
  ("cf_array_peek",
   [
    # Store script-parameters
    (store_script_param_1,":id"),

    # Get array-length
    (party_get_slot,":length",":id",slot_array_length),

    # Initialize return-value
    (assign,"$pout_value",array_null_value),
    (assign,reg0,array_null_value),

    # Make sure the array isn't empty
    (gt,":length",0),

    # Read necessary array-data
    (party_get_slot,":read_index",":id",slot_array_read_index),

    # Get the return-value
    (party_get_slot,"$pout_value",":id",":read_index"),
    (assign,reg0,"$pout_value"),
   ]),
  ("cf_array_read_at",
   [
    # Store script parameters
    (store_script_param_1,":id"),
    (store_script_param_2,":index"),

(store_sub,":max_array_cap",array_last_index,array_first_index),

(assign,":current_id",":id"),

(val_add,":index",array_first_index),
(try_begin),
(gt,":index",array_last_index),
(call_script,"script_array_nexus",":current_id",":index"),
(try_begin),
(gt,reg0,0),
(assign,":current_id",reg0),
(assign,":work_index",reg1),
(else_try),
(call_script,"script_array_init"),
(assign,":new_id",reg0),
(party_set_slot,":current_id",slot_array_link,":new_id"),
(assign,":current_id",":new_id"),
(store_sub,":work_index",":index",":max_array_cap"),
# (val_add,":work_index",array_first_index),
(try_end),
(try_end),

    # Get array length
    (party_get_slot,":length",":current_id",slot_array_length),

    # Initialize return value
    (assign,"$pout_value",array_null_value),
    (assign,reg0,array_null_value),

    # Make sure the array isn't empty
    (gt,":length",0),

    (party_get_slot,":value",":current_id",":work_index"),
    (assign,"$pout_value",":value"),
    (assign,reg0,":value"),     
   ]),
  ("cf_array_write_at",
   [
    # Store script parameters
    (store_script_param_1,":id"),
    (store_script_param_2,":index"),
    (store_script_param,":value",3),

(store_sub,":max_array_cap",array_last_index,array_first_index),

(assign,":current_id",":id"),

(val_add,":index",array_first_index),
(try_begin),
(gt,":index",array_last_index),
(call_script,"script_array_nexus",":current_id",":index"),
(try_begin),
(gt,reg0,0),
(assign,":current_id",reg0),
(assign,":work_index",reg1),
(else_try),
(call_script,"script_array_init"),
(assign,":new_id",reg0),
(party_set_slot,":current_id",slot_array_link,":new_id"),
(assign,":current_id",":new_id"),
(store_sub,":work_index",":index",":max_array_cap"),
# (val_add,":work_index",array_first_index),
(try_end),
(try_end),

    # Get array length
    (party_get_slot,":length",":id",slot_array_length),

    # Initialize return value
    (assign,"$pout_value",array_null_value),
    (assign,reg0,array_null_value),

    # Make sure the array isn't empty
    (gt,":length",0),

    (party_set_slot,":id",":work_index",":value"),
  ]),

grailknighthero

  • Guest
Re: Definitive Array Scripts
« Reply #10 on: April 14, 2008, 06:17:10 PM »
So is the limit definitely 256 slots?  I ask because Khalid ibn Walid on taleworlds said it was about 250 and right now I am at exactly 250 for my party slots and I need more....
« Last Edit: April 15, 2008, 06:47:40 PM by grailknighthero »