Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Hotel Cog
Hotel Cog
2002-02-04, 12:35 PM #1
Ok I know this has been like 2 cogs in one day, but Im almost done with my level, last cog I promise [http://forums.massassi.net/html/smile.gif]. (Thanks to SaberMaster for the clothes.cog)

I need a cog that acts alot like the mm2_ffieldswitch.cog which is the LEC Forcefield cog. Here's my situation: I have a hotel with rooms. I want to be able to Activate the forcefield from both the lobby and the room ( Two switches ), I have a surface (geo 4) door for the rooms, I want it to be unpassable when the forcefield is on, and passasble when it is off, but I need to keep the doors (surface) geo 4.

Any help would be greatly appreciated [http://forums.massassi.net/html/biggrin.gif]
2002-02-05, 9:50 AM #2
I think the only thing you'll have to do is deleting SetFaceGeoMode stuff in the cog...
2002-02-05, 10:28 AM #3
<-- Has no cogging experience whatsoever, you mean just find SetFaceGeoMode, and delete it?
2002-02-05, 10:46 AM #4
oh... well... I guess so.. maybe not on all the places... i checked the cog out... I would try deleting all SetFaceGeoMode lines except the ones in the startup, and changing those to:
SetFaceGeoMode(damsurf,3);
SetFaceGeoMode(damsurf2,3);

it's probably wrong...
just ask the pros GBK, Hideki, SaberMaster etc... for help [http://forums.massassi.net/html/smile.gif]

[This message has been edited by JediJigge (edited February 05, 2002).]
2002-02-05, 1:32 PM #5
Ok pros? Any help here [http://forums.massassi.net/html/smile.gif]
2002-02-05, 1:58 PM #6
This should do it.

********************************************
Code:
# Cloak Switch
# Jedi Knight Cog Script
#
# 10_FFieldSwitch.cog based
#
# Uses 2 switches to open/close 2 sectors, ie: set visible/invisible
# and remove passable.  If StartOn is 1 (true) it starts on, else
# it starts off
# Grevenilvec
# topace@flash.net	somewhere in Rath		phone?? what phone?
#


symbols

message     startup
message     activated

surface     switch1                       linkid=1 mask=0x448
surface     switch2                       linkid=2 mask=0x448
surface	wallface1
surface	wallface2

int         StartOn=0

sound       turnoff=activate04.wav         local
sound       turnon=activate01.wav          local

end


code
startup:
   if (StartOn)
   {
      SetWallCel(switch1,0);                     //on
      SetWallCel(switch2,0);                     //on
	
	SetFaceGeoMode(wallface1, 0x4);
	SetFaceGeoMode(wallface2, 0x4);
      ClearAdjoinFlags(wallface1,2);              //no move
      ClearAdjoinFlags(wallface2,2);
   }
   else
   {
      SetWallCel(switch1,1);                     //off
      SetWallCel(switch2,1);                     //off
      SetFaceGeoMode(wallface1, 0x0);
      SetFaceGeoMode(wallface2, 0x0);
      PlaySoundPos(turnon, GetSurfaceCenter(switch1), 0.5, 1, 10, 0);
      PlaySoundPos(turnon, GetSurfaceCenter(switch2), 0.5, 1, 10, 0);
   }
   return;

activated:
   if ((GetSenderID() != 1) || (GetSenderID() != 2)) return;

   if (GetWallCel(switch1) == 1)
   {
      SetWallCel(switch1,0);                     //on
      SetWallCel(switch2,0);                     //on
	
	SetFaceGeoMode(wallface1, 0x4);
	SetFaceGeoMode(wallface2, 0x4);
      ClearAdjoinFlags(wallface1,2);              //no move
      ClearAdjoinFlags(wallface2,2);

      PlaySoundPos(turnoff, GetSurfaceCenter(switch1), 0.5, 1, 10, 0);
      PlaySoundPos(turnoff, GetSurfaceCenter(switch2), 0.5, 1, 10, 0);
   }
   else if (GetWallCel(switch1) == 0)
   {
      SetWallCel(switch1,1);                     //off
      SetWallCel(switch2,1);                     //off

      SetFaceGeoMode(wallface1, 0x0);
      SetFaceGeoMode(wallface2, 0x0);
      SetAdjoinFlags(wallface1,2);              //move
      SetAdjoinFlags(wallface2,2);

      PlaySoundPos(turnon, GetSurfaceCenter(switch1), 0.5, 1, 10, 0);
      PlaySoundPos(turnon, GetSurfaceCenter(switch2), 0.5, 1, 10, 0);
   }
   return;

end


*********************************************
-Greven


[This message has been edited by Evil_Greven (edited February 05, 2002).]

[This message has been edited by Evil_Greven (edited February 05, 2002).]
2002-02-05, 2:34 PM #7
For some reason, the switch won't do anything... nooo! Curse my cog problems!
Anyone know whats wrong with it?
2002-02-05, 5:01 PM #8
Just a few pointers on for EG,

1) Use arrays, itll cut the size of the cog in half.

2) He needed the surfaces to stay as geo4, not switch back and forth.

3) There isnt any use playing sounds emmidietly on startup, you wont hear them.

4) It is a waste of code using separate linkIDs for the switches, since they perform the same function.

Theres more, but Im in a hurry.


Code:
symbols
message startup
message activated
surface switch0			linkid=1
surface switch1			linkid=1
surface wallface0
surface wallface1
int StartOn=0
sound turnoff=activate04.wav		local
sound turnon=activate01.wav			local
Int I=0					Local
end
code
startup:
if (StartOn == 1) {
For(I=0;I<2;I=I+1) {
SetWallCel(switch0, 0);
ClearAdjoinFlags(wallface0, 2);  } }
else { For(I=0;I<2;I=I+1) {
SetWallCel(switch0, 1);
Setadjoinflags(wallface0, 2);  } }
return;
activated: if(GetSenderID() != 1) return;
if (GetWallCel(switch1) == 1) {
For(I=0;I<2;I=I+1) {
SetWallCel(switch0, 0);
ClearAdjoinFlags(wallface0, 2);
PlaySoundPos(turnoff, GetSurfaceCenter(switch0), 1, -1, 20, 0); } }
else { For(I=0;I<2;I=I+1) {
SetWallCel(switch0,1);
SetAdjoinFlags(wallface0, 2);
PlaySoundPos(turnon, GetSurfaceCenter(switch0), 1, -1, 20, 0); } }
return;
end




I havent tested it, but it should work.

------------------
Success is the inverse relationship between effort, gain, and loss.

[This message has been edited by GBK (edited February 06, 2002).]
And when the moment is right, I'm gonna fly a kite.
2002-02-06, 11:17 AM #9
GBK, it works great... only something is wrong with the switch0, it doesn't change the surface like a normal switch but it makes a sound and changes the surface. Although switch1 works perfect
2002-02-06, 12:02 PM #10
1) Arrays serve little purpose in this code, just add an extra variable and take up less visible space, however it will take up more space in physical code.

2) Misunderstood, was talking to him in IRC

3) Ooops, thought I deleted that

4) I dislike having the same linkids, habit of mine

Oh, and I was in a hurry as well.

Code:
# Wall Door Switch
# Jedi Knight Cog Script
#
# 10_FFieldSwitch.cog based
#
# Uses 2 switches to open/close 2 sectors, ie: set visible/invisible
# and remove passable.  If StartOn is 1 (true) it starts on, else
# it starts off
# Grevenilvec
# topace@flash.net	somewhere in Rath		phone?? what phone?
#


symbols

message     startup
message     activated

surface     switch1                       linkid=1 mask=0x448
surface     switch2                       linkid=2 mask=0x448
surface	wallface1
surface	wallface2

int         StartOn=0

sound       turnoff=activate04.wav         local
sound       turnon=activate01.wav          local

end


code
startup:
   if (StartOn)
   {
      SetWallCel(switch1,0);                     //on
      SetWallCel(switch2,0);                     //on
	
      ClearAdjoinFlags(wallface1,2);              //no move
      ClearAdjoinFlags(wallface2,2);
   }
   else
   {
      SetWallCel(switch1,1);                     //off
      SetWallCel(switch2,1);                     //off
   }
   return;

activated:
   if ((GetSenderID() != 1) && (GetSenderID() != 2)) return;

   if (GetWallCel(switch1) == 1)
   {
      SetWallCel(switch1,0);                     //on
      SetWallCel(switch2,0);                     //on
	
      ClearAdjoinFlags(wallface1,2);              //no move
      ClearAdjoinFlags(wallface2,2);

      PlaySoundPos(turnoff, GetSurfaceCenter(switch1), 0.5, 1, 10, 0);
      PlaySoundPos(turnoff, GetSurfaceCenter(switch2), 0.5, 1, 10, 0);
   }
   else if (GetWallCel(switch1) == 0)
   {
      SetWallCel(switch1,1);                     //off
      SetWallCel(switch2,1);                     //off

      SetAdjoinFlags(wallface1,2);              //move
      SetAdjoinFlags(wallface2,2);

      PlaySoundPos(turnon, GetSurfaceCenter(switch1), 0.5, 1, 10, 0);
      PlaySoundPos(turnon, GetSurfaceCenter(switch2), 0.5, 1, 10, 0);
   }
   return;

end
2002-02-06, 4:09 PM #11
Quote:
<font face="Verdana, Arial" size="2">Originally posted by Evil_Greven:
1) Arrays serve little purpose in this code, just add an extra variable and take up less visible space, however it will take up more space in physical code.</font>



Why then, is my cog half the size of yours?[/i]

Any time you are writing code that runs the same operation on multiple variables, arrays are indespensable.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-02-06, 5:45 PM #12
BTW, I fixed my version of the cog, it should work correctly now.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-02-07, 7:51 AM #13
Arrays are indespensible, yes. However, its just not worth it to add a brand new variable just for putting the code in loops. I've tested this in C++, which I program in extensively, and my professors agree.

This deals with time complexity, and the like. For a reasonably simply time complexity problem, you would assign each operation as 1 Time Unit (TU).

Ex.
int a; //1
int b; //1
int c; //1

Simple arithmatic would give you 3 TUs. Now lets try a piece of code:

int a; //1
a=a+1; //1
a=a+1; //1
a=a+1; //1

Time complexity is 4 TUs. Now the same piece of code in a for loop:

int a; //1
int x; //1
for(x=0; x<3; x=x+1) a=a+1;

Time complexity is 2 so far.. to get the real time complexity, we must change the for loop into a while loop:

int a; //1
int x; //1

x=0; //1
while(x<3) { //1*N
x=x+1; //1*N
a=a+1; //1*N
} //1

Ok so the time complexity is 4+3*N. The loop executes 3 times, so N is 3. Time complexity ends up as 13 TUs. To explain this a little, especially about the last } having a value of 1 is to make it neat.. in actuality, the while(x<3) would be 1*N+1 TUs and the } would have 0 TUs, but its slightly easier to think of this way.

So which is better, 13 or 4?

Yes, arrays and loops make programming far easier, and I dare to say it would be impossible without them. However, don't use them when you don't have to.

-Greven
2002-02-07, 9:22 AM #14
Proccessor time is irrelevent in cogs. The operations performed take little or no effort. Even on my old P2-200, arrays that ran into the thousands were executed in less than a second.

The only valid argument here is the amount of actual code. Arrays help to reduce the overall size of cogs. I dont think you will disagree with that. They do take slightly more time to process, yes, but only by a matter of milliseconds.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-02-07, 3:29 PM #15
Look, I don't see what point you are trying to make here, but if you wrote your code with the same conventions I write mine in, yours would end up LONGER (albet not by much) than my code.

Ie: each piece of code on seperate lines, such as }, {, for(), etc.

And since this is a rather pointless argument, this is my final response.
2002-02-07, 3:58 PM #16
Uhm. I hate to break it to you, but Greven is right. JK breaks the COG script down into opcodes. No matter how compact your code is, it isn't going to make JK run any faster, and it CERTAINLY isn't making your code less obfuscated.

Grev's code:
Code:
mov [val1],1
add [val1],2
add [val1],3 ; val1 = 6


Your code:
Code:
mov [numval],3
mov [val1],1
mov [val2],2
mov [val3],3
mov [finalval],0
mov ,0
startofloop:
add ,1
add [finalval],[val]
cmp ,[numval]
jne startofloop
; finalval = 6.

Both accomplish the same thing, but who would seriously use the second method to add three numbers?

[This message has been edited by Jon`C (edited February 07, 2002).]

↑ Up to the top!