Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old July 14, 2016, 19:55   #51
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
Ok, I looked at De Morgan's laws and the table. I think I have a basic understanding of the concept now.

I like this one: !(a || b || c) best, it looks shorter.

There:

/* Detect all non-invisible, obvious monsters */
if (!rf_has(mon->race->flags, RF_INVISIBLE || mon->m_timed[MON_TMD_INVISIBLE]) ||
!mflag_has (mon->mflag, MFLAG_UNAWARE))
{
/* Hack -- Detect the monster */
mflag_on(mon->mflag, MFLAG_MARK);
mflag_on(mon->mflag, MFLAG_SHOW);

Elfin Jedi is offline   Reply With Quote
Old July 14, 2016, 20:20   #52
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,319
Donated: $40
Pete Mack is on a distinguished road
Cool. This kind of thing--messed up parens, negation, etc--is a very common error in beginning programming. However, the "invariant" as you have written it in your comment is misleading. It should say "detect all visible monsters that are in range". "obvious" monster is misleading. Even better, "exclude monsters that are invisible or out of range", which is the way you wrote the expression. The earlier statement describes the expression using (!a && !b && !c.)

Here is what is meant by invariant. It is a useful concept when thinking about conditional expressions.

https://en.wikipedia.org/wiki/Invari...puter_science)

edited for clarity

Last edited by Pete Mack; July 14, 2016 at 20:25.
Pete Mack is offline   Reply With Quote
Old July 14, 2016, 23:23   #53
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
I looked at the invariant page some, I'll have to study it more before I can get much use out of it, but in the meantime I've changed the comment for the "don't detect" check as well as 2 more invisibility checks:

effects.c:1365-1374

/* Only detect nearby monsters */
if (x < x1 || y < y1 || x > x2 || y > y2) continue;

/* Exclude monsters that are invisible or out of range */
if (!rf_has(mon->race->flags, RF_INVISIBLE || mon->m_timed[MON_TMD_INVISIBLE]) ||
!mflag_has (mon->mflag, MFLAG_UNAWARE))
{
/* Hack -- Detect the monster */
mflag_on(mon->mflag, MFLAG_MARK);
mflag_on(mon->mflag, MFLAG_SHOW);

And the other 2:

effects.c:1441-1444

/* Detect invisible monsters */
if (rf_has(mon->race->flags, RF_INVISIBLE) || mon->m_timed[MON_TMD_INVISIBLE] ) {
/* Take note that they are invisible */
rf_on(lore->flags, RF_INVISIBLE);

and:

mon-util.c:295-302

/* Handle "invisible" monsters */
if (rf_has(mon->race->flags, RF_INVISIBLE || mon->m_timed[MON_TMD_INVISIBLE]) ) {
/* See invisible */
if (player_of_has(player, OF_SEE_INVIS))
{
/* Easy to see */
easy = flag = TRUE;
}

Now when I turn on the debug options and summon a Memory moss it can say:

"The Memory moss disappears. The Memory moss is unaffected!",

"The Memory moss disappears. The Memory moss disappears!"

and:

"The Memory moss disappears.".

However, the Memory moss stays visible the whole time.

I'm also going to go back and edit the messages so that it has a different message for the action of casting the spell .
Elfin Jedi is offline   Reply With Quote
Old July 14, 2016, 23:30   #54
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,319
Donated: $40
Pete Mack is on a distinguished road
You need to mark the square with the memory moss for display update when an event like that happens.
Pete Mack is offline   Reply With Quote
Old July 15, 2016, 00:34   #55
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,827
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by Elfin Jedi View Post
Ok, I looked at De Morgan's laws and the table. I think I have a basic understanding of the concept now.

I like this one: !(a || b || c) best, it looks shorter.

There:

/* Detect all non-invisible, obvious monsters */
if (!rf_has(mon->race->flags, RF_INVISIBLE || mon->m_timed[MON_TMD_INVISIBLE]) ||
!mflag_has (mon->mflag, MFLAG_UNAWARE))
{
/* Hack -- Detect the monster */
mflag_on(mon->mflag, MFLAG_MARK);
mflag_on(mon->mflag, MFLAG_SHOW);

Be careful with where you put the ||s.

Code:
!rf_has(mon->race->flags, RF_INVISIBLE || mon->m_timed[MON_TMD_INVISIBLE])
is very different to

Code:
!rf_has(mon->race->flags, RF_INVISIBLE) || !mon->m_timed[MON_TMD_INVISIBLE]
The first one checks if the monster has the flag 'RF_INVISIBLE || the value of the invisible timer'.* The second one checks the flag RF_INVISIBLE and the timer separately.

To write what you want in the form !(a || b ||c), you want:

Code:
	if (!(rf_has(mon->race->flags, RF_INVISIBLE) ||
		mon->m_timed[MON_TMD_INVISIBLE]) ||
		mflag_has(mon->mflag, MFLAG_UNAWARE))) {
Does that make sense?

Oh, and in answer to your previous comment, in the UK at least we call {} curly braces.

* If you want to understand what this expression actually does, here's an explanation. The way || works in C is that if either side of the OR are not zero, it evaluates to 1. Otherwise it evaluates to 0.

So in the expression
Code:
RF_INVISIBLE || mon->m_timed[MON_TMD_INVISIBLE]
RF_INVISIBLE is the internal number for the flag. All valid flags have a number above 0 (0 is used to mean 'no flag'), so RF_INVISIBLE will be above 0 too. The expression will thus evaluate to 1.

Flag 1 is the UNIQUE flag (you can see this yourself in list-mon-race-flags.h.) So the check will actually only activate when the monster is not a unique.
__________________
"Physician, heal thyself."
takkaria is offline   Reply With Quote
Old July 15, 2016, 01:37   #56
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,319
Donated: $40
Pete Mack is on a distinguished road
Whoops, sorry I missed that.
Pete Mack is offline   Reply With Quote
Old July 15, 2016, 01:52   #57
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
Ok, I changed it.

Then I tested it to see whether it would detect Memory mosses (either invisible or visible) when they were out of LOS (which I didn't think to do before changing it) and found that Detect Monsters isn't detecting monsters at all now. Even when there are monsters (like a band of filthy street urchins) just on the other side of a wall.

Now I am confused.

Edit: But changing it back to what I had before works.
Elfin Jedi is offline   Reply With Quote
Old July 15, 2016, 02:30   #58
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
This time I copied and pasted, and it gives me this error:

effects.c: In function 'effect_handler_DETECT_VISIBLE_MONSTERS':
effects.c:1370:40: error: expected statement before ')' token
mflag_has(mon->mflag, MFLAG_UNAWARE)))

Edit: Going to look up statement. Be back soon.
Elfin Jedi is offline   Reply With Quote
Old July 15, 2016, 03:29   #59
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
Does it not recognize the c conditional as part of the if statement?
Elfin Jedi is offline   Reply With Quote
Old July 15, 2016, 03:47   #60
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,319
Donated: $40
Pete Mack is on a distinguished road
Sure. But the negation has to apply to the entire expression, not just one term in the expression. So you need the parentheses to specify evaluation order, otherwise ! will have higher precedence (I.e.will evaluate first) than ||. Precedence really matters.
Pete Mack is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[PosChengband] Making Realms Questions riftor_77 Development 5 August 4, 2014 13:24
Spellbooks as artifacts TJS Vanilla 48 July 29, 2010 06:12
Sangband and spell realms Malak Darkhunter Variants 21 March 18, 2009 05:03
Spellbooks curinor Variants 3 April 20, 2008 14:38
Spellbooks curinor Vanilla 1 April 19, 2008 23:07


All times are GMT +1. The time now is 04:59.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.