Author |
Message |
ronwolf1705
Moderator

Joined: 31 Jul 2006
Last Visit: 3:58 ago.
Topics: 74
Posts: 3812

|
Posted: Sun Nov 25, 2012 11:52 am
Subject: Translating moving objects code to 4SDL
[ IP : Logged ]
|

 
|
|
The moving object code:
http://diehardwolfers.areyep.com/viewtopic.php?t=4388
BT posted an excellent piece of code in there (#ifdef PUSHOBJECT) that allowed you to push objects. Being a total code noob, I can't get this to work in the 4SDL code. I was wondering if someone could 'translate' this for me. Any help is appreciated.  |
|
|
 |
BrotherTank
Forum Administrator

Joined: 01 Mar 2003
Last Visit: 13 Sep 2017
Topics: 153
Posts: 2255
Location: Ontario

|
Posted: Wed Nov 28, 2012 7:15 am
Subject: Re: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
Hi Ron... I'll expand on this so that you define the pushable item by a tile placed on the floor code and post an update to the code..
Give me a few days...
Greg
BrotherTank |
|
|
 |
ronwolf1705
Moderator

Joined: 31 Jul 2006
Last Visit: 3:58 ago.
Topics: 74
Posts: 3812

|
Posted: Wed Nov 28, 2012 7:24 am
Subject: Re: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
Thanks Greg, I appreciate it a lot!  |
|
|
 |
BrotherTank
Forum Administrator

Joined: 01 Mar 2003
Last Visit: 13 Sep 2017
Topics: 153
Posts: 2255
Location: Ontario

|
Posted: Sat Dec 01, 2012 2:16 am
Subject: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
Ok Ronwolf... Here you go... The nice text in the Blue is what you will be adding to the different files.
In the version.h file add the following:
::: CODE :::
#define PUSHOBJECT // Adds pushable sprite/static object code to the game
In wl_def.h
Make the static object structure look likke this:
::: CODE :::
//---------------------
//
// trivial actor structure
//
//---------------------
typedef struct statstruct
{
byte tilex,tiley;
short shapenum; // if shapenum == -1 the obj has been removed
byte *visspot;
uint32_t flags;
byte itemnumber;
#ifdef PUSHOBJECT // Objects that can be pushed
byte pushable;
#endif
} statobj_t;
#ifdef PUSHOBJECT // Objects that can be pushed
// Place this value on the floor below an item that you want to be pushable
#define PUSHITEMMARKER 145 // Add this value to your mapdata defines - change value if required
#endif
extern void ResetFloorCode (int tilex,int tiley);
// Arrays for quick checking locations on the map
extern char dx4dir[4];
extern char dy4dir[4];
In wl_game.cpp at the top of the file, add these lines to the Global Constants definitions:
::: CODE :::
// Arrays for quick checking cardinal direction locations on the map
char dx4dir[4]= { 0, 1, 0, -1 }; // dx & dy based on direction
char dy4dir[4]= {-1, 0, 1, 0 };
In the wl_agent.cpp file, down in the CMD_Use routine, add these lines before the last ending bracket of the routine:
::: CODE :::
// Static Object/Items manipulation routines
for(statptr = statobjlist; statptr != laststatobj; statptr++)
{
if(statptr->tilex == checkx && statptr->tiley == checky && !buttonheld[bt_use])
{
buttonheld[bt_use] = true; // that must react to spacebar
#ifdef PUSHOBJECT // Pushable Items or Objects that can be pushed
if (statptr->pushable) // Is the item Pushable
{
if (actorat[checkx][checky])
{
if(actorat[checkx + dx4dir[dir]][checky + dy4dir[dir]] > 0) { return; } // Is Tile to move to Free?
SD_PlaySound (TAKEDAMAGESND); // Make a Ugh pushing sound
statptr->tilex = statptr->tilex + dx4dir[dir]; // Free to move object
statptr->tiley = statptr->tiley + dy4dir[dir]; // to it's new location
statptr->visspot = &spotvis[statptr->tilex][statptr->tiley]; // Make it visible
actorat[checkx][checky] = (objtype *)(uintptr_t) 0;
actorat[statptr->tilex][statptr->tiley] = (objtype *)(uintptr_t) 64;
}
}
#endif
// Other routines for static objects can be inserted here
// End of static object check loop
}
}
And at the top of the routine, you will see the defines for checkx and so on... Make that section look like this:
::: CODE :::
int checkx,checky,doornum,dir;
boolean elevatorok;
statobj_t* statptr;
In the wl_act1.cpp file, add the following code above the SpawnStatic routine:
::: CODE :::
/* ============ Reset Floor Code ================ */
// Replace Any Map Modifier Code with a valid Floor Code Value
void ResetFloorCode (int tilex,int tiley)
{
int x,y;
for (x = di_north; x <= di_west; x++)
{
y = MAPSPOT (tilex+dx4dir[x], tiley+dy4dir[x], 0);
if ( y >= AREATILE && y <= (AREATILE+NUMAREAS-1) )
{ MAPSPOT (tilex,tiley,0) = y; return; }
}
}
In the SpawnStatic routine, add the following, to make the end of the routine look like this:
::: CODE :::
#ifdef PUSHOBJECT // Pushable Static Object Item
if (MAPSPOT(tilex,tiley,0) == PUSHITEMMARKER)
{
laststatobj->pushable = 1; // Make Item Pushable or True
ResetFloorCode (tilex,tiley); // Reset the Floor code to a valid Floor code value
}
#endif
laststatobj->flags |= statinfo[type].specialFlags;
laststatobj++;
if (laststatobj == &statobjlist[MAXSTATS]) Quit ("Too many static objects!\n");
And that should be it. Now you add the floor value of 145 to you mapedit defines... and put that tile down underneath the static objects that you want to be pushable on any of your maps. When the maps are loaded, as the static items are spawned, the ResetFloorCode will set the object as pushable and change the floor code back to a proper value of that of one of the squares immediately next to the spot where the pushable item is now marked. This code is taken directly from the Community Map of the Month contest code... I've just extracted it and coloured it nicely to make it easier to re-install. It worked perfectly in that source (SDL) so it shouldn't be a problem in the latest SDL source from Ripper [version 1.7 I believe].
Let me know if you have any problems...
Enjoy!
Greg
BrotherTank |
Last edited by BrotherTank on Sat Dec 01, 2012 12:08 pm; edited 1 time in total
|
|
 |
ronwolf1705
Moderator

Joined: 31 Jul 2006
Last Visit: 3:58 ago.
Topics: 74
Posts: 3812

|
Posted: Sat Dec 01, 2012 5:26 am
Subject: Re: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
Thanks Greg, this is perfect! I didn't want any object pushable by default (only one episode will revolve around this, for now I've dubbed it the 'Sokoban'-episode ), so such a marker is exactly what I needed. One thing not to forget is that statptr still needs to be defined, otherwise you'll get error messages. Simply add 'statobj_t* statptr;' to the beginning of the CMD_Use function. |
|
|
 |
BrotherTank
Forum Administrator

Joined: 01 Mar 2003
Last Visit: 13 Sep 2017
Topics: 153
Posts: 2255
Location: Ontario

|
Posted: Sat Dec 01, 2012 11:59 am
Subject: Re: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
Yep... It's in my code but I missed pulling that out of the code... lol... I knew that I'd miss something or mistype something when I was copying and pasting from the code files to a text file and then addding the formatting blocks so it would look nice in the forums .... I've updated the post to add the missing line of code...
Anyhow... hope it does you well... and look forward to seeing it used in your project....
Greg
BrotherTank
PS: For ALL -- For what it is worth... You can find the Map of the Month source code in the downloads section for both the SDL and Dos versions. The SDL version has many routines modified and converted (the dos tutorials) so you might want to download it and have a look around at the code and the changes that I've made. That version is the SDL version 1.6, so if you are using the newer source version 1.7, then you will have to extract the code that you want and move it over to your working source. Enjoy...
BT |
|
|
 |
Arielus
DieHard Mutant


Joined: 13 Mar 2003
Last Visit: 4:59 ago.
Topics: 20
Posts: 784
Location: Buenos Aires, Argentina

|
Posted: Sat Dec 01, 2012 1:57 pm
Subject: Re: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
BrotherTank,
In reference to the Map of the Month bit of your post, all I want to say is that it was arguably the best/funnest propeller of community efforts this family has to this date seen. I miss it a lot. Thank you for it...
Ariel |
_________________ Hot to Rock - Long Live Metal!
|
|
 |
ronwolf1705
Moderator

Joined: 31 Jul 2006
Last Visit: 3:58 ago.
Topics: 74
Posts: 3812

|
Posted: Sat Dec 01, 2012 2:33 pm
Subject: Re: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
I definitely agree with that, Ariel!  |
|
|
 |
BrotherTank
Forum Administrator

Joined: 01 Mar 2003
Last Visit: 13 Sep 2017
Topics: 153
Posts: 2255
Location: Ontario

|
Posted: Sun Dec 02, 2012 12:18 am
Subject: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
Thanks for that guys... I really did enjoy that too...
For what it's worth, it's easy to do and works just great as people enjoy doing 1 map [as it's easy to do just one] for fun. The software has been sitting there for years now... And no-one wants to keep it going or start it back up again. It's not that hard to set up and run. I'd do it if it wasn't for the fact that right now I'm working on trying to fix the forums software and get the mail system back up and working again.
Start a new topic about it in the Wolfenstein section and see if people are interested in working on or participating in the Map of the Month thing again.
I'm sure people will be interested. That and with the Winter season hitting a great many of us, we might see a little more traffic for the forums once again.
Greg
BrotherTank |
|
|
 |
Chris
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 14 Feb 2019
Topics: 55
Posts: 2169
Location: Canada

|
|
 |
Dean
Moderator

Joined: 10 Jan 2006
Last Visit: 07 Feb 2019
Topics: 54
Posts: 2214
Location: Australia

|
Posted: Sun Dec 02, 2012 1:55 pm
Subject: Re: Translating moving objects code to 4SDL
[ IP : Logged ]
|

  
|
|
Yeah, there's been repeated interest raised over the last few years about doing an SDL version but I seem to recall there being some minor things in the exe that weren't functioning correctly or something... Tricob will remember better than I do. Anyway, I'm sure we'd get participants if we were to start a competition again.
What's with this Winter rubbish of which you speak? Summer here, Beautiful sunny day of 22 degrees (Celcius of course!) and the crickets on, what more could you ask for?!  |
_________________ ... Still alive
|
|
 |
Tricob
Moderator


Joined: 14 Mar 2005
Last Visit: 3:08 ago.
Topics: 165
Posts: 8327
Location: Neo-traditions, Inc.

|
|
 |
|