March 29, 2024, 01:27:36 PM

Username
Password

Pages: 1 ... 4 5 [6]   Go Down
Print
Author Topic: Enemy units in Campaign  (Read 49277 times)
0 Members and 1 Guest are viewing this topic.
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #75 on: April 05, 2012, 11:20:55 PM »

Hm right. Completly forgot about the case that a unit can die...

But in the meanwhile I found a much better solution. I don't know the official way to get the Unit Id within a CTL script, but this here works too:
test_unit_r_eq_i -278, n
n is the Unit Id you want to check.

Of course you can also overwrite the Unit Id with set_unit_r...

I don't guarantee that this still works during the battle because the UnitId is only 2 byte and the registers are 4 byte. If you are lucky the 2 other bytes are unused (and stay 0) Smiley.
« Last Edit: April 05, 2012, 11:33:22 PM by Ghabry » Logged

cuthalion
Campaign Creator
*
Offline Offline

Posts: 385


View Profile
« Reply #76 on: April 06, 2012, 06:07:50 AM »

Yes, this solution works, at least before unit deploy. That's good as it's enough time to set a label to the unit anyway.
Thank you Smiley

What is bad though is that randomizer doesn't work. It always returns 1 regardless of the time passed or I don't understand how to use it.

    test_unit_r_eq_i -278, 2
   iftrue
       set_unit_r_random1to10 5
   endif

    wait_for_deploy
   
    saveip
   set_global_r_i 3 1
      
   test_unit_r_eq_i -278, 2
   iftrue

      set_timer 150
      wait_for_timer
      
      test_unit_r_eq_i 5 1
      iftrue
       #9d 28 (blast)
                else
                 #9d 30 (conflagration)
      endif
        endif

This piece of code always sets blast to Infantry a short period after deployment.
Same happens if I 'randomize' the register after deployment, or if I set the spell before deployment.
Same happens if I use any other register (tried 1, 5, 6)
Logged
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #77 on: April 06, 2012, 01:23:03 PM »

I just noticed that the "random" number generator does start when you finished deployment. So this can't be even used for random values after startup...
So for now I have no idea how to get a good random seed. Guess you will have to stick to a check which regiment is selected when deployment is finished for now...
Logged

cuthalion
Campaign Creator
*
Offline Offline

Posts: 385


View Profile
« Reply #78 on: April 06, 2012, 01:47:03 PM »

Well in my tests it didn't ever start, after or before startup. As it always seemed  to return 1.
But anyway, your verdict is clear Smiley
OK it's not a biggie, I will most likely manually define spells for missions. Im now more worried that I can't find them sprites everyone is talking around on the forum, and I've no idea what DOC111 is and such Smiley

worst thing to be a newbie at something Smiley
Logged
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #79 on: April 06, 2012, 02:01:04 PM »

DOC111 is a very old mod collection from around 2000. Also contains lots of sprites.
Logged

cuthalion
Campaign Creator
*
Offline Offline

Posts: 385


View Profile
« Reply #80 on: April 06, 2012, 06:51:10 PM »

Would the following logic work (sorry for pseudo-language):

after deploy in func 100:

if (user id == my id)
{
 randomize_reg(5)
 reg(6) = 1
}
 
saveip
do
        set_timer 100
        wait_for_timer
  
 if (unit_id == my_id && reg(6) == 1)
 {
   reg(6) = 0
   and here goes logic depending on randomized reg 5
 }

        sleep1
always

I implemented something of the kind but it would give my unit the spell each time I give it a command, I don't know why - maybe the register was automatically set to 1, not sure. After it received like 8 fire blasts, the game crashed.



Logged
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #81 on: April 06, 2012, 10:00:33 PM »

The random value is assigned when you call set_unit_r_random1to10. So to get a random number later you have to call the function again.
The code looks correct but it's possible that reg6 get's written somewhere. Try it with a different register (8 is the highest).
Logged

cuthalion
Campaign Creator
*
Offline Offline

Posts: 385


View Profile
« Reply #82 on: April 07, 2012, 07:18:05 AM »

The random value is assigned when you call set_unit_r_random1to10. So to get a random number later you have to call the function again.

Didn't quite understand that part.
Do you mean that I should use it in the following way.

Somewhere
set_unit_r_random1to10 7
.....
Then
set_unit_r_random1to10 7
test_unit_r_eq_i 7 5

So before testing that register I have to call random again?
Logged
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #83 on: April 07, 2012, 05:27:13 PM »

Everytime you call set_unit_r_random1to10 it gives you a (new) "random" number.

So for a large if-branch you have to call set_unit_r_random1to10 once before the branch:
set_unit_r_random1to10 7
test_unit_r_eq_i
iftrue
...
Then
test_unit_r

and so on.
Logged

cuthalion
Campaign Creator
*
Offline Offline

Posts: 385


View Profile
« Reply #84 on: April 12, 2012, 07:06:32 PM »

Is it known if there exists (and known number) event "You are charged by enemy"?

An idea about intelligent enemy archers came to my mind. Take horsen archers, they shoot you but if you charge them they flee, then regroup and shoot again. Pursuing them may be dangerous as it might discharge a new wave of enemies, and anyway it's hard to pursue cavalry.
 Amount of such regroups can be limited by registers, and also by the fact that they may fail to regroup and flee the battle.
Logged
kilowic
Mummy
*
Offline Offline

Posts: 119


Iron Fist


View Profile
« Reply #85 on: April 12, 2012, 08:33:51 PM »

That would be extra annoying unit!
Logged

My GameRanger info:
ID: 1713251
kilowic

I PLAY FAIR OMEN MOD
Pages: 1 ... 4 5 [6]   Go Up
Print
Jump to: