Thread Tools
Old March 13, 2001, 08:52   #1
Chris B
Warlord
 
Chris B's Avatar
 
Local Time: 04:57
Local Date: October 31, 2010
Join Date: Oct 2000
Location: Canton, CT
Posts: 187
Another SLIC Help request.
My upcoming Scenario, The Persian Wars, Is my 1st SLIC trial. I have already correcty positioned the units and layed a base for city Placemnt, so I decided I'd start on slic. BUt already the Game ont load because of asyntax error in line 4.

Code:
scenario.slc

// Scenario script for GreecevsPersia, 490 BC - Alpha Version

// Make the Persians REALLY hate you
if(IsPlayerAlive(2)) { // if Persians aren't dead
LogRegardEvent(2, 1, -9999, 0, ID_AG_REGARD_EVENT_NEG, 9999);

#include "message.slc"
#include "AG_mod.slc"
#include "AG_func.slc"

Also, I have all my Civspecific Units Down in AG-mod, but thec changes DONT SHOW UP IN THE GAME. If Slic finds one error, does it stop working?

Code:

AG_mod.slc

//Mod Functions for GreecevsPersia, 490 BC

// Players are can not research past Siege Weapons, Hullmaking, Stirrup, and Ethics
int_f mod_CanPlayerHaveAdvance (int_t thePlayer, int_t theAdvance)
{
if (theAdvance == AdvanceDB(ADVANCE_SIEGE_WEAPONS) | |
theAdvance == AdvanceDB(ADVANCE_SIEGE_WEAPONS) | |
theAdvance == AdvanceDB(ADVANCE_HULL_MAKING) | |
theAdvance == AdvanceDB(ADVANCE_STIRRUP) | |
theAdvance == AdvanceDB(ADVANCE_ETHICS)) {
return 0;
} else {
return 1;
}
}

// Civ Special Units

} elseif ((tmpUnit == UnitDB(UNIT_PIKEMEN)) { // if hopite
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
return 1; // greeks can build it
} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
return 1; // Neutral Greeks can build it
} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
return 1; // Traitorous Greeks can build it
} else {
return 0; // other civs can't
}
} elseif ((tmpUnit == UnitDB(UNIT_MACHINE_GUNNER)) { // if 10000 Immortals
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
return 1; // Persians can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_CHARIOT)) { // if Chariot
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
return 1; // Persians can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_INFANTRYMAN)) { // if Spartan Hoplite
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
return 1; // Greeks can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_HOPLITE)) { // if Hoplite Militia
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
return 1; // Greeks can build it
} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
return 1; // Neutral Greeks can build it
} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
return 1; // Traitorous Greeks can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_COMPOSITE_ARCHER)) { // if Persian Archer
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
return 1; // Persians can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_TEUTONIC_KNIGHT)) { // if Greek Heavy Cavalry
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
return 1; // Greeks can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_JAVELIN_CAVALRY)) { // if Gr. Light Cavalry
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
return 1; // Greeks can build it
} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
return 1; // Neutral Greeks can build it
} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
return 1; // Traitorous Greeks can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_HYPASPISTS)) { // if Elite Hoplite
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
return 1; // Greeks can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_HORSEMAN)) { // if Persian Heavy Cavalry
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
return 1; // Persians can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_ARCHER)) { // if Gr. Archer
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
return 1; // Greeks can build it
} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
return 1; // Neutral Greeks can build it
} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
return 1; // Traitorous Greeks can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_PARATROOPER)) { // if Militia
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
return 1; // Persians can build it
} else {
return 0; // other civs can't
} elseif ((tmpUnit == UnitDB(UNIT_PEZHETEROI)) { // if Persian Infantry
if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
return 1; // Persians can build it
} else {
return 0; // other civs can't
} else { // if other unit
return 1; // everyone can always build it
}
}

in AG_mod it says that there is a syntax error on line 19, but I can't find it. None of the instructions I gave it came through, Though I didn't check the research Technology one.

thanx for any help.



[This message has been edited by Chris B (edited March 13, 2001).]
Chris B is offline  
Old March 13, 2001, 11:00   #2
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
A syntax error is an error in the way you use the code: you're doing something that's undefined according to the rules of SLIC. For example, you're using too many (or too little) brackets, you're forgetting a ';', you made some kind of typo (e.g. 'wihle' instead of 'while'), something like that. These errors are generally very easy to spot when you know where to look.

However, you don't give enough information for me to know where to look. 'Syntax error in line 4': Line 4 of what file? And even if I know the file I still need to know exactly what the code looks like, even an empty line or a comment counts as a line when it comes to line-counting so the layout you post here must be exactly identical to the layout of your actual file. (It might be better to post a URL to the actual file instead of posting the contents of the file, or emailing me and attaching the file.)

The way I look at the two sections of code you posted, line 4 of scenario.slc is the line

Code:
if(IsPlayerAlive(2)) { // if Persians aren't dead
and line 4 of AG_mod.slc is the line

Code:
#include "AG_mod.slc" // Mod Functions
Neither line seems to contains a syntax error, so either I screwed up the line-count or the error is in one of the other SLIC files.

The only possible problem I in the code you posted is that you include all files several times, this may cause problems. It's sufficient to include every file exactly 1 time. Another problem, very similiar to the previous, is that you're including AG_mod.slc from itself, this could well cause problems as well. I suspect that, everytime the game encounters a include-statement, it loads the file in the statement and only once it has completely parsed that entire file, it will parse the rest of the file in which the include statement was found. If you include a file from itself, it will load the file, parse up to the point of the include statement to itself, load the file again, parse up to the include statement again, load the file again, etc. It will end up in an infinite loop. I'm not sure if this is how it really works, but if it does, this syntax error could be intended to catch these infinite loops. In any case, it's not a good idea to include a file from itself.

And yes, if the code finds a syntax error, you should always assume that the rest of the code is not executed at all or executed incorrectly (even though this may not always be the case). The first thing to do when you encounter a syntax error is to fix that error; any effects code with syntax errors may or may not have are completely unreliable and unpredictable.
[This message has been edited by Locutus (edited March 13, 2001).]
Locutus is offline  
Old March 13, 2001, 11:41   #3
Chris B
Warlord
 
Chris B's Avatar
 
Local Time: 04:57
Local Date: October 31, 2010
Join Date: Oct 2000
Location: Canton, CT
Posts: 187
sorry, locutus, what I had before was pretty miserable for AG-mod . I've altered the above thread. But it still wont work. In addition, I nned help with a few more advanced trigger for the scenario.

-Phedipeddes Unit- Military forces should pop up at random wherever he goes.
-Victory By Defending Athens Piraeus, Sparta, Corinth, and Thebes for 180 turns.
-Victory by capturing Sardis
- For Alexander I Know Harlan made a custom Queue for every city in AG_mod.
I only need it for 6 cities- Sparta, which builds Spartan Hoplites, Athens, Piraeus, Corinth and Thebes, which build Elite Hoplites, and Sardis which Builds 10000 Immmortals (Persian Elites). Can I do this w/o customizing every city?
- How do you get flat map support?
- one last thing. I want 10000 immortals to be Buildable, but because there could only be 10000, have no more than six possible to have at a time. Could I set a trigger so the Persians could build new ones only to Replace Dead?
Thanx once again.

[This message has been edited by Chris B (edited March 13, 2001).]
Chris B is offline  
Old March 13, 2001, 12:26   #4
Hannibal Ad Portas
Chieftain
 
Local Time: 09:57
Local Date: October 31, 2010
Join Date: Feb 2001
Location: IOW UK
Posts: 72
Hi

This wont help you with your slic but have you considerd this:-

To prevent research past a certain point
Remove offending tech from the advance list

To make a unit race specific
Use enable gov in unit.txt as precurser to build that unit as your scn
has only a couple of sides you should have no trouble assigning a specific
gov type to each faction which you then use to customise the unit
build list so that each personality/gov will produce the units you
want them to.Remember to have a set of generic units available to all
then a set for each gov.

Example
Sythian Nobles
CATEGORY_FLANKER
Attack 35
Defense 25
ZBRangeAttack 35
Firepower 1
Armor 1
MaxHP 15
ShieldCost 750
ShieldHunger 5
MaxMovePoints 500
VisionRange 1
HORSE_RIDING
GOVERNMENT_TYRANNY
ProbOfBombHit 50
BombRounds 10
BombardRange 1
CanCounterBombard

All of this takes considerable less work than slic, which to my
mind should be used to create what cannot be achieved by other means.
No offense intended, just thought you might like to consider other
ways of getting stuff done.look forward to your scn,when will it be
ready?

hannibal
Hannibal Ad Portas is offline  
Old March 13, 2001, 16:40   #5
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
Chris,
Is the code you posted for AG_mod.slc identical to the code in your file? If that's so, a part of the Civ Special Units section is missing. You're supposed to start with a function header and you're supposed to start a series of if-clauses with if and not elseif, like this:

Code:
int_f mod_CanCityBuildUnit(city_t theCity, int_t theUnit) {
city_t	tmpCity;
int_t	tmpUnit;
	tmpUnit = theUnit;
	tmpCity = theCity;

	// use IF the first time (not ELSEIF):
	if ((tmpUnit == UnitDB(UNIT_PIKEMEN)) { // if hopite
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
			return 1;	// greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
			return 1;	// Neutral Greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
			return 1;	// Traitorour Greeks can build it
		} else {
			return 0;	// other civs can't
		}
	// use ELSEIF all subsequent times:
	} elseif ((tmpUnit == UnitDB(UNIT_MACHINE_GUNNER)) {	// if 10000 Immortals
	//	... (etc)
If this is indeed what goes wrong, that explains your syntax error on line 19, the first line of the Civ Special Units section could well be line 19 in your code. If this isn't the complete code and you *did* have this section correct in your own version of the code, I can't help you further until I see the complete code.

As far as the other sections go, I could give you some pointers but you'll have to fill in the details yourself.

Rough code on randomly creating units on/near tile of Phedipeddes (you'll probably want to refine this):
Code:
HandleEvent(MoveUnits) 'HandlePhedipeddes' post {	// or BeginTurn or something else, whatever you want/need
int_t	chance;
unit_t	tmpUnit;
	tmpUnit = unit[0];


	if (tmpUnit.type == UnitDB(UNIT_PHEDIPEDDES) {
		chance = Random(4);
		if (chance == 1) {	// chance of 1 in 4 (= 25%)
			if (Random(2) == 1) {	// 50% chance of Warrior (on random location 1 tile away from Phedipeddes)
				CreateUnit(tmpUnit.owner, UnitDB(UNIT_WARRIOR), tmpUnit.location, 1);
			} else {		// 50% chance of Hoplite (on same tile as Phedipeddes - i.e. distance to Phedipeddes is zero)
				CreateUnit(tmpUnit.owner, UnitDB(UNIT_HOPLITE), tmpUnit.location, 0);
			}
		}
	}
}
For the Victory code keep variables for every city you wish to keep track of, so (global) declaration section could look like this:
Code:
int_t athensTaken;
int_t spartaTaken;
int_t corinthTaken;
int_t sardisTaken;
// etc.

HandleEvent(BeginTurn) 'GameStart' post {	// execute at beginning of (first) turn
	athensTaken = 0;
	spartaTaken = 0;
	corinthTaken = 0;
	sardisTaken = 0;
	// etc.


	DisableTrigger('GameStart');	// execute this only once
}
Then, when a city is conquered, check if it's one of your victory cities:
Code:
HandleEvent(CaptureCity) 'CaptureCity' post {
city_t	tmpCity;
	tmpCity = city[0];


	if (tmpCity.location == athensLoc) {	// this requires you to store city locations as well (ala Alexander scenario)
	// or:

	if (CityIsNamed(tmpCity.name, "Athens") {
		athensTaken = 1;
		// or: immediately declare defeat:
		GameOver(1, 2); // player 1 lost (game stops)
	}

	if (tmpCity.location == sardisLoc) {
		sardisTaken = 1;
		// or: immediately declare victory:
		GameOver(1, 1);	// player 1 won (game stops)
	}
}

HandleEvent(BeginTurn) 'CheckTime' post {
	if (g.year == 180) {	// presuming start of game is year 0 (which is the normal situation, g.year stores turns rather than gameyears)
		if (!athensTaken && !spartaTaken && !corinthTaken) { // etc. (0 = false, 1 = true, !something = not something)
			GameOver(1, 1); // player 1 won (game stops) -> presuming human is player 1 (usually the case)
		} else {
			GameOver(1, 2); // player 1 lost (game stops)
	}
}
For the city-specific build queues you'll have to specify that per city unless those cities have something in common (e.g. Sparta is part of 1 civ, Sardis of another, the others cities of a third or something with terraintype or wonders or buildings or whatever and all this stays the same througout the game), then you could generalize things. In this case it doesn't really matter since there are only 3 groups (presuming there are no other cities in the game): make 1 case for sparta, 1 for sardis and 1 for all other cities (so city is sparta -> build spartan hoplites, else not; city is sardis -> build persian hoplites, else not; city is not sparta or sardis -> build elite hoplites).

Flat-map support: in CtP2 you don't need SLIC for that (which means my SLIC1 code for this is completely useless now ). You can set this in the scenario editor (under the tab Map somewhere IIRC).

10000 Immortals max: simple:

Code:
int_f mod_CanCityBuildUnit(city_t theCity, int_t theUnit) {
city_t	tmpCity;
int_t	tmpUnit;
	tmpUnit = theUnit;
	tmpCity = theCity;

	if ((tmpUnit == UnitDB(UNIT_10000_IMMORTALS)) {
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {	// if player is spartan
			if (UnitCount(tmpCity.owner, UnitDB(UNIT_10000_IMMORTALS)) < 6) {
				return 1; // if less than 6 units of this type
			} else {
				return 0;
			}
		}
		// note: maybe you should use ID_UNIT_10000_IMMORTALS or "UNIT_10000_IMMORTALS" instead of the UnitDB thing,
		// since this is heritage code from CtP1 and the syntax was offen slightly different in SLIC1
	}
}
Note that you can only have 1 mod_CanCityBuildUnit function, so you'll have to combine this with you're already existing code.

Hope this helps...

Hannibal,

You're absolutely right that it's usually better to use non-SLIC solutions if those are available (it often saves a lot of resources and thus makes the game run faster and it is often also easier and faster to implement) and in case of the Advances this could well be done by making the relevant advances prerequisites of themselves, but the solutions you propose are less then ideal.
Removing advances altogether is a lot more work than previously mentioned solutions. It probably requires altering at least half a dozen files all over the folders whereas the SLIC solution or making it a prerequisite of itself only requires altering a few lines concentrated in a single file.
Your solution of editing units to be government specific is an equally large amount of work whereas the SLIC solution is much simpler to achieve (the code may look complicated if you're not into it but it really doesn't contain more than 5 or 6 lines that are copy-'n-pasted and slightly altered for every unit). Even a beginning non-programmer can make this code in less than 30 seconds per civ once he knows how to do it. Combine that with the fact that it's much more flexible (you can basicly control city-by-city and turn-by-turn what can and cannot be built) and the SLIC solution is in this case far superior to any other solution.
[This message has been edited by Locutus (edited March 13, 2001).]
Locutus is offline  
Old March 13, 2001, 22:05   #6
Chris B
Warlord
 
Chris B's Avatar
 
Local Time: 04:57
Local Date: October 31, 2010
Join Date: Oct 2000
Location: Canton, CT
Posts: 187
Thanx for the help Locutus. What a bonehead I was not to include the key.
I will implement these changes as soon as I can. One thing though- There are lots more Cities than the ones that build elite Hoplites for Greece.
The civs are arranged Like This.
Player 1- Greeks
Player 2- Persians
Player 3- Neutral Greeks
Player 4- Pro-Persian Greeks

every civ has multiple cities- the greeks and persians perhaps 25 each. Lesser Greek cities sould only be able to build Hoplites and Hoplite Militias. I want only Principal Cities (Athens, Piraeus, Corinth, Thebes) to build Elite Hoplites and only Sparta to build Spartan Hoplites. Same goes with Sardis 4 Persians.
All other Unit instructions were explianed in my above scrit for AG_mod. If there are only 6 exception Cities, I shouldn't have to do every city, should I? Or am I Just Lazy ?
Chris B is offline  
Old March 14, 2001, 07:18   #7
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
Yes, if there are only 6 exception cities you'll only have to define 4 cases: regular cities, Sparta, Sardis and APCT (Athens/Piraeus/Corinth/Thebes).
Locutus is offline  
Old March 14, 2001, 07:58   #8
Chris B
Warlord
 
Chris B's Avatar
 
Local Time: 04:57
Local Date: October 31, 2010
Join Date: Oct 2000
Location: Canton, CT
Posts: 187
Thats sounds confusing. I'd appreciate an example piece of code for doing the group of for. But in Alexander, Harlan does it by listing all the units every city Can't Build. Could I Do Can Build instead?
As soon as I make all the Mod Functions Changes Correctly aas well as the Victory Conditions, I'll post it on my mydocs page. The only other problem is i still don't Fully understand how to make a messageBox Appear on the Screen with choices.
Everyone thanks 4 the help.
-CB
[This message has been edited by Chris B (edited March 14, 2001).]
[This message has been edited by Chris B (edited March 14, 2001).]
Chris B is offline  
Old March 14, 2001, 08:33   #9
Chris B
Warlord
 
Chris B's Avatar
 
Local Time: 04:57
Local Date: October 31, 2010
Join Date: Oct 2000
Location: Canton, CT
Posts: 187
Okay, I just put in that header and now its still crashing on line 25 no matter what I do.
Code:
// Civ Special Units

int_f mod_CanCityBuildUnit(city_t theCity, int_t theUnit) {
city_t	tmpCity;
int_t	tmpUnit;
	tmpUnit = theUnit;
	tmpCity = theCity;
	// use IF the first time (not ELSEIF):
	} if ((tmpUnit == UnitDB(UNIT_PIKEMEN)) {	// if hopite
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
			return 1;		// greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
			return 1;		// Neutral Greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
			return 1;		// Traitorous Greeks can build it
		} else {
			return 0;		// other civs can't
		}
	} elseif ((tmpUnit == UnitDB(UNIT_MACHINE_GUNNER)) {	// if 10000 Immortals
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
			return 1;		// Persians can build it
		} else {
			return 0;		// other civs can't
I somehow get Suspicious that it would be civ, not city, even though that has nothing to do with the PIKEMEN line in question, but i no almost nothing about SLIC (I hope this project will change That).
-CB
Chris B is offline  
Old March 14, 2001, 09:10   #10
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
I guess I wasn't too clear in explaining this. For the mod-functions you can use all logic available in SLIC, so if you want to specify things city-by-city, be my guest, but if you want to figure out a way that requires as little work as possible, you can use all the logic in the world to do that. If I understood you correctly, what you're looking for is something like this:

Code:
int_f mod_CanCityBuildUnit(city_t theCity, int_t theUnit) {
city_t	tmpCity;
int_t	tmpUnit;
	tmpUnit = theUnit;
	tmpCity = theCity;
	
	if (tmpUnit == UnitDB(UNIT_HOPLITE)) {
		if (tmpCity.owner == 1 | | tmpCity.owner == 3 | | tmpCity.owner == 4) {	// player 1, 3 or 4
			if (tmpCity.location != athensLoc && tmpCity.location != piraeusLoc
					&& tmpCity.location != corinthLoc && tmpCity.location != thebesLoc) {
			return 1;					// except for big cities, all greeks can build this
		} else {
			return 0;					// big cities and non-Greeks can't build this
		}
	} elseif (tmpUnit == UnitDB(UNIT_10000_IMMORTALS)) {
		if (tmpCity.owner == 2) {				// only if persians own city this can be built
			if (tmpCity.location == sardisLoc) {		// only sardis can build this
				if (UnitCount(tmpCity.owner, UnitDB(UNIT_10000_IMMORTALS)) < 6) {
					return 1;			// no more than 6 can be built
				} else {
					return 0;
				}
			} else {
				return 0;
			}
		} else {
			return 0;
		}
	} elseif (tmpUnit == UnitDB(UNIT_SPARTAN_HOPLITE)) {
		if (tmpCity.location == spartaLoc) {			// only sparta can build this
			return 1;					// (regardless of what civ Sparta belongs to)
		} else {
			return 0;
		}
	} elseif ((tmpUnit == UnitDB(UNIT_ELITE_HOPLITE)) {
		if (tmpCity.owner == 1 | | tmpCity.owner == 3 | | tmpCity.owner == 4) {	// player 1, 3 or 4
			if (tmpCity.location == athensLoc | | tmpCity.location == piraeusLoc | | tmpCity.location == corinthLoc
						| | tmpCity.location == thebesLoc) {
				return 1;				// only big cities of greeks can build this
			} else {
				return 0;
			}
		} else {
			return 0;
		}
//	} elseif (...) {	-> fill in rest of the units
	} else {
		return 1;						// all other units can always be built by everyone
	}
}
Bottom line: just use whatever logic you need, keeping the code as compact as you can, as this will not only save you a lot of time typing it all out, but it will also make the game run faster (which is always nice for those of us playing on P200 like myself

Messageboxes with choices aren't too difficult. Just call a message from the regular SLIC code whenever you need it (specifying the name of the message and the player to send it to) and define the actual message and all its options in a messagebox or alertbox structure. Add 1 button per choice (keep in mind that you can't have more than 4 or 5 button in 1 box) to allow different choices. Example:

Code:
HandleEvent(BeginTurn) 'Example' post {
	if (g.year == 0) {
		Message(1, 'ExampleMessage');	// in turn 0, send message with title 'ExampleMessage' to player 1
	}
}

Messagebox 'ExampleMessage' {			// message 'ExampleMessage' (gets called above)
	Show();
	// (optional) this makes the message pop up on screen (leaving this out would put the message only in the messagetab)
	Title(ID_EXAMPLE_TITLE);
	// (optional) set title for message (text files must contain a string with name EXAMPLE_TITLE which contains the title) 
	Text(ID_EXAMPLE_TEXT);
	// set text for message (text files must contain a string with name EXAMPLE_TEXT which contains the text of this message)
	Button(ID_BUTTON_YES) {
	// Choice 1: Button with name YES (text files must contain a string with name BUTTON_YES which contains the text that will be 
				// displayed on the button, e.g. "Yes")
		// here comes all the code that will be executed if player clicks on button YES:
		GameOver(1, 1);				// player 1 wins the game
		Kill();					// message is killed (not really needed since game is over)
	}					// -> it will close and disappear from the message history tab
	Button(ID_BUTTON_NO) {
	// Choice 2: Button with name NO (text files must contain a string with name BUTTON_NO)
		// here comes all the code that will be executed if player clicks on button NO:
		CreateUnit(1, UnitDB(WARRIOR), athensLoc, 0);	// place warrior in athens
		Kill();					// message is killed
	}
	Button(ID_BUTTON_DONT_KNOW) {
	// Choice 3: Button with name DONT_KNOW (text files must contain a string with name BUTTON_DONT_KNOW)
		// here comes all the code that will be executed if player clicks on button DONT_KNOW:
		Message(1, 'SomeOtherMessage');			// some other message is displayed
		Kill();					// message is killed
	}
}
Hope this helps...
[This message has been edited by Locutus (edited March 14, 2001).]
Locutus is offline  
Old March 14, 2001, 09:16   #11
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
The crash on line 25 is probably because I made a mistake with the brackets:

if ((tmpUnit == UnitDB(UNIT_PIKEMEN)) { // if hopite

should be

if (tmpUnit == UnitDB(UNIT_PIKEMEN)) { // if hopite

With my code you'll always have to double-check the brackets if you get errors, 'cause I do that a lot

Edit: same goes for all other units

[This message has been edited by Locutus (edited March 14, 2001).]
Locutus is offline  
Old March 14, 2001, 20:19   #12
Chris B
Warlord
 
Chris B's Avatar
 
Local Time: 04:57
Local Date: October 31, 2010
Join Date: Oct 2000
Location: Canton, CT
Posts: 187
I just plugged in the new code and a new syntax error appeared. At least we know we fixed the old one. I"ve made every possible effort to fix it.
Line 26:
f (tmpCity.owner == 1) | | tmpCity.owner == 3 | | tmpCity.owner == 4) { // player 1, 3 or 4

Thanx again Locutus, I apologize if you think I'm feeding of you .
Chris B is offline  
Old March 14, 2001, 21:47   #13
Dale
Emperor
 
Dale's Avatar
 
Local Time: 19:57
Local Date: October 31, 2010
Join Date: Dec 2000
Posts: 3,944
quote:

Originally posted by Chris B on 03-14-2001 07:19 PM
I just plugged in the new code and a new syntax error appeared. At least we know we fixed the old one. I"ve made every possible effort to fix it.
Line 26:
f (tmpCity.owner == 1) | | tmpCity.owner == 3 | | tmpCity.owner == 4) { // player 1, 3 or 4

Thanx again Locutus, I apologize if you think I'm feeding of you .


Chris:
Bracket problem:

Code:
if (tmpCity.owner == 1 | | tmpCity.owner == 3 | | tmpCity.owner == 4) { // player 1, 3 or 4
------------------
Rommell to a sub-commander outside Tobruk: "Those Australians are in there somewhere. But where? Let's advance and wait till they shoot, then shoot back."
Dale is offline  
Old March 15, 2001, 12:28   #14
Chris B
Warlord
 
Chris B's Avatar
 
Local Time: 04:57
Local Date: October 31, 2010
Join Date: Oct 2000
Location: Canton, CT
Posts: 187
Damn it still dont work. I have the worst luck with slic of anyone!!!!!!!!!!!!!
Fortunatley I do have Good news. The Savegame is coming along Splendidly. As soon as we fix ths, I should be able to post it for playtesting.
[This message has been edited by Chris B (edited March 15, 2001).]
Chris B is offline  
Old March 20, 2001, 11:27   #15
Chris B
Warlord
 
Chris B's Avatar
 
Local Time: 04:57
Local Date: October 31, 2010
Join Date: Oct 2000
Location: Canton, CT
Posts: 187
Sorry, I haven't forgotten everyone. My family took a trip for the weekend and I didn't recieve help. This is the full and still prblematic AG-mod slc. code
Code:
//Mod Functions for GreecevsPersia, 490 BC

// Players are can not research past Siege Weapons, Hullmaking, Stirrup, and Ethics
int_f mod_CanPlayerHaveAdvance (int_t thePlayer, int_t theAdvance)
{
	if (theAdvance == AdvanceDB(ADVANCE_SIEGE_WEAPONS) | |
		theAdvance == AdvanceDB(ADVANCE_SIEGE_WEAPONS) | |
		theAdvance == AdvanceDB(ADVANCE_HULL_MAKING) | |
		theAdvance == AdvanceDB(ADVANCE_STIRRUP) | |
		theAdvance == AdvanceDB(ADVANCE_ETHICS)) {
		return 0;
	} else {
		return 1;
	}
}

// Civ Special Units

int_f mod_CanCityBuildUnit(city_t theCity, int_t theUnit) {
city_t	tmpCity;
int_t	tmpUnit;
	tmpUnit = theUnit;
	tmpCity = theCity;
	
	if (tmpUnit == UnitDB(UNIT_PIKEMEN)) {
		if (tmpCity.owner == 1 | | tmpCity.owner == 3 | | tmpCity.owner == 4) {	// player 1, 3 or 4
			if (tmpCity.location != athensLoc && tmpCity.location != piraeusLoc
					&& tmpCity.location != corinthLoc && tmpCity.location != thebesLoc) {
			return 1;					// except for big cities, all greeks can build this
		} else {
			return 0;					// big cities and non-Greeks can't build this
		}
	} elseif (tmpUnit == UnitDB(UNIT_MACHINE_GUNNER)) {
		if (tmpCity.owner == 2) {				// only if persians own city this can be built
			if (tmpCity.location == sardisLoc) {		// only sardis can build this
				if (UnitCount(tmpCity.owner, UnitDB(UNIT_10000_IMMORTALS)) < 6) {
					return 1;			// no more than 6 can be built
				} else {
					return 0;
				}
			} else {
				return 0;
			}
		} else {
			return 0;
		}
	} elseif (tmpUnit == UnitDB(UNIT_INFANTRYMAN)) {
		if (tmpCity.location == spartaLoc) {			// only sparta can build this
			return 1;					// (regardless of what civ Sparta belongs to)
		} else {
			return 0;
		}
	} elseif (tmpUnit == UnitDB(UNIT_HYPASPISTS)) {
		if (tmpCity.owner == 1 | | tmpCity.owner == 3 | | tmpCity.owner == 4) {	// player 1, 3 or 4
			if (tmpCity.location == athensLoc | | tmpCity.location == piraeusLoc | | tmpCity.location == corinthLoc
						| | tmpCity.location == thebesLoc) {
				return 1;				// only big cities of greeks can build this
			} else {
				return 0;
			}
		} else {
			return 0;
		}
	} elseif ((tmpUnit == UnitDB(UNIT_CHARIOT)) {	// if Chariot
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
			return 1;		// Persians can build it
		} else {
			return 0;		// other civs can't
	} elseif ((tmpUnit == UnitDB(UNIT_HOPLITE)) {	// if Hoplite Militia
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
			return 1;		// Greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
			return 1;		// Neutral Greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
			return 1;		// Traitorous Greeks can build it
		} else {
			return 0;		// other civs can't
	} elseif ((tmpUnit == UnitDB(UNIT_COMPOSITE_ARCHER)) {	// if Persian Archer
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
			return 1;		// Persians can build it
		} else {
			return 0;		// other civs can't
	} elseif ((tmpUnit == UnitDB(UNIT_TEUTONIC_KNIGHT)) {	// if Greek Heavy Cavalry
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
			return 1;		// Greeks can build it
		} else {
			return 0;		// other civs can't
	} elseif ((tmpUnit == UnitDB(UNIT_JAVELIN_CAVALRY)) {	// if Gr. Light Cavalry
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
			return 1;		// Greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
			return 1;		// Neutral Greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
			return 1;		// Traitorous Greeks can build it
		} else {
			return 0;		// other civs can't
	} elseif ((tmpUnit == UnitDB(UNIT_HORSEMAN)) {	// if Persian Heavy Cavalry
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
			return 1;		// Persians can build it
		} else {
			return 0;		// other civs can't
	} elseif ((tmpUnit == UnitDB(UNIT_ARCHER)) {	// if Gr. Archer
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("GREEKS")) {
			return 1;		// Greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ROMANS")) {
			return 1;		// Neutral Greeks can build it
		} elseif (PlayerCivilization(tmpCity.owner) == CivilizationIndex("ENGLISH")) {
			return 1;		// Traitorous Greeks can build it
		} else {
			return 0;		// other civs can't
	} elseif ((tmpUnit == UnitDB(UNIT_PARATROOPER)) {	// if Militia
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
			return 1;		// Persians can build it
		} else {
			return 0;		// other civs can't
	} elseif ((tmpUnit == UnitDB(UNIT_PEZHETEROI)) {	// if Persian Infantry
		if (PlayerCivilization(tmpCity.owner) == CivilizationIndex("PERSIANS")) {
			return 1;		// Persians can build it
		} else {
			return 0;		// other civs can't
	} else {				// if other unit
		return 1;			// everyone can always build it
	}
}
The Problematic line is
Code:
if (tmpCity.owner == 1 | | tmpCity.owner == 3 | | tmpCity.owner == 4) {	// player 1, 3 or 4
also, the game just carashed on the savegame. I think I'll need 2 or 3 more days.
-CB
Chris B is offline  
Old March 20, 2001, 16:51   #16
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 11:57
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
Well, believe it or not, it's once again a bracket error, this time only a }-bracket instead of a )-bracket. But I also saw another bug, that's more or less related to the bracket problem: there's 1 else clause to little. Here's what the fixed part should look like:
Code:
	if (tmpUnit == UnitDB(UNIT_PIKEMEN)) {
		if (tmpCity.owner == 1 | | tmpCity.owner == 3 | | tmpCity.owner == 4) {	// player 1, 3 or 4
			if (tmpCity.location != athensLoc && tmpCity.location != piraeusLoc
					&& tmpCity.location != corinthLoc && tmpCity.location != thebesLoc) {
				return 1;					// except for big cities, all greeks can build this
			} else {
				return 0;
			}					// big cities and non-Greeks can't build this
		} else {		// new
			return 0;	// new
		}			// new
	} elseif (tmpUnit == UnitDB(UNIT_MACHINE_GUNNER)) {
[This message has been edited by Locutus (edited March 20, 2001).]
Locutus is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:57.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Apolyton Civilization Site | Copyright © The Apolyton Team