2019-12-16 00:35 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000690Spring engineGeneralpublic2007-12-09 23:05
Reporterlurker 
Assigned ToKDR_11k 
PrioritynormalSeverityfeatureReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000690: [patch] get play_sound: gives the ability to play sounds from cob that aren't heard by everyone
Description1) Adds a new get call, PLAY_SOUND, to play a sound that can be heard only by allies, enemy, in los, etc.
2) changes get health to allow a unit ID to be passed
3) adds a call to create() at the end of ReloadCOB
Additional InformationGET PLAY_SOUND(sound number, volume, who hears the sound, where to play the sound)

To set up sounds to use with GET PLAY_SOUND, put a function like this near the top of your bos:
Sounds()
{
    play-sound ("movement", 10);
    play-sound ("pew", 10);
    play-sound ("reporting", 10);
}
The sound number is based on the order the sounds appear, staring from 0. To call the songs by name, add #defines like this:
Sounds()
{
    play-sound ("movement", 10);
    #define movement 0
    play-sound ("pew", 10);
    #define pew 1
    play-sound ("reporting", 10);
    #define reporting 2
}

To actually call the sound, you use a line such as this:
    GET PLAY_SOUND (pew, 655360);

1) sound number - as above

2) volume - similar to the volume for play-sound, more affecting the distance where it is audible than actual volume
        - given as a float multiplied by 65536

3) who hears the sound
    0 = anyone with the unit in ALOS
    1 = anyone with the unit in LOS
    2 = anyone with the unit in ALOS or radar
    3 = anyone with the unit in LOS or radar
    4 = everyone
    5 = the unit's allies
    6 = the unit's team
    7 = the unit's enemies

4) where to play the sound
        - if 0, the sound is played from the unit's position
        - if 1, the sound is played directly from the speakers, the same way unit replies are
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon play_sound.patch (3,110 bytes) 2007-11-20 16:19 -
    Index: rts/Game/Game.cpp
    ===================================================================
    --- rts/Game/Game.cpp	(revision 4832)
    +++ rts/Game/Game.cpp	(working copy)
    @@ -4317,6 +4317,7 @@
     				delete unit->localmodel;
     				unit->localmodel =
     					modelParser->CreateLocalModel(unit->model, &unit->cob->pieces);
    +				unit->cob->Call("Create");
     			}
     		}
     	}
    Index: rts/Sim/Units/COB/CobInstance.cpp
    ===================================================================
    --- rts/Sim/Units/COB/CobInstance.cpp	(revision 4832)
    +++ rts/Sim/Units/COB/CobInstance.cpp	(working copy)
    @@ -12,6 +12,7 @@
     #include "Map/Ground.h"
     #include "Rendering/UnitModels/3DOParser.h"
     #include "Rendering/UnitModels/s3oParser.h"
    +#include "Sim/Misc/LosHandler.h"
     #include "Sim/Misc/RadarHandler.h"
     #include "Sim/MoveTypes/AirMoveType.h"
     #include "Sim/MoveTypes/MoveType.h"
    @@ -104,6 +105,7 @@
     #define CHANGE_TARGET             98 // set, the value it's set to determines the affected weapon
     #define CEG_DAMAGE                99 // set
     #define COB_ID                   100 // get
    +#define PLAY_SOUND				 101 // get, so multiple args can be passed
     #define ALPHA_THRESHOLD          103 // set or get
     #define SET_WEAPON_UNIT_TARGET   106 // get (fake set)
     #define SET_WEAPON_GROUND_TARGET 107 // get (fake set)
    @@ -968,8 +970,15 @@
     	case STANDINGFIREORDERS:
     		return unit->fireState;
     		break;
    -	case HEALTH:
    -		return (int) ((unit->health/unit->maxHealth)*100.0f);
    +	case HEALTH:{
    +		if (p1 <= 0)
    +			return (int) ((unit->health/unit->maxHealth)*100.0f);
    +		CUnit *u = (p1 < MAX_UNITS) ? uh->units[p1] : NULL;
    +		if (u == NULL)
    +			return 0;
    +		else
    +			return (int) ((u->health/u->maxHealth)*100.0f);
    +		}
     	case INBUILDSTANCE:
     		if (unit->inBuildStance)
     			return 1;
    @@ -1159,6 +1168,40 @@
     			return (u == NULL) ? -1 : u->unitDef->cobID;
     		}
     	}
    + 	case PLAY_SOUND:
    +		switch(p3) {	//who hears the sound
    +			case 0:		//ALOS
    +				if (!loshandler->InAirLos(unit->pos,gu->myAllyTeam)) {return 0;}
    +				break;
    +			case 1:		//LOS
    +				if (!(unit->losStatus[gu->myAllyTeam] & LOS_INLOS)) {return 0;}
    +				break;
    +			case 2:		//ALOS or radar
    +				if (!(loshandler->InAirLos(unit->pos,gu->myAllyTeam) || unit->losStatus[gu->myAllyTeam] & (LOS_INRADAR))) {return 0;}
    +				break;
    +			case 3:		//LOS or radar
    +				if (!(unit->losStatus[gu->myAllyTeam] & (LOS_INLOS | LOS_INRADAR))) {return 0;}
    +				break;
    +			case 4:		//everyone
    +				break;
    +			case 5:		//allies
    +				if (unit->allyteam != gu->myAllyTeam) {return 0;}
    +				break;
    +			case 6:		//team
    +				if (unit->team != gu->myTeam) {return 0;}
    +				break;
    +			case 7:		//enemies
    +				if (unit->allyteam == gu->myAllyTeam) {return 0;}
    +				break;
    +		}
    +		logOutput.Print("Playing %i %i %i", p1, p2, script.sounds[p1]);
    +		if ((p1 + 1 > script.sounds.size()) || p1 < 0) { return 1;}
    +		if (p4 == 0) {
    +			sound->PlaySample(script.sounds[p1], unit->pos, float(p2) / COBSCALE);
    +		}else{
    +			sound->PlaySample(script.sounds[p1], float(p2) / COBSCALE);
    +		}
    +		return 0;
     	case SET_WEAPON_UNIT_TARGET: {
     		const int weaponID = p1 - 1;
     		const int targetID = p2;
    
    patch file icon play_sound.patch (3,110 bytes) 2007-11-20 16:19 +
  • patch file icon play_sound_fixed.patch (3,043 bytes) 2007-11-20 16:23 -
    Index: rts/Game/Game.cpp
    ===================================================================
    --- rts/Game/Game.cpp	(revision 4832)
    +++ rts/Game/Game.cpp	(working copy)
    @@ -4317,6 +4317,7 @@
     				delete unit->localmodel;
     				unit->localmodel =
     					modelParser->CreateLocalModel(unit->model, &unit->cob->pieces);
    +				unit->cob->Call("Create");
     			}
     		}
     	}
    Index: rts/Sim/Units/COB/CobInstance.cpp
    ===================================================================
    --- rts/Sim/Units/COB/CobInstance.cpp	(revision 4832)
    +++ rts/Sim/Units/COB/CobInstance.cpp	(working copy)
    @@ -12,6 +12,7 @@
     #include "Map/Ground.h"
     #include "Rendering/UnitModels/3DOParser.h"
     #include "Rendering/UnitModels/s3oParser.h"
    +#include "Sim/Misc/LosHandler.h"
     #include "Sim/Misc/RadarHandler.h"
     #include "Sim/MoveTypes/AirMoveType.h"
     #include "Sim/MoveTypes/MoveType.h"
    @@ -104,6 +105,7 @@
     #define CHANGE_TARGET             98 // set, the value it's set to determines the affected weapon
     #define CEG_DAMAGE                99 // set
     #define COB_ID                   100 // get
    +#define PLAY_SOUND				 101 // get, so multiple args can be passed
     #define ALPHA_THRESHOLD          103 // set or get
     #define SET_WEAPON_UNIT_TARGET   106 // get (fake set)
     #define SET_WEAPON_GROUND_TARGET 107 // get (fake set)
    @@ -968,8 +970,15 @@
     	case STANDINGFIREORDERS:
     		return unit->fireState;
     		break;
    -	case HEALTH:
    -		return (int) ((unit->health/unit->maxHealth)*100.0f);
    +	case HEALTH:{
    +		if (p1 <= 0)
    +			return (int) ((unit->health/unit->maxHealth)*100.0f);
    +		CUnit *u = (p1 < MAX_UNITS) ? uh->units[p1] : NULL;
    +		if (u == NULL)
    +			return 0;
    +		else
    +			return (int) ((u->health/u->maxHealth)*100.0f);
    +		}
     	case INBUILDSTANCE:
     		if (unit->inBuildStance)
     			return 1;
    @@ -1159,6 +1168,39 @@
     			return (u == NULL) ? -1 : u->unitDef->cobID;
     		}
     	}
    + 	case PLAY_SOUND:
    +		switch(p3) {	//who hears the sound
    +			case 0:		//ALOS
    +				if (!loshandler->InAirLos(unit->pos,gu->myAllyTeam)) {return 0;}
    +				break;
    +			case 1:		//LOS
    +				if (!(unit->losStatus[gu->myAllyTeam] & LOS_INLOS)) {return 0;}
    +				break;
    +			case 2:		//ALOS or radar
    +				if (!(loshandler->InAirLos(unit->pos,gu->myAllyTeam) || unit->losStatus[gu->myAllyTeam] & (LOS_INRADAR))) {return 0;}
    +				break;
    +			case 3:		//LOS or radar
    +				if (!(unit->losStatus[gu->myAllyTeam] & (LOS_INLOS | LOS_INRADAR))) {return 0;}
    +				break;
    +			case 4:		//everyone
    +				break;
    +			case 5:		//allies
    +				if (unit->allyteam != gu->myAllyTeam) {return 0;}
    +				break;
    +			case 6:		//team
    +				if (unit->team != gu->myTeam) {return 0;}
    +				break;
    +			case 7:		//enemies
    +				if (unit->allyteam == gu->myAllyTeam) {return 0;}
    +				break;
    +		}
    +		if ((p1 + 1 > script.sounds.size()) || p1 < 0) { return 1;}
    +		if (p4 == 0) {
    +			sound->PlaySample(script.sounds[p1], unit->pos, float(p2) / COBSCALE);
    +		}else{
    +			sound->PlaySample(script.sounds[p1], float(p2) / COBSCALE);
    +		}
    +		return 0;
     	case SET_WEAPON_UNIT_TARGET: {
     		const int weaponID = p1 - 1;
     		const int targetID = p2;
    
    patch file icon play_sound_fixed.patch (3,043 bytes) 2007-11-20 16:23 +
  • ? file icon get_play_sound_demo.sd7 (794,842 bytes) 2007-11-20 16:35

-Relationships
+Relationships

-Notes

~0001451

lurker (reporter)

oops. forgot to remove the logOutput.

~0001486

KDR_11k (reporter)

committed in r4974
+Notes

-Issue History
Date Modified Username Field Change
2007-11-20 16:19 lurker New Issue
2007-11-20 16:19 lurker File Added: play_sound.patch
2007-11-20 16:23 lurker Note Added: 0001451
2007-11-20 16:23 lurker File Added: play_sound_fixed.patch
2007-11-20 16:35 lurker File Added: get_play_sound_demo.sd7
2007-12-06 19:43 tvo Summary get play_sound: gives the ability to play sounds from cob that aren't heard by everyone => [patch] get play_sound: gives the ability to play sounds from cob that aren't heard by everyone
2007-12-09 23:03 KDR_11k Status new => assigned
2007-12-09 23:03 KDR_11k Assigned To => KDR_11k
2007-12-09 23:05 KDR_11k Status assigned => resolved
2007-12-09 23:05 KDR_11k Resolution open => fixed
2007-12-09 23:05 KDR_11k Note Added: 0001486
+Issue History