Update of /cvsroot/slashmud/slashmudx/plugins/Push
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv25383/plugins/Push
Modified Files:
push.c
Log Message:
Fix incorrect memory free and random move indexing.
Index: push.c
===================================================================
RCS file: /cvsroot/slashmud/slashmudx/plugins/Push/push.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** push.c 10 Jun 2007 18:04:03 -0000 1.29
--- push.c 21 Apr 2008 15:20:00 -0000 1.30
***************
*** 292,295 ****
--- 292,298 ----
#ifndef NDEBUG
+
+ /* TODO Is this still needed? */
+
static void
pi_validate_rooms_and_exits(InstanceDataPtr instance_data)
***************
*** 312,323 ****
count = kg_list_items(instance_data->mPushDir);
for (index = 1; index <= count; index++)
{
theExitName = smapi_get_exit_name(instance_data->mRoom, (direction_t) kg_list_retrieve(instance_data->mPushDir, index));
! if (theExitName)
! {
! smapi_free((Ptr) theExitName);
! }
! else
{
snprintf(buffer, kCatchTellBufferBytes, "Push plugin for room '%s', could not find exit in direction '%s'.", theRoomName, (char *) kg_list_retrieve(instance_data->mPushDirText, index));
--- 315,323 ----
count = kg_list_items(instance_data->mPushDir);
+
for (index = 1; index <= count; index++)
{
theExitName = smapi_get_exit_name(instance_data->mRoom, (direction_t) kg_list_retrieve(instance_data->mPushDir, index));
! if (theExitName == NULL)
{
snprintf(buffer, kCatchTellBufferBytes, "Push plugin for room '%s', could not find exit in direction '%s'.", theRoomName, (char *) kg_list_retrieve(instance_data->mPushDirText, index));
***************
*** 651,666 ****
/* Random room and exit selection. */
! indexOption = kg_good_random_int(0, kg_list_items(instance_data->mPushDir) + kg_list_items(instance_data->mPushRoom) - 2);
! if ((0 < indexOption) && (indexOption <= kg_list_items(instance_data->mPushDir)))
{
smapi_room_move(instance_data->mRoom, living, (direction_t) kg_list_retrieve(instance_data->mPushDir, indexOption));
}
! else
{
- indexOption -= kg_list_items(instance_data->mPushDir);
-
smapi_teleport_to_room_name(living, (Ptr) kg_list_retrieve(instance_data->mPushRoom, indexOption));
}
}
--- 651,681 ----
/* Random room and exit selection. */
! /* Generate one random number then determine based on range if it is a random exit or room move */
! /* List indexes are one based. */
!
! indexOption = kg_good_random_int(0, kg_list_items(instance_data->mPushDir) + kg_list_items(instance_data->mPushRoom));
! if (indexOption == 0)
! {
! return; /* No random movement. */
! }
!
! if (indexOption <= kg_list_items(instance_data->mPushDir))
{
smapi_room_move(instance_data->mRoom, living, (direction_t) kg_list_retrieve(instance_data->mPushDir, indexOption));
+ return;
}
!
! indexOption = indexOption - kg_list_items(instance_data->mPushDir);
! if ((indexOption != 0) && (indexOption <= kg_list_items(instance_data->mPushRoom)))
{
smapi_teleport_to_room_name(living, (Ptr) kg_list_retrieve(instance_data->mPushRoom, indexOption));
}
+ #ifndef NDEBUG
+ else
+ {
+ smapi_log_debug("Push plugin failed random move.");
+ }
+ #endif
}
|