Thread Tools
Old July 21, 2001, 00:29   #1
Jules
Warlord
 
Jules's Avatar
 
Local Time: 06:42
Local Date: October 31, 2010
Join Date: Jul 2001
Location: Chairman & CEO, Dallas Oil Company
Posts: 142
Need help in SLIC
I'm trying to write a program that will warn the player whenever they discover an advance the makes a building obsolete. The popup message will tell the player the advance, the building made obsolete, and the replacement building. Here's a sample of my code:

Code:
messagebox 'BUILDING_OBSOLETE_1_MSG' {
  Text(ID_BUILDING_OBSOLETE_1);
  Show();
}

HandleEvent(GrantAdvance) 'BuildingExpires' post {
  int_t advanceType;
  advanceType = value[0];
  advance[0] = advanceType;
  if (advanceType == AdvanceDB(ADVANCE_ECONOMICS)) {
    building[0] = BuildingDB(IMPROVE_BAZAAR);
    building[1] = BuildingDB(IMPROVE_BROKERAGE);
    Message(player[0], 'BUILDING_OBSOLETE_1_MSG');
  }
}
Then in "info_str.txt" I have the following string:

BUILDING_OBSOLETE_1 "Our knowledge of {advance[0].name} has made the improvement {building[0].name} obsolete. However we can now build the {building[1].name} improvement instead."

Now everything works except when I get the popup message in-game, where it should say "Bazaar" it says "{building[0].name}" and where it should say "Brokerage" it says "{building[1].name}". I don't get it.

Please help!
__________________
"People sit in chairs!" - Bobby Baccalieri
Jules is offline  
Old July 21, 2001, 11:14   #2
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 12:42
Local Date: October 31, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
I think this is caused when you have DebugSlic set to No. Its one of those annoying things that Activision didn't think much about.
Try it, I'm fairly sure that will help.
Immortal Wombat is offline  
Old July 21, 2001, 11:59   #3
Peter Triggs
CTP2 Source Code ProjectCivilization IV Creators
King
 
Local Time: 11:42
Local Date: October 31, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
Jules,

For your specific example, you could use:

Code:
    HandleEvent(GrantAdvance) 'BuildingExpires' post { 

         advance[0]=value[0];
         if (value[0] == AdvanceDB(ADVANCE_ECONOMICS)) {
 
              Message(player[0], 'BUILDING_OBSOLETE_1_MSG');
         }
    }
with:

BUILDING_OBSOLETE_1 "Our knowledge of {advance[0].name} has made the improvement {BuildingDB(IMPROVE_BAZAAR)} obsolete. However we can now build the {BuildingDB(IMPROVE_BROKERAGE)} improvement instead."

But you'll then have to do this over again for each advance that makes a building obsolete. As there's quite a few of them you might want to set up a mapping from advances to buildings via a system of arrays. This is what I did in my UnitUpdater. In your case it would look something like this:

obsadv[0]=AdvanceDB(ADVANCE_ECONOMICS) ;
OBS_BUILDING_TYPE[0]= BuildingDB(IMPROVE_BAZAAR);
NEW_BUILDING_TYPE[0]= BuildingDB(IMPROVE_BROKERAGE);

obsadv[1]=AdvanceDB(ADVANCE_whatever) ;
OBS_BUILDING_TYPE[1]= BuildingDB(IMPROVE_whatever);
NEW_BUILDING_TYPE[1]= BuildingDB(IMPROVE_whatever);

obsadv[2]=AdvanceDB(ADVANCE_and so on) ;
OBS_BUILDING_TYPE[2]= BuildingDB(IMPROVE_and so on);
NEW_BUILDING_TYPE[2]= BuildingDB(IMPROVE_and so on);

Your handler would then look like:

Code:
// Globals:
int_t BUILDING_INDEX;
int_t OBS_BUILDING_TYPE[];
int_t NEW_BUILDING_TYPE[];

    HandleEvent(GrantAdvance) 'BuildingExpires' post {

    int_t i;
    int_t obsadv[];

    // the above data arrays can go here

     for(i=0; i
with:

BUILDING_OBSOLETE_1 "Our knowledge of {advance[0].name} has made the improvement {BuildingDB(OBS_BUILDING_TYPE[BUILDING_INDEX])} obsolete. However we can now build the {BuildingDB(NEW_BUILDING_TYPE[BUILDING_INDEX])} improvement instead."


This is assuming that no advance obsoletes more than one type of building. It's a bit more complicated if you allow that to happen. No guarentees the above code will work as it stands; I might have forgotten something.
Peter Triggs is offline  
Old July 21, 2001, 17:15   #4
Jules
Warlord
 
Jules's Avatar
 
Local Time: 06:42
Local Date: October 31, 2010
Join Date: Jul 2001
Location: Chairman & CEO, Dallas Oil Company
Posts: 142
Thanks Peter! Your suggestion worked.

Immortal: Don't you have to have DebugSLIC set to "no" in order to run the Med Mod? But that's a moot point now since I got it to work.

For anyone with the Med Mod interested in implementing this little bit of SLIC, here's the full code:

Code:
messagebox 'BUILDING_OBSOLETE_1_MSG' {
  Text(ID_BUILDING_OBSOLETE_1);
  Show();
}

messagebox 'BUILDING_OBSOLETE_2_MSG' {
  Text(ID_BUILDING_OBSOLETE_2);
  Show();
}



int_t BUILDING_INDEX;
int_t OBS_BUILDING_1_TYPE[];
int_t OBS_BUILDING_2_TYPE[];
int_t NEW_BUILDING_TYPE[];



HandleEvent(GrantAdvance) 'BuildingExpires' post {
  int_t i;
  int_t obsadv[];
  int_t advanceType;
  advanceType = value[0];
  advance[0] = advanceType;

  obsadv[0] = AdvanceDB(ADVANCE_ECONOMICS);
  OBS_BUILDING_1_TYPE[0] = BuildingDB(IMPROVE_BAZAAR);
  NEW_BUILDING_TYPE[0] = BuildingDB(IMPROVE_BROKERAGE);

  obsadv[1] = AdvanceDB(ADVANCE_DIGITAL_ENCRYPTION);
  OBS_BUILDING_1_TYPE[1] = BuildingDB(IMPROVE_BANK);
  NEW_BUILDING_TYPE[1] = BuildingDB(IMPROVE_E_BANK);

  obsadv[2] = AdvanceDB(ADVANCE_MASS_MEDIA);
  OBS_BUILDING_1_TYPE[2] = BuildingDB(IMPROVE_CITY_CLOCK);
  NEW_BUILDING_TYPE[2] = BuildingDB(IMPROVE_TELEVISION);

  obsadv[3] = AdvanceDB(ADVANCE_PUBLIC_EDUCATION);
  OBS_BUILDING_1_TYPE[3] = BuildingDB(IMPROVE_ACADEMY);
  NEW_BUILDING_TYPE[3] = BuildingDB(IMPROVE_ORBITAL_LABORATORY);

  obsadv[4] = AdvanceDB(ADVANCE_COMPUTER);
  OBS_BUILDING_1_TYPE[4] = BuildingDB(IMPROVE_PUBLISHING_HOUSE);
  NEW_BUILDING_TYPE[4] = BuildingDB(IMPROVE_COMPUTER_CENTER);

  obsadv[5] = AdvanceDB(ADVANCE_OIL_REFINING);
  OBS_BUILDING_1_TYPE[5] = BuildingDB(IMPROVE_MILL);
  NEW_BUILDING_TYPE[5] = BuildingDB(IMPROVE_OIL_REFINERY);

  obsadv[6] = AdvanceDB(ADVANCE_ROBOTICS);
  OBS_BUILDING_1_TYPE[6] = BuildingDB(IMPROVE_FACTORY);
  NEW_BUILDING_TYPE[6] = BuildingDB(IMPROVE_ROBOTIC_PLANT);

  obsadv[7] = AdvanceDB(ADVANCE_NANO_ASSEMBLY);
  OBS_BUILDING_1_TYPE[7] = BuildingDB(IMPROVE_OIL_REFINERY);
  NEW_BUILDING_TYPE[7] = BuildingDB(IMPROVE_NANITE_FACTORY);

  obsadv[8] = AdvanceDB(ADVANCE_FUSION);
  OBS_BUILDING_1_TYPE[8] = BuildingDB(IMPROVE_NUCLEAR_PLANT);
  NEW_BUILDING_TYPE[8] = BuildingDB(IMPROVE_FUSION_PLANT);

  obsadv[9] = AdvanceDB(ADVANCE_FUEL_CELLS);
  OBS_BUILDING_1_TYPE[9] = BuildingDB(IMPROVE_PUBLIC_TRANSPORTATION);
  NEW_BUILDING_TYPE[9] = BuildingDB(IMPROVE_ECO_TRANSIT);

  obsadv[10] = AdvanceDB(ADVANCE_MOLECULAR_SYNTHESIS);
  OBS_BUILDING_1_TYPE[10] = BuildingDB(IMPROVE_RECYCLING_PLANT);
  NEW_BUILDING_TYPE[10] = BuildingDB(IMPROVE_MATTER_DECOMPILER);

  obsadv[11] = AdvanceDB(ADVANCE_NEURAL_REPROGRAMMING);
  OBS_BUILDING_1_TYPE[11] = BuildingDB(IMPROVE_COURTHOUSE);
  NEW_BUILDING_TYPE[11] = BuildingDB(IMPROVE_BEHAVIORAL_MOD_CENTER);

  obsadv[12] = AdvanceDB(ADVANCE_AI_SURVEILLANCE);
  OBS_BUILDING_1_TYPE[12] = BuildingDB(IMPROVE_CORRECTIONAL_FACILITY);
  NEW_BUILDING_TYPE[12] = BuildingDB(IMPROVE_SECURITY_MONITOR);

  obsadv[13] = AdvanceDB(ADVANCE_MILITARY_ENGINEERING);
  OBS_BUILDING_1_TYPE[13] = BuildingDB(IMPROVE_CITY_WALLS);
  NEW_BUILDING_TYPE[13] = BuildingDB(IMPROVE_BASTION);

  obsadv[14] = AdvanceDB(ADVANCE_ELECTRICITY);
  OBS_BUILDING_1_TYPE[14] = BuildingDB(IMPROVE_THEATER);
  OBS_BUILDING_2_TYPE[14] = BuildingDB(IMPROVE_ARENA);
  NEW_BUILDING_TYPE[14] = BuildingDB(IMPROVE_CIVIC_CENTER);

  obsadv[15] = AdvanceDB(ADVANCE_UNIFIED_PHYSICS);
  OBS_BUILDING_1_TYPE[15] = BuildingDB(IMPROVE_BALLISTA_TOWERS);
  OBS_BUILDING_2_TYPE[15] = BuildingDB(IMPROVE_BASTION);
  NEW_BUILDING_TYPE[15] = BuildingDB(IMPROVE_FORCEFIELD);

  for (i = 0; i < 16; i = i + 1) {
     BUILDING_INDEX = i;
     if (i == 14 || i == 15) {
       if (advanceType == obsadv[i]) {
         message(player[0], 'BUILDING_OBSOLETE_2_MSG');
       }
     } elseif (advanceType == obsadv[i]) {
           message(player[0], 'BUILDING_OBSOLETE_1_MSG');
     }
  }
}
And in your "info_str.txt":
BUILDING_OBSOLETE_1 "Our knowledge of {advance[0].name} has made the improvement {BuildingDB(OBS_BUILDING_1_TYPE[BUILDING_INDEX])} obsolete. However we can now build the {BuildingDB(NEW_BUILDING_TYPE[BUILDING_INDEX])} improvement instead."
BUILDING_OBSOLETE_2 "Our knowledge of {advance[0].name} has made the improvements {BuildingDB(OBS_BUILDING_1_TYPE[BUILDING_INDEX])} and {BuildingDB(OBS_BUILDING_2_TYPE[BUILDING_INDEX])} obsolete. However we can now build the {BuildingDB(NEW_BUILDING_TYPE[BUILDING_INDEX])} improvement instead."

You'll have to change this a little bit since I use a Civic Center building to replace Theaters and Arenas after the discovery of Electrification.
__________________
"People sit in chairs!" - Bobby Baccalieri
Jules is offline  
Old July 21, 2001, 17:27   #5
Peter Triggs
CTP2 Source Code ProjectCivilization IV Creators
King
 
Local Time: 11:42
Local Date: October 31, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
Glad it worked. Mind you, I don't know what happened to the code I posted earlier.

Ben's right about DebugSlic. If you don't have DebugSlic=Yes you won't get proper Error messages.
Peter Triggs is offline  
Old July 21, 2001, 17:58   #6
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 12:42
Local Date: October 31, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
Yeah, I don't run MedMod...
Immortal Wombat is offline  
Old July 21, 2001, 18:36   #7
Jules
Warlord
 
Jules's Avatar
 
Local Time: 06:42
Local Date: October 31, 2010
Join Date: Jul 2001
Location: Chairman & CEO, Dallas Oil Company
Posts: 142
Here's a different question:
Has anybody tried to implement the AddHappyTimer event? It has a city argument, and three other integer arguments. I'm guessing two of those are for amount of (un)happiness and duration, but I'm clueless as to what the third one is for. It'd be kind of neat to use this with Immortal's natural disasters code, like say random political unrest strikes a city. Like what's happening in Italy right now with the protests against the G8 summit.
__________________
"People sit in chairs!" - Bobby Baccalieri
Jules 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 07:42.


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