Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: First post : Code analysis  (Read 1197 times)

Pesi

  • Bay Watcher
    • View Profile
First post : Code analysis
« on: November 09, 2011, 12:17:27 pm »

My first post. Hello. :D

On to business.

This is what determines if the hacker group gets caught for a minor hack:
Code: [Select]
if(DIFFICULTY_FORMIDABLE<hack_skill+LCSrandom(5)-2)
DIFFICULTY_FORMIDABLE = 13

I can't help thinking that the "<" is supposed to be ">".
The similar one for a major hack has the ">".
As it is, it rewards being bad with the absence of heat. A group of 8 or 9 liberals, all with intelligence 3 or less, could hack to their HRT's content and #1:Always succeed (still being bad enough to not go "up the ladder" to doing major hacks) and #2: Never get caught (because their numbers don't contribute to that part).
Logged

klingon13524

  • Bay Watcher
  • The Mongols are cool!
    • View Profile
Re: First post : Code analysis
« Reply #1 on: November 09, 2011, 04:01:30 pm »

1. Welcome to the Bay12 community! You should really check out our other forums, this is the best online community I've ever found.

2. I don't know anything about code, so I can't help you there.
Logged
By creating a gobstopper that never loses its flavor he broke thermodynamics
Maybe it's parasitic. It never loses its flavor because you eventually die from having your nutrients stolen by it.

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: First post : Code analysis
« Reply #2 on: November 09, 2011, 05:37:40 pm »

Yeah, it looks like this is bugged. Someone should fix this.

(Not me, it's my birthday. I don't have to work on LCS bug fixes.) ;)
Logged

Pesi

  • Bay Watcher
    • View Profile
Re: First post : Code analysis
« Reply #3 on: November 10, 2011, 10:20:35 am »

Jonathan S. Fox, may your birthday have been awesome.

Another "OBJECTION!" I have is with the part on graffiti, where it decides which issue to do a mural on. (activities.cpp)
Code: [Select]
issue=randomissue();This means that sometimes they make a mural about the CCS when they have either been defeated or never existed at all.

Fortunately, this should be easy to correct by checking for defeat [endgamestate>=ENDGAME_CCS_DEFEATED] in which case do [issue=LCSrandom(VIEWNUM-1);] instead. (good thing the CCS is the last issue, eh?)
Logged

klingon13524

  • Bay Watcher
  • The Mongols are cool!
    • View Profile
Re: First post : Code analysis
« Reply #4 on: November 10, 2011, 10:31:10 am »

Jefeated or never existed at all.
if they were defeated, of course they'd want to brag about it. If they never existed, it would be a prophetic work.
Logged
By creating a gobstopper that never loses its flavor he broke thermodynamics
Maybe it's parasitic. It never loses its flavor because you eventually die from having your nutrients stolen by it.

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: First post : Code analysis
« Reply #5 on: November 10, 2011, 12:08:14 pm »

Changes like that should be applied in the randomissue() function itself rather than going around it on a case-by-case basis -- that way, you not only fix any other calls to the central function, you can also preserve any special behavior that randomissue() provides. In this case, it actually weights the issues it returns based on what has recently been in the news. So if you raid the nuclear plant frequently, you're much more likely to see murals about nuclear power.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: First post : Code analysis
« Reply #6 on: November 10, 2011, 02:38:40 pm »

I'll steal that fix from the first post in my LCS Gen mod and mention you if you don't mind :). If you spot something else like that, please tell us.
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Pesi

  • Bay Watcher
    • View Profile
Re: First post : Code analysis
« Reply #7 on: November 10, 2011, 06:49:21 pm »

My mistake for assuming that the function was a basic dicethrower. Here's my suggested change:
Code: [Select]
int randomissue(bool core_only)
{
   int interest_array[VIEWNUM];
   int i;
   int total_interest=0;
   int CCSisDead = 0;
   if(!core_only && endgamestate>=ENDGAME_CCS_DEFEATED){CCSisDead = 1;}
   for(i=0;i<VIEWNUM-(core_only*5)-CCSisDead;i++)
   {
      interest_array[i]=public_interest[i]+total_interest+25;
      total_interest+=public_interest[i]+25;
   }
   int roll = LCSrandom(total_interest);
   for(i=0;i<VIEWNUM-(core_only*5)-CCSisDead;i++)
   {
      if(roll<interest_array[i])
         return i;
   }
   return -1;
}

"Something else like that" might be this from recruit.cpp:
Code: [Select]
if(pool[p]->skill_check(SKILL_PERSUASION,difficulty))
{
   success=1;
   set_color(COLOR_CYAN,COLOR_BLACK,1);
   r.level++;
   r.eagerness1++;
   move(y++,0);
   addstr(r.recruit->name);
   addstr(" found ");
   addstr(pool[p]->name);
   addstr("'s views to be insightful.");
   move(y++,0);
   addstr("They'll definitely meet again tomorrow.");
}
else if(pool[p]->skill_check(SKILL_PERSUASION,difficulty)) // Second chance to not fail horribly
{
   r.level++;
   r.eagerness1--;
   move(y++,0);
   addstr(r.recruit->name);
   addstr(" is skeptical about some of ");
   addstr(pool[p]->name);
   addstr("'s arguments.");
   move(y++,0);
   addstr("They'll meet again tomorrow.");
}
There's no overflow containment on "r.level" and "r.eagerness". A success at 127 brings it down to -128. I want to change it to
Code: [Select]
if(r.level<127){r.level++;}
if(r.eagerness<127){r.eagerness++;}
Logged

Pesi

  • Bay Watcher
    • View Profile
Re: First post : Code analysis
« Reply #8 on: November 12, 2011, 11:49:59 am »

Another thing I want to be sure I understand correctly, because this made me do a double-take (from siege.cpp):
Code: [Select]
// Cleanse record on things that aren't illegal right now
if(law[LAW_FLAGBURNING]>0)pool[p]->crimes_suspected[LAWFLAG_BURNFLAG]=0;
if(law[LAW_DRUGS]>0)pool[p]->crimes_suspected[LAWFLAG_BROWNIES]=0;
if(law[LAW_IMMIGRATION]==2)pool[p]->flag &= ~CREATUREFLAG_ILLEGALALIEN;
if(law[LAW_FREESPEECH]>-2)pool[p]->crimes_suspected[LAWFLAG_SPEECH]=0;

Now, when illegal aliens are arrested during L+ immigration laws, they may not be deported, but they also don't stop being illegal aliens.

The code here seems to eliminate their illegal-alien-ness permanently, so that should immigration laws later drop below L+ they still won't be deported.

This seems like a major inconsistency.
Logged

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: First post : Code analysis
« Reply #9 on: November 12, 2011, 04:35:15 pm »

I don't understand the first part of the inconsistency. If laws go to L+, not only will it cease to be illegal, they'll declare amnesty. Are you saying that the flag should also be cleared when they're arrested and it isn't currently?
Logged

Pesi

  • Bay Watcher
    • View Profile
Re: First post : Code analysis
« Reply #10 on: November 12, 2011, 05:04:30 pm »

Your reply caused me to check again, whereupon I found out that I had been a bit dumb. At first it looked like the above piece of code was a part of the siege-countdown that only happens when there's an imminent raid, but it actually happens every day.

So, yeah, they get permanent amnesty after the law changes.

...so they DO actually stop being illegal aliens.

 :-X
Logged

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: First post : Code analysis
« Reply #11 on: November 12, 2011, 05:10:20 pm »

Hahaha, that's funny, because I can hardly blame you for the confusion -- if I'm not mistaken, this is all in "siege.cpp". I've edited siege planning and heat management a LOT, and the logic flow in that file SILL confuses me half of the time I'm in there. It's a mess.
Logged

Pesi

  • Bay Watcher
    • View Profile
Re: First post : Code analysis
« Reply #12 on: November 13, 2011, 09:21:50 am »

OK, found another thing, and I'm pretty sure this one is actually something.
Code: [Select]
case CREATURE_COP:
   addstr(" is seized, ");
   if(law[LAW_POLICEBEHAVIOR]>=ALIGN_LIBERAL)
   {
      addstr("pushed to the ground, and handcuffed!");
   }
   else
   {
      if(activesquad->squad[p]->blood<10)
         addstr("thrown to the ground, and tazed to death!");
      else
         addstr("thrown to the ground, and tazed repeatedly!");
      activesquad->squad[p]->blood-=10;
   }
   break;

// SNIP

}
if(activesquad->squad[p]->blood<=0)
   activesquad->squad[p]->die();

If someone is at 10 blood they get tazed to death, but the message is that of mere repeated tazings.

"if(activesquad->squad[p]->blood<10)" should be "if(activesquad->squad[p]->blood<=10)" since 0 blood means death.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: First post : Code analysis
« Reply #13 on: November 13, 2011, 10:30:49 am »

This one is surely correct since 10-10 = 0 :).
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Pesi

  • Bay Watcher
    • View Profile
Re: First post : Code analysis
« Reply #14 on: November 13, 2011, 01:12:53 pm »

Then how about this? This is from fight.cpp, the part regarding conversion attacks.
Code: [Select]
else if(attack>resist)
{
   t.stunned+=(attack-resist)/4;
   if(a.enemy())
   {
      if(t.juice>=100)
      {
         move(17,1);
         addstr(t.name);
         addstr(" loses juice!");
         addjuice(t,-50,100);
      }
Code: [Select]
void addjuice(Creature &cr,long juice,long cap)
{
   // Ignore zero changes
   if(juice==0) return;

   // Check against cap
   if((juice>0 && cr.juice>=cap) ||
      (juice<0 && cr.juice<=cap))
   {
      return;
   }
If the person in question has 100 juice, they get told to lose juice... down to 100. the addjuice function exits without doing anything. The person may be stunned a lot, but they are also pretty much immune to conversion.
Logged