Bay 12 Games Forum

Other Projects => Curses => Topic started by: Jonathan S. Fox on September 26, 2012, 09:36:14 pm

Title: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on September 26, 2012, 09:36:14 pm
We've been posting a lot of programming stuff in the download thread, so I'm creating this topic to try to siphon off some of the discussion. Feel free to ask questions about any programming related stuff in this thread.
Title: Re: LCS Programming Discussion Topic
Post by: addictgamer on September 26, 2012, 09:53:08 pm
Hehe, thanks.

I don't mind the switch statement bit, but it can be fixed in other ways if it's problematic. For example:

Code: [Select]
   char* flavorText;
   switch(LCSrandom(4))
   {
   case 0:
      flavorText = "You keep the gas floored!";
      break;
   case 1:
      flavorText = "You swerve around the next corner!";
      break;
   case 2:
      flavorText = "You screech through an empty lot to the next street!";
      break;
   case 3:
      if(yourworst>15)
         flavorText = "You boldly weave through oncoming traffic!";
      else
         flavorText = "You make obscene gestures at the pursuers!";
      break;
   }

   addstr(flavorText, gamelog);
   gamelog.newline();

True. Good idea. I'll keep it in mind for future switch statements.
I see a couple issues with merging the gamelog.newline() call into addstr:

1. Curses already has a bunch of boggling variants on addstr, like mvwaddnstr.

To me, addstrl looks to me like it should affect how the text is displayed, or at least give me additional options in the parameter list about how I want the text displayed. If it has no impact on the parameter list or on displaying text, that will likely be unintuitive to people who have past experience with Curses.

To me, it's obvious it does more than just display something due to the log parameter.

2. The difference between addstrl and addstr isn't self-documenting.

When I'm assessing how to best integrate logging into the current system for displaying text, I'm worried about code readability. If I'm a new developer to the project, pulling up the source code, how will I know when I should use addstr and when should I use addstrl? I won't be able to figure out what that function does from seeing its name or how it's used -- I won't even know that the difference has something to do with logging rather than displaying text. I will likely be confused, because they appear to do the same thing. There's a good chance that I'll code and use one when they should have used the other, thus creating minor bugs in the logger that other programmers will have to clean up later.

Code: [Select]
addstr(cr->name, log);
addstr(" turns the tables on ", log);
addstr(a->name, log);
addstrl("!", log); // It's not obvious what the difference is here

addstr(a->name, log);
addstr(" has been tainted with wisdom!", log);
gamelog.endmessage(); // This leads to point #3...

Good points. The log parameter does add the realm of possibility that addstrl would effect the log, which only would make the situation more confusing due to even more possibilities.

3. You will need a variant for double newlines as well.

Both of the above concerns get worse when you have a distinction between endmessage() and newline(), and are trying to represent both with single-character variations on addstr's function name.

I hadn't thought of that. That's true.


Personally, I never/rarely come across the first two issues pointed out because I *almost* always check the definition of the function before using it.
That's why I didn't think of those two issues until you pointed them out.

Oh well. Like I said, I can float the code either way.
Title: Re: LCS Programming Discussion Topic
Post by: dreadmullet on September 26, 2012, 11:08:33 pm
One thing that seems to be missing is a flush command for gamelog. Here's an example:

Code: [Select]
for(int p=0;p<pool.size();p++)
{
if(!pool[p]->alive)
{
addstr("The Liberal " , gamelog);
addstr(pool[p].name , gamelog);
addstr(" is dead!" , gamelog);
gamelog.newline();
}

}

gamelog.newline();
// Need a flush function here.

adstr("Something happens!");
gamelog.nextMessage();

There should be a flush function between the "x is dead!" lines and "Something happens!". None of the logs are written to gamelog.txt until the final gamelog.nextMessage() call. This example doesn't seem like much, but in the part of siege.cpp I'm in, it could be a long time before gamelog.nextMessage() is called somewhere and the buffer is finally flushed.

Actually, a better idea would be to make gamelog.newLine() write the buffer to the file. There isn't anything wrong with that, is there?
Title: Re: LCS Programming Discussion Topic
Post by: addictgamer on September 26, 2012, 11:56:26 pm
Actually, a better idea would be to make gamelog.newLine() write the buffer to the file. There isn't anything wrong with that, is there?

Yes, I noticed that too in chase.cpp. I'll go ahead and add a flush function and update the newLine function to flush.
Title: Re: LCS Programming Discussion Topic
Post by: addictgamer on September 27, 2012, 02:50:19 am
Nevermind about the flush function, it was both redundant and a bad idea. I did modify newline to flush the log, though. It seems to be working nicely.
I've also finished with chase.cpp. Chases should now be logging!

Before anybody asks, yes, keep logging the way prescribed thus far. This update does not effect the use of the logger. It's an internal change only.

I'll see what other files I add logging to tomorrow. Probably the kidnap/hostage file in the combat folder.
Title: Re: LCS Programming Discussion Topic
Post by: addictgamer on September 27, 2012, 12:33:44 pm
I've added logging for combat/haulkidnap.cpp

I'm going to do daily/activities.cpp next.
Title: Re: LCS Programming Discussion Topic
Post by: dreadmullet on September 27, 2012, 10:18:43 pm
I've been working on an update to make sieges generally better, such as making them go on longer (less 1 day sieges, now). It makes safehouse improvements and rations much more important. I also made starving more lethal, and made it so people can die properly from it, and it shows a message. I'm also trying to gracefully fix the bug where there's a siege on an empty safehouse.

I've added logging to siege.cpp, and it's looking good. I'm starting on fight.cpp now.

Spoiler: siege log (click to show/hide)




EDIT: Why is the random seed saved with the game? I noticed it after I kept reloading. (I added an incredibly useful debug define to disable saving.) Everything always happened the same. It was like Groundhog Day.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on September 28, 2012, 12:11:19 am
EDIT: Why is the random seed saved with the game? I noticed it after I kept reloading. (I added an incredibly useful debug define to disable saving.) Everything always happened the same. It was like Groundhog Day.

That's often done in strategy games, since it discourages reloading for superior random outcomes. Civilization V, for example, saves the RNG seed unless you go into your new game options and specifically check the box to disable that.

Being able to load a save game and repeat the same steps to get the same outcome is also handy for reproducing bugs.
Title: Re: LCS Programming Discussion Topic
Post by: Dagun on September 28, 2012, 08:13:31 am
Hi gents, programming related query for you.

The main thread seems to indicate that i need VC++2010, but VC++2010 doesn't seem to recognize the project solution and instead thinks it's from an older VC++ and thus wants to convert it. However converting it breaks a great deal of configuration to the extent where it becomes unusable. Just to check do i indeed need VC++2010 and not an older version? Also is the SVN link in the main thread still correct, perhaps i'm checking out the wrong SVN?

Also since express 2012 came out, your VC++2010 link no longer works, not sure if you noticed.
Title: Re: LCS Programming Discussion Topic
Post by: dreadmullet on September 28, 2012, 08:45:28 am
Hi gents, programming related query for you.

The main thread seems to indicate that i need VC++2010, but VC++2010 doesn't seem to recognize the project solution and instead thinks it's from an older VC++ and thus wants to convert it. However converting it breaks a great deal of configuration to the extent where it becomes unusable. Just to check do i indeed need VC++2010 and not an older version? Also is the SVN link in the main thread still correct, perhaps i'm checking out the wrong SVN?

Also since express 2012 came out, your VC++2010 link no longer works, not sure if you noticed.

I use VC++ 2010 and it works fine for me. I had to convert it, as you did, and it did break some stuff. I managed to work around it by fiddling with the project settings.

Hmm... I doubt that many people still use VC++ 6 or whatever the .sln version is in trunk. Would it be a good idea to add a 2010 solution file but keep the old one as default? People could just rename the two files and use the 2010 .sln.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on September 28, 2012, 11:22:32 am
Hi gents, programming related query for you.

The main thread seems to indicate that i need VC++2010, but VC++2010 doesn't seem to recognize the project solution and instead thinks it's from an older VC++ and thus wants to convert it. However converting it breaks a great deal of configuration to the extent where it becomes unusable. Just to check do i indeed need VC++2010 and not an older version? Also is the SVN link in the main thread still correct, perhaps i'm checking out the wrong SVN?

Also since express 2012 came out, your VC++2010 link no longer works, not sure if you noticed.

I use VC++ 2010 and it works fine for me. I had to convert it, as you did, and it did break some stuff. I managed to work around it by fiddling with the project settings.

Hmm... I doubt that many people still use VC++ 6 or whatever the .sln version is in trunk. Would it be a good idea to add a 2010 solution file but keep the old one as default? People could just rename the two files and use the 2010 .sln.

Are you calling my IDE old and busted? You people wound me! And after I upgraded to Visual Studio 2008 and everything... :P

I suppose that I should at least upgrade to 2010. If 2012 express is out, is there a good reason to not just use that? I guess there's probably still a lot of people running XP and Vista.
Title: Re: LCS Programming Discussion Topic
Post by: Dagun on September 29, 2012, 04:58:15 am
-snip for tidyness-

Are you calling my IDE old and busted? You people wound me! And after I upgraded to Visual Studio 2008 and everything... :P

I suppose that I should at least upgrade to 2010. If 2012 express is out, is there a good reason to not just use that? I guess there's probably still a lot of people running XP and Vista.

Aside from the 40 minute install time and no compatibility for XP + vista, nope. Source on compatibility. (http://www.microsoft.com/visualstudio/eng/products/compatibility) I also don't believe you can install individual visual studio parts now, and instead have to download the whole studio. (Or at least i did, i downloaded the VC++2012 and it plugged it in with basic and another. >:( )

Not trying to force you into a decision or anything, but xp + vista still appears to make up ~50% of net users, so you might be cutting off a lot of potential people.  :( (Source. (http://netmarketshare.com/operating-system-market-share.aspx?qprid=10&qpcustomd=0) Not sure how much faith you want to put into the source, but it's up to date and seems plausible.)
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on September 29, 2012, 04:15:12 pm
My question was partially rhetorical; I agree that the XP/Vista compatibility issue (which I pointed out in the next sentence) is enough to kill the prospect.

I realize it might be seen as a disadvantage if you know you want to use only one language, and want to limit the amount of hard drive space used, but installing Visual Studio parts separately was a drawback of earlier Express versions rather than a feature. Even aside from the inconvenience of installing multiple copies of the same IDE to support different languages, Express crippled the ability of users to handle larger projects that incorporated multiple languages in the same program.
Title: Re: LCS Programming Discussion Topic
Post by: Vherid on October 02, 2012, 08:25:32 am
I had some interesting ideas that I was going to code myself or at least try to in my LCS mod, I'm gonna have to dig around and see if I can remember what I was going to do. I am interested in trying to get back into it again, I'd prefer to not be super rusty in programming again even though I learned java.
Title: Re: LCS Programming Discussion Topic
Post by: dreadmullet on October 03, 2012, 07:07:17 pm
I've been working on organizing the fight logs. If I just used gamelog.nextMessage() after every message, it would be really disorganized. I decided to make it so that it makes a blank line between rounds.

Spoiler: example fight log (click to show/hide)
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on October 03, 2012, 07:47:55 pm
I've been working on organizing the fight logs. If I just used gamelog.nextMessage() after every message, it would be really disorganized. I decided to make it so that it makes a blank line between rounds.

Spoiler: example fight log (click to show/hide)

That looks fantastic.
Title: Re: LCS Programming Discussion Topic
Post by: dreadmullet on October 03, 2012, 07:53:07 pm
(Edit moved to new post) The purpose of nextMessage() was to leave an arbitrary amount of blank lines, right? It seems I'm bypassing that function by mostly calling newline(). But I would argue that any more than 2 blank lines is absurd.


That looks fantastic.

Thanks!
Title: Re: LCS Programming Discussion Topic
Post by: dreadmullet on October 04, 2012, 02:05:08 am
I finally got around to pushing my huge revision I've been holding off. Hopefully I didn't break anything too much.

Spoiler: changelog (click to show/hide)


Note to self: there's a log message for when you leave a site, but not when you enter a site. (I think because it's in a different file that hasn't had logging added to, yet.)
Title: Re: LCS Programming Discussion Topic
Post by: addictgamer on October 04, 2012, 03:20:11 am
Note to self: there's a log message for when you leave a site, but not when you enter a site. (I think because it's in a different file that hasn't had logging added to, yet.)

It is in a different file, if I recall correctly. I think in daily/activities.cpp
I haven't had too much time to work on that file. Been plenty busy with college this last week <.< But I'll finish it...eventually...
Title: Re: LCS Programming Discussion Topic
Post by: KA101 on January 14, 2013, 08:28:51 pm
Necroing to figure out the problem with metal-detector checkpoints: having a sleeper on-site doesn't let the squad bypass the detection, and may even obstruct the Disguise check for uniform-conforming weapons.  Quoting from the map-mod thread where I originally mentioned the problem:
Update: -BEEEP-  -BEEEP-  -BEEEP-

Unfortunately the Conservative metal detector insists on alarming no matter the situation: my test-character couldn't take his .44 Magnum (IIRC that's acceptable for security or police) through the front door of the nuke plant even in a Security, Police, or even Death Squad Uniform.  Death Squads are active at the moment.  Not sure if my having a Lab Tech sleeper on-site derails the disguise-check, but I'm thinking that might be the culprit.  It does cancel mentioning that the squad actually goes through the detector, which they might or might not depending on the site/badges.

This sounds weird. The intended behavior when you have a sleeper is that you flash badges and get waved in. If you see the badge flashing text, there shouldn't be any way you'd get the metal detector going off -- the same trigger that shows that text should also prevent the game from checking for weapons at all.

First test I can think of is to send the guy through with some other disqualifying issue (no weapon), such as no Disguise or perhaps sending in someone without the skill.  Guessing that either the ", metaldetect" in the weapons-check line somehow bypasses the "!autoadmit", or maybe the second-visit call under autoadmit somehow doesn't clear the metaldetect.

That said, I'm no cpp coder so I could well be completely mistaken, too.

Edit on reviewing the thread: For the record, I use WinXP and will be installing Win2k (!) on the old tower once I get it a working primary drive.  Old-stuff compatibility is good.

Further edit, after taking another look at mapspecials.cpp: when a bouncer-checkpoint autoadmits, it also selfdestructs so far as I can tell; the remaining Club Security sticks around but you can walk around the front door all you like.  When a security checkpoint autoadmits, it changes to a "secondvisit" encounter, which doesn't have a value for metal-detecting or not.  Is it possible that the second-visit somehow doesn't carry over the autoadmit, but does carry over the detector?
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on January 16, 2013, 04:37:44 pm
Further edit, after taking another look at mapspecials.cpp: when a bouncer-checkpoint autoadmits, it also selfdestructs so far as I can tell; the remaining Club Security sticks around but you can walk around the front door all you like.  When a security checkpoint autoadmits, it changes to a "secondvisit" encounter, which doesn't have a value for metal-detecting or not.  Is it possible that the second-visit somehow doesn't carry over the autoadmit, but does carry over the detector?

The "secondvisit" encounter just spawns a couple of security guards, they shouldn't frisk you or send you through the metal detector. Should be the same as the bouncer.
Title: AA-Gun is but a bomb-magnet.
Post by: Pesi on January 16, 2013, 11:02:13 pm
Since we're talking programming here, what's the deal with the AA-gun? As far as I can tell...

"You hear planes streak overhead!"
"The thunder of anti-aircraft fire drives them back!"
"The anti-aircraft gun takes a direct hit!"
"Nothing left but smoking wreckage..."


...all it does is keep the generator from being destroyed for one day (or however many it takes the military to launch another plane), it doesn't actually keep them from bombing the compound.
Title: Re: LCS Programming Discussion Topic
Post by: Neonivek on January 16, 2013, 11:25:25 pm
It is almost like holding out against the United states military is impossible or something when you are outmanned, outclassed, and outgunned.
Title: Re: LCS Programming Discussion Topic
Post by: KA101 on January 17, 2013, 07:06:27 pm
Further edit, after taking another look at mapspecials.cpp: when a bouncer-checkpoint autoadmits, it also selfdestructs so far as I can tell; the remaining Club Security sticks around but you can walk around the front door all you like.  When a security checkpoint autoadmits, it changes to a "secondvisit" encounter, which doesn't have a value for metal-detecting or not.  Is it possible that the second-visit somehow doesn't carry over the autoadmit, but does carry over the detector?

The "secondvisit" encounter just spawns a couple of security guards, they shouldn't frisk you or send you through the metal detector. Should be the same as the bouncer.

OK, fair enough.  Hypothesizing based on the trunk-code, and from what I've seen so far.  Will probably experiment again over the weekend.

Experiment conducted: My tester (10 Charisma, 9 Disguise, Lab Coat, no weapon equipped) repeatedly tried to pass the metal-detector checkpoint, which had a locked door in front of it if picking the door matters.  Leaky Beaker the Lab Tech sleeper routinely met him there and helped him flash an ID badge.  Equally routinely, the metal detector (staffed by Elite Security, if that matters) sounded, the site Alarmed, and the door ahead went red/nonpickable.  After Bluffing the remaining guard, the checkpoint indeed completely disappeared and the tester could walk around those two squares as much as he liked without encountering another checkpoint.

Assessment: Autoadmit is firing but not bypassing the detector.  Detector seems to trigger on something other than the presence of a weapon (does Martial Arts skill count??).  Secondvisit isn't actually doing anything--the detector-checkpoint is, in fact, self-destructing as per bouncers.

Fox, I'm sorry for the suboptimal report :( but something's munged here and I'm willing to say that the 4.06.3 metal-detector is not ready for prime time.  Got the screencaps to prove it if you tell me how you want them. (I use NoScript so if there's a button in the message-composer interface, I don't know about it).  Let me know if you'd like me to run it without sleepers or have any other experimental requests.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on January 21, 2013, 08:10:06 pm
Well, I've looked at the code for the metal detector, and nothing has jumped out at me as possibly allowing that behavior, so it's probably either something obvious that I'm blindly missing, or something really subtle. I just can't think of a logical explanation for why the metal detector would go off on an unarmed person after they get auto-admitted by a sleeper; the obvious typos that came to mind for me aren't present. What I really need to do is reproduce the behavior in a debugger and step through the code line by line to figure out why it's happening. Right now I'm chest-deep in working on a game based on LCS though, so I'm not in a good brainspace to really do serious debugging on LCS. I don't have a conclusion when I'll get to tracking that bug down, but it's something I'd like to have working rather than broken.
Title: Re: LCS Programming Discussion Topic
Post by: KA101 on January 22, 2013, 12:02:47 am
Well, if it's related to LCS and not flash-based/free-to-play, you could probably persuade me to give it a shot when you're done.  Thanks for the heads-up; I'll ease back on this for now.
Title: Re: LCS Programming Discussion Topic
Post by: addictgamer on January 24, 2013, 10:28:29 pm
Alright, I've finally finished adding logging to everything (mostly -- there are some places that I wasn't sure if that thing should be logged). Sorry that I didn't finish it back in October; The second half of the semester thought it was a good idea to brutally murder all my time until Christmas. I blame video games for further delaying the update until today.

Anyway, I played a dozen or so game sessions with logging but I was not able to fully playtest everything (of course). So if there are any problems, please yell at me. Hopefully I didn't break anything. The game seemed to be functioning normally in all my playtests.

Again, sorry for the huge delay. I blame school, video games, and the sheer amount of time needed to playtest this update.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on January 24, 2013, 10:55:13 pm
Awesome! Just built and tried the game with those changes!

My gamelog.txt:

Code: [Select]


---------- PROGRAM STARTED ----------


A NEW CONSERVATIVE ERA
The Year is 2009.
Conservative President Paul Florez ends his second term with approval
ratings in the high 70s, and is succeeded by hardcore Arch-Conservative
Chris Warman.

With Conservatives sweeping into power in the House of Representatives
and Senate, and a Conservative majority in the Supreme Court of the
United States, commentators are hailing it as the beginning of a new
Conservative era.

President Chris Warman has asked the new Congress to move quickly
to rubber stamp his radical Arch-Conservative agenda. The left seems
powerless to stop this imminent trampling of Liberal Sanity and Justice.

In this dark time, the Liberal Crime Squad is born...

The Liberal Crime Squad has arrived at American Bank Corp.

Tricia Kindale says, "Do you want to hear something disturbing?"
Prostitute responds, "What?"
Tricia Kindale says, "Over thirty innocent people have been executed over the past decade."
Prostitute responds, "Dear me! Is there anything we can do?"
After more discussion, Prostitute agrees to come by later tonight.


A bank teller is available.
Tricia Kindale slips the teller a note: I HAVE A GUN. CASH PLEASE.
The bank teller reads the note, nods calmly, and slips several bricks of cash into the squad's bag.


The Liberal Crime Squad has left American Bank Corp.


Meeting with Erika Birkin, Prostitute
Tricia Kindale explains their views on torture.
Tricia Kindale comes off as slightly insane.
This whole thing was a mistake. There won't be another meeting.

The Liberal Crime Squad has arrived at The Oubliette.

The Liberal Crime Squad has arrived at Fire Station.

Tricia Kindale says, "Do you want to hear something disturbing?"
Firefighter responds, "No." <turns away>


You try the door, but it is locked.
Tricia Kindale unlocks the door!


You try the door, but it is locked.
Tricia Kindale unlocks the door!


You find: Kitschy Trinket


You try the door, but it is locked.
Tricia Kindale unlocks the door!


Tricia Kindale acts natural.


The Liberal Crime Squad has left Fire Station.


The Liberal Crime Squad has arrived at Stevenson's Department Store.

The Liberal Crime Squad has arrived at Police Station.

You try the door, but it is locked.
Tricia Kindale unlocks the door!


You find: PDA


You find: Laptop


You find: Cellphone


Police Officer sees the Squad's Liberal Weapons and lets forth a piercing Conservative alarm cry!


You try the door, but it is locked.
Tricia Kindale shoots at Police Gang Unit with a AR-15!
Tricia Kindale hits the left leg.
Police Officer shoots at Tricia Kindale with a Shotgun!
Police Officer hits the right leg.
Police Gang Unit shoots at Tricia Kindale with a MP5 SMG!
Police Gang Unit hits the left leg, striking three times.
Police Officer shoots at Tricia Kindale with a 9mm Semiauto!
Police Officer hits the body.
Tricia Kindale gasps a last breath and soils the floor.
Nobody can carry Martyr Tricia Kindale.



Title: Re: LCS Programming Discussion Topic
Post by: addictgamer on January 24, 2013, 11:32:23 pm
Excellent. I'm happy the code works for other people too.
Title: Re: LCS Programming Discussion Topic
Post by: Vherid on January 25, 2013, 01:18:13 am
That certainly sounds pretty nifty
Title: Re: LCS Programming Discussion Topic
Post by: KA101 on January 25, 2013, 07:24:39 pm
Dammit, that's another reason for me to try/fail at compiling something, if there's a free compiler for Win2k/XP.  ;)  Logging squad activity will make for interesting reading and hopefully help counter the Now Where Was I Going Again that comes from only playing on free nights.

Thanks, addictgamer.
Title: Re: LCS Programming Discussion Topic
Post by: Vherid on February 16, 2013, 12:47:09 am
So looking at lawreference.cpp, as you can see it actually goes to C++ and whatever S(Soviet?) is, can the game actually utilize these? Or are these about as useful as a comment?
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on February 16, 2013, 04:47:13 pm
So looking at lawreference.cpp, as you can see it actually goes to C++ and whatever S(Soviet?) is, can the game actually utilize these? Or are these about as useful as a comment?

C++ is used when showing laws on the Game Over screen, S is Soviet and isn't used by the game. Servant Corps did most of the work on those, if I'm not mistaken.
Title: Re: LCS Programming Discussion Topic
Post by: usr_share on February 17, 2013, 03:21:04 am
S seems to actually mean "Stalinist", but yeah -- it looks like some developers had an idea of adding an extra degree to the issue spectrum.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on February 17, 2013, 07:43:35 am
S seems to actually mean "Stalinist", but yeah -- it looks like some developers had an idea of adding an extra degree to the issue spectrum.

Ah, yeah, that's right.
Title: Re: LCS Programming Discussion Topic
Post by: Vherid on February 17, 2013, 03:28:43 pm
EDIT: Fixed it
Title: Re: LCS Programming Discussion Topic
Post by: Servant Corps on February 17, 2013, 11:15:08 pm
So looking at lawreference.cpp, as you can see it actually goes to C++ and whatever S(Soviet?) is, can the game actually utilize these? Or are these about as useful as a comment?

C++ is used when showing laws on the Game Over screen, S is Soviet and isn't used by the game. Servant Corps did most of the work on those, if I'm not mistaken.
The idea was that you would have a special Game-Over screen if the Stalinists "win" the game by passing their Stalinist Amendment. It would not show up in normal play though, as the Stalinists generally adhere to a mixed platform of L+ and C+ ideas. The Stalinists was intended to be a sometimes-ally, sometimes-enemy of the LCS, and the player has to decide when to let them run free and when to crack down.

At least that was the idea. I'm not sure if it actually worked though.
Title: Re: LCS Programming Discussion Topic
Post by: Lenny Zicree on February 20, 2013, 01:17:41 am
here's my top 3 list of annoyances:

talk/say what to who  ..  please, having it the other way around is driving me mad.
sieges kill my squad assignments  ..  ouch! please, if i have at least 1 6 person squad don't try to help me!
{Esc}{Esc}R1AA ... wtf! why can't i assign something to someone who's not in a squad.

is it ok here? can someone with a dev setup please spend an hr on the last 2, or 2hrs on the 1st one? ty!
Title: Re: LCS Programming Discussion Topic
Post by: Dbuhos on March 02, 2013, 02:09:12 pm
What's some freeware software I could use to compile LCS?
Title: .
Post by: Yannanth on March 02, 2013, 02:52:56 pm
.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on March 03, 2013, 06:06:42 pm
LCS is normally compiled with GCC and GNU Make (both come preinstalled on most Linux distros), and on Windows with Visual Studio Express, which was freeware until 2 years ago. Now it's a stripped-down version of the full VC++ and you have to pay for it after the trial expires.

I think you might be conflating two different products. Visual Studio Express has always been a stripped down version, but this is the first I've heard of it being turned into a trial version rather than a forever free version. Wikipedia says Visual Studio Express is still freeware, Microsoft advertises the line as "entirely free" on their website, and all discussion on tech sites and forums seems consistent with it still being 100% free and not a trial product.

I think you may be confusing this with the fact that you can freely download other versions of Visual Studio, besides Express, which you then have to pay for after their trial elapses. Well, you have to pay for them if you want to keep using them. Obviously they can't make you pay for them.
Title: Re: LCS Programming Discussion Topic
Post by: Vherid on April 18, 2013, 10:20:21 am
So I still look at this crazy ideas list every now and then, and someone of them don't really require big changes, things I could really easily put together, are all of these ideas a to do list for you Fox, or are they just ideas good and bad altogether? I wouldn't mind doing a few of them really quickly, but I'm also unsure of how to SVN contribute and all of that. Would it to just edit the SVN marked files and then do the SVN Commit thing?
Title: Re: LCS Programming Discussion Topic
Post by: seth-- on April 18, 2013, 10:52:08 am
Did anyone got a warning of a CCS raid? I didn't had one but looking at the source it looks like it will never happen:
Code: [Select]
               int ccssleepercount=0;
               for(int pl=0;pl<pool.size();pl++)
               {
                  if(pool[pl]->flag & CREATUREFLAG_SLEEPER&&
                     (pool[pl]->type==CREATURE_CCS_VIGILANTE || pool[pl]->type==CREATURE_CCS_ARCHCONSERVATIVE ||
                      pool[pl]->type==CREATURE_CCS_MOLOTOV || pool[pl]->type==CREATURE_CCS_SNIPER))
                  {
                     ccssleepercount=1;
                     break;
                  }
               }
               if(ccssleepercount>1) // !! It will be 1 or 0, never >1
               {                               // It should be if(ccssleepercount)
                  erase();
                  set_color(COLOR_WHITE,COLOR_BLACK,1);
                  move(8,1);
                  addstr("You have received a sleeper warning that the CCS ", gamelog);
                  move(9,1);
                  addstr(" is gearing up to attack ", gamelog);
                  addstr(location[l]->name, gamelog);
                  addstr(".", gamelog);
                  gamelog.nextMessage();

                  refresh();
                  getch();
               }
            }
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on April 18, 2013, 08:12:47 pm
So I still look at this crazy ideas list every now and then, and someone of them don't really require big changes, things I could really easily put together, are all of these ideas a to do list for you Fox, or are they just ideas good and bad altogether? I wouldn't mind doing a few of them really quickly, but I'm also unsure of how to SVN contribute and all of that. Would it to just edit the SVN marked files and then do the SVN Commit thing?

They aren't necessarily vetted as good ideas (they could just be crazy ones), but if you think they're good, feel free to do them.

You can SVN commit if you are a member of the Sourceforge project. If you aren't a member and would like to join, send me a PM with your Sourceforge username (registration is free if you don't have one yet) and maybe a statement about your programming experience, or mention a useful source code edit you've already done and tested on your computer. I'll add you to the project and write back confirming it's done, then you can use your Sourceforge username and password when committing.

You are also welcome to join the project, seth--; I've committed a couple of patches on your behalf already, and they have been quite good. You are certainly welcome to just commit directly and bypass me. (And I agree with your observation, that code is broken. Your fix would work.)
Title: Re: LCS Programming Discussion Topic
Post by: seth-- on April 18, 2013, 09:36:46 pm
Have you thought of migrating to github?
It's interface is nicer than sourceforge.
Pull requests would make it easier to review and keep track of patches.
The issue tracker would make it impossible to forget about bugs or suggestions.
A project there usually attracts more developers than a project in sf.

I don't remember that much about svn but I'm making a sf account anyway.

edit: best of all, gh allows hypens in usernames
Title: Re: LCS Programming Discussion Topic
Post by: dreadmullet on April 18, 2013, 10:23:13 pm
Popping in here to give my support to git and github. I always hear that git is very hard to get used to, but if you use a GUI tool it's much easier (tortoisegit makes things very easy indeed).

There's been a lot of awesome work done by people trying to help development recently. I would get back into it, but I've got other things going on at the moment. But mostly, the source code scares me. So many global variables...
Title: Re: LCS Programming Discussion Topic
Post by: KA101 on April 18, 2013, 10:38:25 pm
I just joined github to hopefully resolve a problem over with CataDDA.  Not intuitive for this non-coder, even with the windows shell.  Haven't tried sourceforge though.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on April 19, 2013, 02:47:42 pm
Open question: Would it be productive to, like, regex the whole code base to convert the existing 3 space tabs into a more normal 4 space convention? I know 3 space tabs are really... uncommon.
Title: Re: LCS Programming Discussion Topic
Post by: seth-- on April 19, 2013, 02:55:02 pm
If it uses 3 spaces consistently, I dont think its necessary
Title: Re: LCS Programming Discussion Topic
Post by: ed boy on April 20, 2013, 07:05:21 am
If it uses 3 spaces consistently, I dont think its necessary
When I was making my mod, I mixed 3 and 4 space tabs, and there were no issues.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on April 20, 2013, 12:42:50 pm
If it uses 3 spaces consistently, I dont think its necessary
When I was making my mod, I mixed 3 and 4 space tabs, and there were no issues.

C++ doesn't care about whitespace, so there wouldn't be. But that isn't the purpose of keeping the tabs consistent. It's very difficult for other programmers to understand what they're looking at if you vary from the conventions, because the whole point of indenting in the first place is to ensure the visual structure of the code matches the logical structure of the code. When you change the manner in which you indent, the code becomes more difficult to comprehend. And code is arcane enough without making fellow coders tax their brains on reverse engineering the parts you wrote. Keeping tabs consistent is one of the universal rules if you work in a professional environment.
Title: Re: LCS Programming Discussion Topic
Post by: seth-- on April 22, 2013, 01:03:23 pm
If it uses 3 spaces consistently, I dont think its necessary
When I was making my mod, I mixed 3 and 4 space tabs, and there were no issues.

C++ doesn't care about whitespace, so there wouldn't be. But that isn't the purpose of keeping the tabs consistent. It's very difficult for other programmers to understand what they're looking at if you vary from the conventions, because the whole point of indenting in the first place is to ensure the visual structure of the code matches the logical structure of the code. When you change the manner in which you indent, the code becomes more difficult to comprehend. And code is arcane enough without making fellow coders tax their brains on reverse engineering the parts you wrote. Keeping tabs consistent is one of the universal rules if you work in a professional environment.
If you change the indentation, please also remove the spaces at the end of the lines and leave one (only one) line break at the end of the files.


Edit:
I just joined github to hopefully resolve a problem over with CataDDA.  Not intuitive for this non-coder, even with the windows shell.  Haven't tried sourceforge though.
Just made my first commit to sourceforge and it took hours. Git isn't easy to get either but I don't think it's harder.

edit2:
Code: [Select]
make  all-recursive
make[1]: Entering directory `/media/data/programming/cpp/lcsgame'
Making all in src
make[2]: Entering directory `/media/data/programming/cpp/lcsgame/src'
g++ -DHAVE_CONFIG_H -I. -I..  -DINSTALL_DATA_DIR=\"/usr/local/share\"  -I../src -g -O2 -MT crimesquad-game.o -MD -MP -MF .deps/crimesquad-game.Tpo -c -o crimesquad-game.o `test -f 'game.cpp' || echo './'`game.cpp
In file included from game.cpp:73:0:
includes.h:889:10: error: extra qualification ‘Location::’ on member ‘getname’ [-fpermissive]
    char* Location::getname(bool shortname=false);
          ^
make[2]: *** [crimesquad-game.o] Error 1
make[2]: Leaving directory `/media/data/programming/cpp/lcsgame/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/media/data/programming/cpp/lcsgame'
make: *** [all] Error 2

r644 broke it, r643 dies with something else:
Code: [Select]
terminate called after throwing an instance of 'std::bad_alloc'
                                                                 what():  std::bad_alloc
                                                                                        Aborted (core dumped)
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on April 23, 2013, 11:09:07 am
Code: [Select]
make  all-recursive
make[1]: Entering directory `/media/data/programming/cpp/lcsgame'
Making all in src
make[2]: Entering directory `/media/data/programming/cpp/lcsgame/src'
g++ -DHAVE_CONFIG_H -I. -I..  -DINSTALL_DATA_DIR=\"/usr/local/share\"  -I../src -g -O2 -MT crimesquad-game.o -MD -MP -MF .deps/crimesquad-game.Tpo -c -o crimesquad-game.o `test -f 'game.cpp' || echo './'`game.cpp
In file included from game.cpp:73:0:
includes.h:889:10: error: extra qualification ‘Location::’ on member ‘getname’ [-fpermissive]
    char* Location::getname(bool shortname=false);
          ^
make[2]: *** [crimesquad-game.o] Error 1
make[2]: Leaving directory `/media/data/programming/cpp/lcsgame/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/media/data/programming/cpp/lcsgame'
make: *** [all] Error 2

r644 broke it, r643 dies with something else:
Code: [Select]
terminate called after throwing an instance of 'std::bad_alloc'
                                                                 what():  std::bad_alloc
                                                                                        Aborted (core dumped)

The first issue should be dealt with now. I'm mildly surprised that it wasn't even warned about by the Visual Studio project. (I would be more than mildly surprised if the project weren't set to be pretty permissive with code quality.) The second is occurring because r643 broke save compatibility and it's trying and failing to load your existing save game -- you will need to manually delete the old save file.
Title: Re: LCS Programming Discussion Topic
Post by: seth-- on April 24, 2013, 02:11:44 pm
I rewrote the loadinitfile function
It now uses LCSOpenFileCPP to open the init.txt file, searching for it in ~/.lcs/ like it's done with gamelog.txt and save.dat
I want to include a default init.txt but I have now idea of how to do make the installer copy it.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on April 24, 2013, 02:59:36 pm
I rewrote the loadinitfile function
It now uses LCSOpenFileCPP to open the init.txt file, searching for it in ~/.lcs/ like it's done with gamelog.txt and save.dat
I want to include a default init.txt but I have now idea of how to do make the installer copy it.

The makefile.am in /trunk/ (not the identically named file in /trunk/src/) enumerates all the files that should be moved to the art directory in the install. Figuring out how it does that should lead you to a way to copy init.txt to the save directory in the install process.
Title: Re: LCS Programming Discussion Topic
Post by: seth-- on April 24, 2013, 04:56:24 pm
Where are gamelog.txt and save.dat created in windows? src/?
As there is no makefile there I should put init.txt in the same folder, right? It feels weird, as it's not source code

Edit: I've commited the code but still I'm not sure how to do the file thing. Here is a init.txt for those wanting to test:
Code: [Select]
#Leave this to use [ and ]
pagekeys=brackets

#Uncomment to use . and /
#pagekeys=AZERTY

#Uncomment to use PGUP and PGDOWN
#pagekeys=page
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on April 25, 2013, 04:00:30 pm
Where are gamelog.txt and save.dat created in windows? src/?
As there is no makefile there I should put init.txt in the same folder, right? It feels weird, as it's not source code

Edit: I've commited the code but still I'm not sure how to do the file thing. Here is a init.txt for those wanting to test:
Code: [Select]
#Leave this to use [ and ]
pagekeys=brackets

#Uncomment to use . and /
#pagekeys=AZERTY

#Uncomment to use PGUP and PGDOWN
#pagekeys=page

init.txt is not created by the game in Windows. It comes in the game's zip file and lives in the top directory (same as the .exe). I'm a bit surprised, but it doesn't look like it's in the SVN repository.

Here's the init.txt packed with the game's Windows download:

Code: [Select]
#####################################################################
#####################################################################
##                                                                 ##
##           Configuration File for Liberal Crime Squad            ##
##                                                                 ##
#####################################################################
#####################################################################

#####################################################################
##                        Interface Options                        ##
#####################################################################

Change "brackets" to "page" to use pgup/pgdn to scroll in menus.
You might have to try both or fiddle with numloc and the pgup/pgdn
on your number pad to find a combination that works.

Alternatively, replace the word after pagekeys with "AZERTY" to use
the ; and : keys to scroll in menus, specifically designed for the
AZERTY keyboard layout. Note that setting AZERTY here causes the
game to do a number of additional conversions to make the keyboard
input easier, ignoring the effect of capslock on the number keys
(allowing & é " etc to be used in place of their corresponding
numbers) and making '.' and '/' interchangable with ';' and ':'.


pagekeys = brackets

This is a really peripheral file that is irrelevant to most players, which is probably why nobody's ever noticed or mentioned the fact that it doesn't come with the Linux version until now. The file was originally created to let you toggle to the brackets setting if the pageup/pagedown options don't work, but they don't work for so many people that I changed the default and never looked back. The newer AZERTY setting is probably the only really useful feature these days -- its handful of features should make the interface a notably less hostile for anyone playing on a French keyboard.
Title: Re: LCS Programming Discussion Topic
Post by: seth-- on April 25, 2013, 04:07:27 pm
My idea is to allow disabling the autosave from this file, as requested here (http://www.bay12forums.com/smf/index.php?topic=115686.msg4183106#msg4183106) but the code sucked so I rewrote it
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on April 25, 2013, 04:25:04 pm
My idea is to allow disabling the autosave from this file, as requested here (http://www.bay12forums.com/smf/index.php?topic=115686.msg4183106#msg4183106) but the code sucked so I rewrote it

That sounds like a good idea to me.
Title: Re: LCS Programming Discussion Topic
Post by: seth-- on April 27, 2013, 10:34:17 pm
I had to read the K&R book to finally understand variable scope in c++ but autosave can be disabled now

Still init.txt isn't copied by make. If somebody knows how to do it, please contribute. If not, it's time to read the automake documentation.
Title: Re: LCS Programming Discussion Topic
Post by: Jonathan S. Fox on April 28, 2013, 05:18:19 am
Visual Studio people: Do you use an earlier version of Visual Studio than 2010? I'm planning on updating the visual studio project file on SVN to 2010, but I don't want to break backwards compatibility if there are several people relying on the existing 2008 format.
Title: Re: LCS Programming Discussion Topic
Post by: Funk on April 28, 2013, 05:39:59 pm
im using 2010.
Title: Re: LCS Programming Discussion Topic
Post by: Vherid on April 28, 2013, 06:30:28 pm
2012