March 11, 2001, 11:20
|
#1
|
Chieftain
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Dec 2000
Location: Mazamet, France
Posts: 32
|
Request help from SLIC expert
As using 2 different tech in EnableAdvance for units doesn't work, I have tried to use SLIC.
Here is the code.
int_f mod_CanCityBuildUnit(city_t theCity, int_t theUnit)
{
if (theUnit == UnitDB(UNIT_LEGION))
{
if(HasAdvance(theCity.owner, AdvanceDB(ADVANCE_MILITARISM)))
{
return 1; // can build this
}
else
{
return 0; // can't build this
}
}
if (theUnit == UnitDB(UNIT_HUNTER))
{
if(HasAdvance(theCity.owner, AdvanceDB(ADVANCE_WHEEL)))
{
return 1; // can build this
}
else
{
return 0; // can't build this
}
}
return 1; // can build all other units
}
This way, legion should be buildable only if the player has the techs militarism and iron working (iron working is used in the unit.txt with EnableAdvance, and militarism via SLIC).
Trouble is :
- Legion can appear in the buildable units list as soon as I discover Iron Working. But they do not appear every time ! ("random" behaviour every time you open the build list of the city). When I try to add the unit, it is not added in the list... Most of the time... If I click fast enough, I can add some legions in the lists (like 2 legions if I click 10 times...).
How can I make it work??
|
|
|
|
March 12, 2001, 11:22
|
#2
|
Deity
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
|
Well, I tested these CanCityBuildxxx functions thoroughly and never had any problems with them, they always work perfectly for me. The only thing that could go wrong here (and in the other thread) that I can think of is a bug in the user-defined functions which Mr Ogre warned us about (though he didn't give much details on this bug, so I have no idea when it could occur or why). If you're being plagued by this bug, you should be able get around it by storing arguments of the function in local variables before using them instead of using them directly. So in your case it should look like this:
Code:
|
int_f mod_CanCityBuildUnit(city_t theCity, int_t theUnit) {
city_t tmpCity; // added
int_t tmpUnit; // added
tmpUnit = theUnit; // added
tmpCity = theCity; // added
if (tmpUnit == UnitDB(UNIT_LEGION)) {
if(HasAdvance(tmpCity.owner, AdvanceDB(ADVANCE_MILITARISM))) {
return 1; // can build this
} else {
return 0; // can't build this
}
}
if (tmpUnit == UnitDB(UNIT_HUNTER)) {
if(HasAdvance(tmpCity.owner, AdvanceDB(ADVANCE_WHEEL))) {
return 1; // can build this
} else {
return 0; // can't build this
}
}
return 1; // can build all other units
} |
I didn't test this, so let me know if this works...
[This message has been edited by Locutus (edited March 12, 2001).]
|
|
|
|
March 12, 2001, 15:50
|
#3
|
Deity
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
|
Steph,
What are the specs of your computer? I just remembered Alpha Wulf had some similiar problems a while ago and I couldn't explain those either. Then, out of despair, I suggested it might be his computer: the code that displays the units in the build-manager might be executed earlier/faster than the code that disables these units, and hence (sometimes) showing the units when it's not supposed to. AW tried the exact same code on a slower computer (where the display part is executed slower/later than the disable code) and it *did* work correctly...
Of course this doesn't mean my theory has to be correct, but it did show the problem could well be system-specific. Any chance you could repeat the experiment? Try out the same code on a different computer? I'll try to run the code on my system tonight or tomorrow, but I'm quite busy so I can't promise anything. Besides, I'm almost 100% positive that it will work on my sytstem as I have tested similiar things thoroughly in the past without encountering any problems.
|
|
|
|
March 13, 2001, 01:43
|
#4
|
Chieftain
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Dec 2000
Location: Mazamet, France
Posts: 32
|
It still doesn't work !
I may have hunter in the list before I research wheel, and clicking on it doesn't not always add it in the queue. And after I discover wheel, hunter are not added to the list...
Do you think it could be because I have a lot of units and tech?
|
|
|
|
March 15, 2001, 01:48
|
#5
|
Chieftain
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Dec 2000
Location: Mazamet, France
Posts: 32
|
My comp is a PIII 500 Mhz with 256 Mo. I agree with your idea, as the result is not systematic, and could very well depend on the speed of each part. Unfortunately, I cannot try it on a slower computer (at my office we only have faster computer). And even If I could, I don't think I will downgrade my PC just to play my mod!
I think it could not work on my PC du to the number of techs / units I have (150 units and 250 tehcs I should say). This may slow down the checking part. I will try the SLIC code with the original CTP files, and see if it runs well. In that case, I may need a faster PC, not a slower one.
|
|
|
|
March 15, 2001, 21:14
|
#6
|
King
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
|
Steph,
I think your problem might originate in the way you modified Locutus's original code. Try this:
code:
--------------------------------------------------------------------------------
int_f mod_CanCityBuildUnit(city_t theCity, int_t theUnit) { if (theUnit == UnitDB(UNIT_LEGION)) { if(HasAdvance(theCity.owner, AdvanceDB(ADVANCE_MILITARISM))&& HasAdvance(theCity.owner, AdvanceDB(ADVANCE_IRON_WORKING)) )
{ return 1; // can build this } else { return 0; // can't build this } } if (theUnit == UnitDB(UNIT_HUNTER)) { if(HasAdvance(theCity.owner, AdvanceDB(ADVANCE_WHEEL))&& HasAdvance(theCity.owner, AdvanceDB(ADVANCE_???)) )
{ return 1; // can build this } else { return 0; // can't build this } } return 1; // can build all other units}
--------------------------------------------------------------------------------
The '???' are for your other advance in this case. It's untested but with luck it should over-ride the advance prerequisites in Units.txt.
|
|
|
|
March 15, 2001, 21:16
|
#7
|
King
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
|
No, don't try that. I'll e-mail it to you; I can never get this thing to work.
Peter
|
|
|
|
March 16, 2001, 15:52
|
#8
|
Chieftain
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Dec 2000
Location: Mazamet, France
Posts: 32
|
I still doesn't work. The "forbidden" unit still appears in the list from time to time. However, as it happens perhaps 10% of the time, and that in that case you cannot always add the unit to the queue, I think I can try to keep it that way. I don't really like it, as it could allow a player to build unit to early (like a nuke sub with submarine warfare, but witout fission!). The really bad thing is that the unit is not avalaible once the tehc has been discovered
Another solution would be to add tech (like nuclear submarine). What do you think? Should I add some techs, or keep a SLIC code that works 90% of the time?
I hope the "barracks" SLIC code will work better, and by combining the two code, I can make it really fun to play
I may also have another solution : what if, at the beginning of each turn, I remove from the queue any unit that should not be there
[This message has been edited by Steph (edited March 16, 2001).]
|
|
|
|
March 16, 2001, 21:24
|
#9
|
Settler
Local Time: 01:57
Local Date: October 31, 2010
Join Date: Feb 2001
Location: Vancouver, Canada
Posts: 26
|
Here's a solution that can be used for this problem and for the civ-specific unit problem:
Add separate techs for units that require two or more techs to build. Grant these techs automatically using SLIC once the required two plus techs have been discovered so the player doesn't need to research them... like:
trigger 'GiveTech' when (HasAdvance(player,ID_ADVANCE_1) && HasAdvance(player, ID_ADVANCE_2))
{
//code here
}
That's CTP1 syntax, but the concept will do the trick. It'll also work for civ-specific units, when each civ has a tech corresponding to it's civ, like ADVANCE_ROMAN, etc, and each unit needs a combination of advances, like ADVANCE_JAPANESE and ADVANCE_IRON_WORKING for the samurai, etc.
plus - no more worries about oddities in the build-lists. One problem though, how do you keep the ai from trading these advances? Offhand I'd say remove the advance from their research lists, but would that do it?
|
|
|
|
March 17, 2001, 14:21
|
#10
|
Deity
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
|
Madd_Mugsy,
I don't think that does the trick in this particular situation. And even in the case of civ-specific units there are more elegant ways of doing this in SLIC2 (check out the Chris B's 'Another SLIC Help Request.' thread, that contains some examples of civ-specific units). In SLIC1 it was indeed the best (if not only) way of doing this (though I don't think the trade-bug could be resolved in SLIC1, you'd need more SLIC2 code to do that).
Steph,
I have no idea what could be causing your problems, so I guess using smaller increments in techs is the way to go.
|
|
|
|
March 18, 2001, 01:39
|
#11
|
Chieftain
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Dec 2000
Location: Mazamet, France
Posts: 32
|
As I'm not very confident with SLIC code, I have decided to add a lot of "small techs", that would not cost much, and will give my units.
|
|
|
|
March 18, 2001, 06:56
|
#12
|
Chieftain
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Dec 2000
Location: Mazamet, France
Posts: 32
|
I'm really disappointed that the SLIC code doesn't work. I don't mind that much adding new techs for my units (even if it is a bit strange sometimes, as they are not as important as other : having "nuclear carrier" beside "naval aviation" and "nuclear power" is not that good I think). What really upset me is that I can't use the barrack code! I had planned to use it a lot with barracks, stable, weapon manufacture, submarine factory, etc.
|
|
|
|
March 18, 2001, 20:00
|
#13
|
King
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
|
Steph, you're right, this is very disappointing. I thought it might be your modifications that were causing the deviations so I tested it on the standard advances tree and got different but equally unsatisfactory results. I can't understand why. It seems the CanCityBuildUnit function can't be modified to do what you want it to do. This doesn't mean you can't do it, it just means you'd have to start from basics and write your own code, along the lines of the idea you suggested above. I guess we could use some help, from someone like Mr Ogre or whoever it was that worked in this area.
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
All times are GMT -4. The time now is 05:57.
|
|